我用Caret拟合了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))
################################################################################
另请参阅:
答案 0 :(得分:0)
avNNet
是一个模型,其中使用不同的随机数种子拟合相同的神经网络模型。所有得到的模型都用于预测。为了进行回归,对每个网络的输出求平均值。对于分类,首先将模型得分平均,然后转换为预测的类别。 Source。
适合的模型数量由参数repeats
控制,该参数通过caret
传递给...
中的模型
repeats - the number of neural networks with different random number seeds
。默认情况下,它设置为5
。因此,将平均五个模型。在caret's definition of the model中,我看不到这种变化。
如果将bag
参数设置为TRUE
,则模型拟合和聚合由bootstrap aggregation执行,在我看来,如果模型数量为10,则几乎可以保证提供更好的预测性能足够高。