How to change weights in mlp general interface on tidymodels?

440 views Asked by At

So I'm trying to fit a deep learning model into my data, using tidymodels. The general interface for this is mlp() and I'm using fit_resamples() in order to find the best model to external data. I keep getting this error:

ann_model <-
  mlp(epochs = 50, hidden_units = 5, dropout = 0.1) %>%
  set_engine("nnet", weights = 10000) %>% 
  set_mode("regression")

ann_wflw <-
  workflow() %>% 
  add_recipe(dados_recipe) %>% 
  add_model(ann_model)

ann_fit <- 
  ann_wflw %>% 
  fit_resamples(resamples = dados_cv)

x Fold01, Repeat1: model: Error in nnet.default(x, y, w, ...): too many (1301) weights

x Fold02, Repeat1: model: Error in nnet.default(x, y, w, ...): too many (1296) weights....

How do I change the weights? Please I'm really in a rush here. BTW is there any other approach to not overfit my training data other than cross validation? Thanks in advance!

1

There are 1 answers

1
hnagaty On

I guess you want to increase MaxNWts parameter instead of weights.

I'm quoting the below from the answer at I get error "Error in nnet.default(x, y, w, ...) : too many (77031) weights" while training neural networks

Either increase MaxNWts to something that will accommodate the size of your model, or reduce size to make your model smaller.

According to nnet documentation, weights is the

(case) weights for each example – if missing defaults to 1

Whereas MaxNWts is

The maximum allowable number of weights. There is no intrinsic limit in the code, but increasing MaxNWts will probably allow fits that are very slow and time-consuming