neural network using all input variables?

北慕城南 提交于 2019-12-04 17:03:34

There are 3 ways to insert variables in the formula part of a function:

First by using . which will include all of the variables in the data data.frame apart from the response variable (variable Output in this case):

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 Output and another 30 variables only.

Second if you want to use a vector of names to include from 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 you can use:

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

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

Third just subset the data data.frame using the columns you want in the function e.g.:

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

Use this to (or any other subset that is convenient) and choose the 30 variables you need along with the Output variable. Then use . to include everything.

Hope it helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!