[英]neural network in R
hi i am trying to use neuralnet function in R so i can predict an integer outcome (meaning) using the rest of the variables. 您好,我想在R中使用神经网络功能,以便可以使用其余变量来预测整数结果(含义)。 here is the code that i have used:
这是我使用的代码:
library("neuralnet")
I am going to put 2/3 from the data for neural network learning and the rest for test 我将把2/3的数据用于神经网络学习,其余的用于测试
ind<-sample(1:nrow(Data),6463,replace=FALSE)
Train<-Data[ind,]
Test<-Data[-ind,]
m <- model.matrix(
~meaning +
firstLevelAFFIRM + firstLevelDAT.PRSN + firstLevelMODE +
firstLevelO.DEF + firstLevelO.INDIV + firstLevelS.AGE.INDIV +
secondLevelV.BIN + secondLevelWord1 + secondLevelWord2 +
secondLevelWord3 + secondLevelWord4 + thirdLevelP.TYPE,
data = Train[,-1]) #(the first column is ID , i am not going to use it)
PredictorVariables <- paste("m[," , 3:ncol(m),"]" ,sep="")
Formula <- formula(paste("meaning ~ ", paste(PredictorVariables, collapse=" + ")))
net <- neuralnet(Formula,data=m, hidden=3, threshold=0.05)
m.test < -model.matrix(
~meaning +
firstLevelAFFIRM + firstLevelDAT.PRSN + firstLevelMODE +
firstLevelO.DEF + firstLevelO.INDIV + firstLevelS.AGE.INDIV +
secondLevelV.BIN + secondLevelWord1 + secondLevelWord2 +
secondLevelWord3 + secondLevelWord4 + thirdLevelP.TYPE,
data = Test[,-1])
net.results <- compute(net, m.test[,-c(1,2)]) #(first column is ID and the second one is the outcome that i am trying to predict)
output<-cbind(round(net.results$net.result),Test$meaning)
mean(round(net.results$net.result)!=Test$meaning)
the misclassification that i got was around 0.01 which is great, but my question is why the outcome that i got (net.results$net.result) is not an integer? 我得到的错误分类大约是0.01,这很好,但是我的问题是为什么我得到的结果(net.results $ net.result)不是整数?
I assume that your output is linear. 我假设您的输出是线性的。 Try setting
linear.output = FALSE
. 尝试设置
linear.output = FALSE
。
net <- neuralnet(Formula, data = m, hidden = 3, threshold = 0.05, linear.output = FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.