nnet函数与预测

时间:2017-11-25 22:50:53

标签: r predict nnet

我试图使用nnet函数和预测功能来返回一些值,但我的nnet $ fitted.values与我的预测值相同,我不知道为什么,是的2个数据集是不同的

  trainTest<- function(Train, Test)
{
nnetfit<- nnet(as.numeric(Train[,7])~ Train[,10]+Train[,15],data=Train,linout=TRUE,Hess=TRUE,maxit=1000,size=30,na.rm=TRUE)
 predicted <-predict(nnetfit,Test[2:13,c(10,15)],na.rm=TRUE)
return(list(nnetfit$fitted.values,predicted))
}

编辑:添加了使用的数据

> cbind(Train[,7],Train[,10],Train[,15])
      [,1]       [,2] [,3]
[1,] 75.59         NA   52
[2,] 77.84 -26.895809   45
[3,] 78.98  34.371298   38
[4,] 78.99  15.444714   31
[5,] 83.28  12.452137   24
[6,] 82.82 -33.920929   17
[7,] 84.50   8.855511   10
[8,] 85.34  30.744892    3
[9,] 85.08 -16.296103   68
[10,] 82.12  -9.209724   61
[11,] 80.85  33.632136   54
[12,] 83.62 -32.724031   47

> cbind(Test[2:14,10],Test[2:14,15])
           [,1] [,2]
[1,]  -6.951645   40
[2,]  -2.581847   33
[3,]   7.264525   26
[4,] -46.483134   20
[5,]  88.103500   12
[6,]  39.473314    5
[7,] -12.413910   89
[8,] -12.961001   82
[9,] -21.355713   75
[10,]  15.221032   68
[11,]  17.508519   61  
[12,]   8.811952   54
[13,]  18.064204   47

1 个答案:

答案 0 :(得分:0)

predict语句中,您必须指定type="class"

predicted <-predict(nnetfit,Test[2:13,c(10,15)],na.rm=TRUE, type="class")