0

我有问题。我有一个数据集很多功能。当我尝试使用插入符号 R 执行我的 nnet 时,给我一个错误。如果我尝试执行一小部分功能,nnet 会收敛。

这是我的代码:

> dim(trainT)
[1]  130 3413
> nnFit <- train(target ~ ., data = trainT,
+ method = "nnet",
+                trControl = fitControl#,
+                #trControl = ctrl, metric = "ROC", 
+                #verbose = TRUE#,
+                #tuneGrid = nnGrid
+ )
Something is wrong; all the Accuracy metric values are missing:
    Accuracy       Kappa    
 Min.   : NA   Min.   : NA  
 1st Qu.: NA   1st Qu.: NA  
 Median : NA   Median : NA  
 Mean   :NaN   Mean   :NaN  
 3rd Qu.: NA   3rd Qu.: NA  
 Max.   : NA   Max.   : NA  
 NA's   :9     NA's   :9    
Error in train.default(x, y, weights = w, ...) : Stopping
In addition: There were 50 or more warnings (use warnings() to see the first 50)
>
> nnFit <- train(target ~ ., data = trainT[,1:100],
               method = "nnet",
               trControl = fitControl#,
               #trControl = ctrl, metric = "ROC", 
               #verbose = TRUE#,
               #tuneGrid = nnGrid
)
# weights:  102
initial  value 65.440715 
iter  10 value 34.586483
iter  20 value 25.531746
iter  30 value 22.930604
iter  40 value 22.919387
iter  50 value 20.326238
iter  60 value 20.018595
iter  70 value 5.289718
iter  80 value 0.016055
final  value 0.000063 
converged
# weights:  304
initial  value 85.540457 
iter  10 value 25.219303
iter  20 value 5.562977
iter  30 value 4.712105
iter  40 value 4.676887
iter  50 value 4.625627
iter  60 value 4.622304
iter  70 value 4.597801
iter  80 value 4.582877
iter  90 value 4.570602
iter 100 value 4.569542
final  value 4.569542 
stopped after 100 iterations
[...]
initial  value 75.037558 
iter  10 value 4.301843
iter  20 value 1.495044
iter  30 value 0.159978
iter  40 value 0.118735
iter  50 value 0.110560
iter  60 value 0.101595
iter  70 value 0.079860
iter  80 value 0.073034
iter  90 value 0.065459
iter 100 value 0.052024
final  value 0.052024 
stopped after 100 iterations
# weights:  506
initial  value 95.448738 
iter  10 value 20.859400
iter  20 value 6.493820
iter  30 value 5.597509
iter  40 value 5.516322
iter  50 value 5.510970
iter  60 value 5.510881
final  value 5.510881 
converged

你能帮助我吗?:)

PS:会议信息:

> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252   
[3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C                  
[5] LC_TIME=Italian_Italy.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] nnet_7.3-9      caret_6.0-47    ggplot2_1.0.1   lattice_0.20-31

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.6         magrittr_1.5        splines_3.2.0       MASS_7.3-40        
 [5] munsell_0.4.2       colorspace_1.2-6    foreach_1.4.2       minqa_1.2.4        
 [9] car_2.0-25          stringr_1.0.0       plyr_1.8.2          tools_3.2.0        
[13] parallel_3.2.0      pbkrtest_0.4-2      grid_3.2.0          gtable_0.1.2       
[17] nlme_3.1-120        mgcv_1.8-6          quantreg_5.11       e1071_1.6-4        
[21] class_7.3-12        iterators_1.0.7     gtools_3.5.0        lme4_1.1-7         
[25] digest_0.6.8        Matrix_1.2-0        nloptr_1.0.4        reshape2_1.4.1     
[29] codetools_0.2-11    stringi_0.4-1       compiler_3.2.0      BradleyTerry2_1.0-6
[33] scales_0.2.4        SparseM_1.6         brglm_0.5-9         proto_0.3-10  

编辑:我在我的代码中忘记了一个逗号 :( 我只是 col 并且仅用于测试。

@cyberj0g:

我试试你的建议:

1-分析我看到的摘要都是数字。

2-如果我调用警告 () 不会返回任何内容,但是如果我在完成 nnet me 之前尝试停止:

        > nnFit <- train(target ~ ., data = trainT,
    +                method = "nnet",
    +                trControl = fitControl#,
    +                #trControl = ctrl, metric = "ROC", 
    +                #verbose = TRUE#,
    +                #tuneGrid = nnGrid
    + )

    Warning messages:
    1: In eval(expr, envir, enclos) :
      model fit failed for Fold1.Rep1: size=1, decay=0e+00 Error in nnet.default(x, y, w, entropy = TRUE, ...) : 
      too many (3011) weights

    2: In eval(expr, envir, enclos) :
      model fit failed for Fold1.Rep1: size=3, decay=0e+00 Error in nnet.default(x, y, w, entropy = TRUE, ...) : 
      too many (9031) weights

    3: In eval(expr, envir, enclos) :
      model fit failed for Fold1.Rep1: size=5, decay=0e+00 Error in nnet.default(x, y, w, entropy = TRUE, ...) : 
      too many (15051) weights

    4: In eval(expr, envir, enclos) :
      model fit failed for Fold1.Rep1: size=1, decay=1e-01 Error in nnet.default(x, y, w, entropy = TRUE, ...) : 
      too many (3011) weights

    5: In eval(expr, envir, enclos) :
      model fit failed for Fold1.Rep1: size=3, decay=1e-01 Error in nnet.default(x, y, w, entropy = TRUE, ...) : 
      too many (9031) weights

3-如果我增加 cv 的数量(如果我理解你对它的理解)问题是一样的:

    > fitControl <- trainControl(## 5-fold CV
+   method = "repeatedcv",
+   number = 1000,
+   ## repeated 5 times
+   repeats = 5)
> nnFit <- train(target ~ ., data = trainT,
+                method = "nnet",
+                trControl = fitControl#,
+                #trControl = ctrl, metric = "ROC", 
+                #verbose = TRUE#,
+                #tuneGrid = nnGrid
+ )

There were 50 or more warnings (use warnings() to see the first 50)
4

1 回答 1

0

目前尚不清楚导致错误的原因,但我建议如下:

  1. 检查您的数据是否有异常:summary(trainT)
  2. 错误后检查警告:warnings()
  3. 尝试增加迭代次数:trainControl(number=1000)

此外,您的完整数据集几乎没有足够的样本来训练具有 130 个预测变量的模型(但这取决于)。仅在 100 个样本上收敛很可能毫无意义。

于 2015-06-04T13:13:28.243 回答