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".
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.