Using all Input Variables in neuralnet in R

♀尐吖头ヾ 提交于 2020-01-01 16:58:14

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/31729775/using-all-input-variables-in-neuralnet-in-r

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