0

我正在尝试进行简单的神经网络建模,但 NNet 结果给了我很差的结果。我希望 nnet 模型学习的只是“输出 = 0.5 x 输入”模型,但预测结果显示所有“1”。怎么了?

library(neuralnet)
traininginput <- as.data.frame(runif(50,min=1,max=100))
trainingoutput <- traininginput/2

trainingdata<-cbind(traininginput,trainingoutput)
colnames(trainingdata)<-c("Input","Output")

net.sqrt2 <- nnet(trainingdata$Output~trainingdata$Input,size=0,skip=T, linout=T)


Testdata<-as.data.frame(1:50)
net.result2<-predict(net.sqrt2, Testdata)

cleanoutput2 <- cbind(Testdata,Testdata/2,as.data.frame(net.result2))
colnames(cleanoutput2)<-c("Input2","Expected Output2","Neural Net Output2")
print(cleanoutput2)
4

1 回答 1

1
library(nnet)
traininginput <- as.data.frame(runif(50,min=1,max=100))
trainingoutput <- traininginput/2

trainingdata<-cbind(traininginput,trainingoutput)
colnames(trainingdata)<-c("Input","Output")

net.sqrt2 <- nnet(Output~Input, data=trainingdata, size=0,skip=T, linout=T)


Testdata<-data.frame(Input=1:50)
net.result2<-predict(net.sqrt2, newdata = Testdata, type="raw")

cleanoutput2 <- cbind(Testdata,Testdata/2,as.data.frame(net.result2))
colnames(cleanoutput2)<-c("Input2","Expected Output2","Neural Net Output2")
print(cleanoutput2)

您正在使用并且predict错误。Predict 预计需要为模型的一列输入(即在本例中称为 的列)。in不是通过对数据的文字调用来构建的。它是象征性的,所以它应该是数据中列的名称。此外,您使用的包不是but 。formulannetnewdatadata.frameInputformulannetneuralnetnnet

于 2015-05-31T10:02:08.963 回答