R神经网络软件包-net.result显示什么? [英] R Neural Network Package - what does net.result show?

查看:272
本文介绍了R神经网络软件包-net.result显示什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码,我构建了一个神经网络模型来预测收盘价:

Using the following code I have constructed a neural network model to predict the close price:

library(neuralnet)
myformula <- close ~ High+Low+Open 
nn_close <- neuralnet(myformula,data=train_,hidden=c(5,3),linear.output=T)
nn_close$net.result[[1]]

有人可以向我解释nn_close$net.result[[1]]行是什么吗?我已经查看了 CRAN文档,但目前尚不清楚给我.

Could someone explain to me what the nn_close$net.result[[1]] line does? I have checked the CRAN documentation but this is still not clear to me.

推荐答案

compute()$net.result的结果仅包含一个级别,这给出了每个样本成为给定物种的概率(在此示例中).换句话说,行的总和(大约)等于1.在下面的示例中,我已使用此信息来预测数据的验证子集中的种类,并使用:

The results from compute()$net.result only contain one level and this gives the probability of each sample to be a given species (in this example). In other words, the sum of the rows is (roughly) equal to 1. In the following example, I have used this information to predict the species in the validation subset of the data, and these are compared with their true values using table:

# install.packages("neuralnet")
library(neuralnet)

# adapted iris
data(iris)
iris2 <- iris
iris2$setosa <- c(iris2$Species == 'setosa')
iris2$versicolor <- c(iris2$Species == 'versicolor')
iris2$virginica <- c(iris2$Species == 'virginica')
# iris2$Species <- NULL

# training and validation subsets
train.samples <- sample(nrow(iris), nrow(iris)*0.5)
train <- iris2[train.samples,]
valid <- iris2[-train.samples,]

# fit model
inet <- neuralnet(setosa + versicolor + virginica ~ Sepal.Length + Sepal.Width + 
  Petal.Length + Petal.Width, train, hidden=3, lifesign="full")

# prediction 
pred <- compute(inet, valid[,1:4])
head(pred$net.result) # only one level (probability of each category)
predspp <- factor(c("setosa" , "versicolor", "virginica"))[apply(pred$net.result, MARGIN=1, FUN=which.max)]
table(predspp, valid$Species)
# predspp      setosa versicolor virginica
#   setosa         19          0         0
#   versicolor      0         24         4
#   virginica       0          2        26

在我的情况下,所有setosa样本均已正确预测.对于杂色和弗吉尼亚州,分别有2个和4个错误的预测.通常,对于92%的验证样本(69/75 * 100),预测是正确的.

In my case, all setosa samples were correctly predicted. There were 2 and 4 false predictions for versicolor and virginica, respectively. Generally, the prediction was correct for 92% of the validation samples (69/75 * 100).

这篇关于R神经网络软件包-net.result显示什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆