A neural network using all input variables?

I am new to neural networks and am testing the algorithm with some large datasets. Is there a way to bring all the input variables online without typing all the names? For example, I have about 30 variables that I would like to use as input to predict the output. Is there a shortcut for the next command?

net <- neuralnet(Output~Var1+Var2+Var3+Var4+.....upto Var30, data, hidden=0)

      

I've searched everywhere but couldn't find a solution to this. Sorry if this is the main question!

+2


source to share


1 answer


There are three ways to insert variables into a function formula:

The first one with the help .

, which will include all variables in the data

data.frame besides the response variable (in this case the Output variable):

net <- neuralnet(Output ~ ., data, hidden=0) #apart from Output all of the other variables in data are included

      

Use this if your data.frame has an Output and 30 more variables.

Second , if you want to use a vector of names to include in the data data.frame, you can try:

names <- c('var1','var2','var3') #choose the names you want
a <- as.formula(paste('Output ~ ' ,paste(names,collapse='+')))

> a
Output ~ var1 + var2 + var3 #this is what goes in the neuralnet function below

      

so that you can use:



net <- neuralnet( a , data, hidden=0) #use a in the function

      

Use this if you can provide a vector of names of 30 variables

Third, simply multiply the data

data.frame using the columns you want to use in the function, for example:

net <- neuralnet(Output ~ ., data=data[,1:31] , hidden=0)

      

Use this for (or any other subset that is convenient) and select the 30 variables you need and the Output variable. Then use .

to turn everything on.

Hope it helps!

+5


source







All Articles