Multinomial classification using neuralnet package

微笑、不失礼 提交于 2019-12-03 16:37:58
UBod

You are right that the formula interface of neuralnet() does not support '.'.

However, the problem with your code above is rather that a factor is not accepted as target. You have to expand the factor Species to three binary variables first. Ironically, this works best with the function class.ind() from the nnet package (which wouldn't need such a function, since nnet() and multinom() work fine with factors):

trainData <- cbind(iris[, 1:4], class.ind(iris$Species))
neuralnet(setosa + versicolor + virginica ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, trainData)

This works - at least for me.

Maybe you should have a look to http://cran.r-project.org/web/packages/nnet/nnet.pdf, the description of the package's content. You can see that there is a function called multinom, that helps you achieve this.

Basically, it will split the qualitative column species into quantitative columns (which is what class.ind does), and then try to predict the values for these new artificial columns.

nn <- multinom(species ~ ., iris)

I'm not sure if I answered your question because I have the feeling that you are trying to do with neuralnet something that does not work with nnet. If I'm wrong then... sorry ;)

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