神经网络,插入符号和交叉验证

时间:2016-04-11 17:37:33

标签: r neural-network r-caret

我有一个非常大的数据集,包含36个功能,包括6个输出列。我试图在这个数据集中进行MLP反向传播神经网络学习(回归),我正在使用神经网络和插入符号。我想要两个隐藏层,每层有6个和5个节点。我还想在我的NN模型中添加k折叠交叉验证

    control <- trainControl(method="repeatedcv", number=5, repeats=1)
    # train the model
    model <- train(X,Y, method="neuralnet", 
               algorithm = "backprop", learningrate = 0.25,act.fct = 'tanh',
               tuneGrid = data.frame(layer1 = 2:6, layer2 = 2:6, layer3 = 0),threshold = 0.1, trControl=control)
warnings()

其中X和Y分别是特征和预测数据框

但是它给出错误和警告

Error in train.default(X, Y, method = "neuralnet", algorithm = "backprop",  : 
  wrong model type for classification
> warnings()
Warning messages:
1: In eval(expr, envir, enclos) :
  model fit failed for Resample01: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

2: In eval(expr, envir, enclos) :
  model fit failed for Resample02: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

3: In eval(expr, envir, enclos) :
  model fit failed for Resample03: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

4: In eval(expr, envir, enclos) :
  model fit failed for Resample04: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

5: In eval(expr, envir, enclos) :
  model fit failed for Resample05: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

6: In eval(expr, envir, enclos) :
  model fit failed for Resample06: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

7: In eval(expr, envir, enclos) :
  model fit failed for Resample07: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

8: In eval(expr, envir, enclos) :
  model fit failed for Resample08: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

9: In eval(expr, envir, enclos) :
  model fit failed for Resample09: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

10: In eval(expr, envir, enclos) :
  model fit failed for Resample10: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

11: In eval(expr, envir, enclos) :
  model fit failed for Resample11: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

12: In eval(expr, envir, enclos) :
  model fit failed for Resample12: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

13: In eval(expr, envir, enclos) :
  model fit failed for Resample13: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

14: In eval(expr, envir, enclos) :
  model fit failed for Resample14: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

15: In eval(expr, envir, enclos) :
  model fit failed for Resample15: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

16: In eval(expr, envir, enclos) :
  model fit failed for Resample16: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

17: In eval(expr, envir, enclos) :
  model fit failed for Resample17: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

18: In eval(expr, envir, enclos) :
  model fit failed for Resample18: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

19: In eval(expr, envir, enclos) :
  model fit failed for Resample19: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

20: In eval(expr, envir, enclos) :
  model fit failed for Resample20: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

21: In eval(expr, envir, enclos) :
  model fit failed for Resample21: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

22: In eval(expr, envir, enclos) :
  model fit failed for Resample22: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

23: In eval(expr, envir, enclos) :
  model fit failed for Resample23: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

24: In eval(expr, envir, enclos) :
  model fit failed for Resample24: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

25: In eval(expr, envir, enclos) :
  model fit failed for Resample25: layer1=4, layer2=1, layer3=1 Error in if (reached.threshold < min.reached.threshold) { : 
  missing value where TRUE/FALSE needed

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

1 个答案:

答案 0 :(得分:1)

如果您不介意,可以使用“neuralnet”软件包手动进行交叉验证。以下是“A(快速)交叉验证”部分中的示例:https://www.r-bloggers.com/fitting-a-neural-network-in-r-neuralnet-package/