Ayush Raj Singh
Ayush Raj Singh

Reputation: 873

I get error "Error in nnet.default(x, y, w, ...) : too many (77031) weights" while training neural networks

I am trying to train neural networks in R using package nnet. Following is the information about my training data.

str(traindata)

'data.frame':   10327 obs. of  196 variables:
$ stars                          : num  5 5 5 3.5 3.5 4.5 3.5 5 5 3.5 ...
$ open                           : num  1 1 1 1 1 1 1 1 1 1 ...
$ city                           : Factor w/ 61 levels "ahwatukee","anthem",..: 36 38
$ review_count                   : int  3 5 4 5 14 6 21 4 14 10 ...
$ name                           : Factor w/ 8204 levels " leftys barber shop",..:
$ longitude                      : num  -112 -112 -112 -112 -112 ...
$ latitude                       : num  33.6 33.6 33.5 33.4 33.7 ...
$ greek                          : int  0 0 0 0 0 0 0 0 0 0 ...
$ breakfast...brunch             : int  0 0 0 0 0 0 0 0 0 0 ...
$ soup                           : int  0 0 0 0 0 0 0 0 0 0 ...

I have truncated this information.

When I run the following:

library(nnet)  
m4 <- nnet(stars~.,data=traindata,size=10, maxit=1000)

I get the following error:

Error in nnet.default(x, y, w, ...) : too many (84581) weights

When I try changing weights in the argument like:

m4 <- nnet(stars~.,data=traindata,size=10, maxit=1000,weights=1000)

Then I get the following error:

Error in model.frame.default(formula = stars ~ ., data = traindata, weights = 1000) : 
variable lengths differ (found for '(weights)')

What is the mistake I am making? How do I avoid or correct this error? Maybe the problem is with my understanding of "weights".

Upvotes: 22

Views: 37978

Answers (4)

Artemination
Artemination

Reputation: 723

Increase the MaxNWts parameter by passing it directly

m4 <- nnet(stars~.,data=traindata,size=10, maxit=1000,MaxNWts=84581)

Upvotes: 2

Filippo Mazza
Filippo Mazza

Reputation: 4377

The option to set to increase the number of weights allowed in the network is MaxNWts, not weights (set to specify weights for each sample).

Upvotes: 3

Hong Ooi
Hong Ooi

Reputation: 57686

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

You probably also want to think some more on exactly which variables to include in the model. Just looking at the data provided, name is a factor with more than 8000 levels; you're not going to get anything sensible out of it with only 10000 observations. city might be more useful, but again, 61 levels in something as complex as a neural net is likely to be marginal.

Upvotes: 19

Tommy Levi
Tommy Levi

Reputation: 781

Increase 'MaxNWts' option to something larger than 84581.

Upvotes: 8

Related Questions