调整神经网络的大小参数

时间:2017-12-08 01:16:38

标签: r neural-network r-caret nnet

我想使用插入符号包来拟合神经网络模型。有208个预测变量,所有这些都很重要,不能丢弃。 我可以给size参数的最大值是4,超过该值我会收到一个错误,说明权重太多。

> ctrl<-trainControl(method = 'cv',number = 5)
> my.grid <- expand.grid(.decay = 0.1, .size =5)
> nn.fit <- train(train_predictors,train_responses[["r2c1"]],method = "nnet",algorithm = 'backprop', tuneGrid = my.grid,trace=F, linout = TRUE,trControl = ctrl)
Something is wrong; all the RMSE metric values are missing:
      RMSE        Rsquared        MAE     
 Min.   : NA   Min.   : NA   Min.   : NA  
 1st Qu.: NA   1st Qu.: NA   1st Qu.: NA  
 Median : NA   Median : NA   Median : NA  
 Mean   :NaN   Mean   :NaN   Mean   :NaN  
 3rd Qu.: NA   3rd Qu.: NA   3rd Qu.: NA  
 Max.   : NA   Max.   : NA   Max.   : NA  
 NA's   :1     NA's   :1     NA's   :1    
Error: Stopping
In addition: Warning messages:
1: model fit failed for Fold1: decay=0.1, size=5 Error in nnet.default(x, y, w, ...) : too many (1051) weights

2: model fit failed for Fold2: decay=0.1, size=5 Error in nnet.default(x, y, w, ...) : too many (1051) weights

3: model fit failed for Fold3: decay=0.1, size=5 Error in nnet.default(x, y, w, ...) : too many (1051) weights

4: model fit failed for Fold4: decay=0.1, size=5 Error in nnet.default(x, y, w, ...) : too many (1051) weights

5: model fit failed for Fold5: decay=0.1, size=5 Error in nnet.default(x, y, w, ...) : too many (1051) weights

6: In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo,  :
  There were missing values in resampled performance measures.

该模型对4个神经元(大小= 4)表现非常糟糕。如果我想拥有超过5个神经元,我该怎么做才能使模型有效?

2 个答案:

答案 0 :(得分:1)

您始终可以使用插入符...方法中的train可选参数将其他参数传递给基础训练方法(在本例中为nnet)。 nnet程序包的CRAN文档描述了MaxNwts参数,该参数可以控制最大隐藏单元数。

答案 1 :(得分:0)

您可以为nnet方法指定调整网格中的其他参数。每种方法的可用参数都可在线获得,但很难找到。以下是使用mxnet for adam nn:

的示例
mxnet_grid_A2 = expand.grid(layer1 = c(10, 12),   
                           layer2 = c(4, 6),
                           layer3 = 2,
                           learningrate = c(0.001, 0.0001),
                           dropout = c(0, 0.2)
                           beta1 = .9,
                           beta2 = 0.999,
                           activation = 'relu')