Adam12344
Adam12344

Reputation: 1053

Using all Input Variables in neuralnet in R

I'm trying to create a simple Neural Network in R using the nerualnet package. Instead of typing out all 784 input variables I am just using a . like is suggested in this thread: neural network using all input variables?

But I am getting this error

> digitnet <- neuralnet(label ~ ., trainingset, hidden = 4)

Error in terms.formula(formula) : '.' in formula and no 'data' argument

Upvotes: 3

Views: 1120

Answers (1)

LyzandeR
LyzandeR

Reputation: 37879

I don't know why that doesn't work but you can always use the following:

myform <- as.formula(paste0('label ~ ', 
                             paste(names(trainingset[!names(trainingset) %in% 'label']),
                     collapse = ' + ')))

and then:

digitnet <- neuralnet(myform, trainingset, hidden = 4)

And it will use all 784 input variables in the neural network model.

Upvotes: 2

Related Questions