r - 平均神经网络 (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))
################################################################################
也可以看看:
解决方案
avNNet
是一个模型,其中相同的神经网络模型使用不同的随机数种子进行拟合。所有生成的模型都用于预测。对于回归,每个网络的输出是平均的。对于分类,首先对模型分数进行平均,然后将其转换为预测类别。来源。
拟合模型的数量由通过传递给模型的参数repeats
控制caret
...
repeats - the number of neural networks with different random number seeds
. 默认情况下,这设置为5
。因此将平均五个模型。在插入符号对模型的定义中,我没有看到这种变化。
如果bag
参数设置为TRUE
模型拟合,并且聚合由bootstrap aggregation执行,我认为如果模型数量足够多,几乎可以保证提供更好的预测性能。
推荐阅读
- php - 使用来自 Laravel 控制器的值重定向 URL
- html - 如何仅删除最后一个 css 规则而不影响除此之外的任何其他 n 个最后一个规则
- android - ARCore Unity 图像捕捉
- mongodb - 投影在 mongodb npm 版本 3.1.8 中未按预期工作
- javascript - 使用角度形式将元素值形成为 JSON
- shell - 删除超过 2 年的大型媒体文件的脚本,其中删除了同名和日期的文本文件
- python - 如何在 Python 中保存元组对象中的数据?
- go - 如何查找未分配的结构字段
- c# - 运行多个进程、C++ 和 Excel 导致的错误
- ruby - ruby - 将http响应正文从xml转换为哈希的问题 - 缺少属性引用错误