<div id="Main" ></div>
<iframe src="frmtest1.aspx" style="display:none"></iframe>
<iframe src="frmtest2.aspx" style="display:none"></iframe>
<input type="button" id="LoadTest1" />
<input type="button" id="LoadTest2" />
嗨,鉴于上述内容。我已经构建了一个神经网络模型,我将用它来尝试预测收盘价。有人可以向我解释myformula <- close ~ High+Low+Open
nn_close <- neuralnet(myformula,data=train_,hidden=c(5,3),linear.output=T)
nn_close$net.result[[1]]
行的作用吗?我检查了CRAN documentation,但这对我来说仍然不清楚。
答案 0 :(得分:1)
你会通过一个例子更好地理解这一点(我修改了一下但我从here得到了它):
itrain <- iris[sample(1:150, 50),]
itrain$setosa <- c(itrain$Species == 'setosa')
itrain$versicolor <- c(itrain$Species == 'versicolor')
itrain$virginica <- c(itrain$Species == 'virginica')
itrain$Species <- NULL
inet <- neuralnet(setosa + versicolor + virginica ~ Sepal.Length + Sepal.Width +
Petal.Length + Petal.Width, itrain, hidden=3, lifesign="full")
#make a prediction on the training set and then compare to
#inet$net.result[[1]]
predict <- compute(inet, itrain[1:4])
现在看一下结果:
head(predict$net.result)
# [,1] [,2] [,3]
#80 0.0167232688257 0.995316738272 -0.011840391533
#112 -0.0008289388986 -0.006814451178 1.007637170495
#17 1.0028534166840 0.004240124926 -0.007115290101
#104 -0.0002256650283 -0.031771967776 1.031855488316
#149 0.0019424886784 0.007205356060 0.990892583485
#82 -0.0061699713404 0.957656929739 0.048564910023
head(inet$net.result[[1]])
# [,1] [,2] [,3]
#80 0.0167232688257 0.995316738272 -0.011840391533
#112 -0.0008289388986 -0.006814451178 1.007637170495
#17 1.0028534166840 0.004240124926 -0.007115290101
#104 -0.0002256650283 -0.031771967776 1.031855488316
#149 0.0019424886784 0.007205356060 0.990892583485
#82 -0.0061699713404 0.957656929739 0.048564910023
我使用compute
使用神经网络模型对训练集进行预测。
正如您所看到的,inet$net.result[[1]]
和predict$net.result
是相同的。因此,inet$net.result[[1]]
只是您用于训练模型的数据集的预测(它与lm
模型的拟合值相同)。
根据@sebastianmm非常有用的评论,有net.result
列表的原因。基本上,neuralnet
具有参数rep
,这使得可以在一次调用中训练多个模型。当rep
大于1时,net.result
将大于1(其他组件也是如此(weights
,result.matrix
,start.weights
))。
答案 1 :(得分:1)
compute()$net.result
的结果只包含一个级别,这给出了每个样本成为给定物种的概率(在本例中)。换句话说,行的总和(大致)等于1.在下面的示例中,我使用此信息来预测数据验证子集中的物种,并使用{{将它们与真实值进行比较。 1}}:
table
在我的情况下,所有setosa样本都被正确预测。对于云芝和维吉尼亚分别有2和4个错误的预测。通常,92%的验证样本(69/75 * 100)的预测是正确的。