首页 > 解决方案 > 平均神经网络 (avNNet) 是所有迭代的平均值吗?

问题描述

我用插入符号在 R 中安装了一个平均神经网络。请参阅下面的代码。平均一词是否意味着平均值基于 1000 个神经网络的结果?(因为在这种情况下有 1000 次迭代)

谢谢。

library(AppliedPredictiveModeling)
data(solubility)

### Create a control funciton that will be used across models. We
### create the fold assignments explictily instead of relying on the
### random number seed being set to identical values.

library(caret)
set.seed(100)
indx <- createFolds(solTrainY, returnTrain = TRUE)
ctrl <- trainControl(method = "cv", index = indx)

################################################################################
### Section 7.1 Neural Networks

### Optional: parallel processing can be used via the 'do' packages,
### such as doMC, doMPI etc. We used doMC (not on Windows) to speed
### up the computations.

### WARNING: Be aware of how much memory is needed to parallel
### process. It can very quickly overwhelm the availible hardware. We
### estimate the memory usuage (VSIZE = total memory size) to be 
### 2677M/core.

library(doMC)
registerDoMC(10)


library(caret)

nnetGrid <- expand.grid(decay = c(0, 0.01, .1), 
                        size = c(1, 3, 5, 7, 9, 11, 13), 
                        bag = FALSE)

set.seed(100)
nnetTune <- train(x = solTrainXtrans, y = solTrainY,
                  method = "avNNet",
                  tuneGrid = nnetGrid,
                  trControl = ctrl,
                  preProc = c("center", "scale"),
                  linout = TRUE,
                  trace = FALSE,
                  MaxNWts = 13 * (ncol(solTrainXtrans) + 1) + 13 + 1,
                  maxit = 1000,
                  allowParallel = FALSE)
nnetTune

plot(nnetTune)

testResults <- data.frame(obs = solTestY,
                          NNet = predict(nnetTune, solTestXtrans))

################################################################################

也可以看看:

https://scientistcafe.com/post/nnet.html

标签: rneural-networkr-caretnnet

解决方案


avNNet是一个模型,其中相同的神经网络模型使用不同的随机数种子进行拟合。所有生成的模型都用于预测。对于回归,每个网络的输出是平均的。对于分类,首先对模型分数进行平均,然后将其转换为预测类别。来源

拟合模型的数量由通过传递给模型的参数repeats控制caret...

repeats - the number of neural networks with different random number seeds. 默认情况下,这设置为5。因此将平均五个模型。在插入符号对模型的定义中,我没有看到这种变化。

如果bag参数设置为TRUE模型拟合,并且聚合由bootstrap aggregation执行,我认为如果模型数量足够多,几乎可以保证提供更好的预测性能。


推荐阅读