if(ncol.matrix <rep){中的错误:参数的长度为零

时间:2019-05-22 10:05:48

标签: r neural-network

需要帮助了解什么会触发“ ncol.matrix

我已经浏览了神经网络https://rdrr.io/cran/neuralnet/src/R/neuralnet.r的源代码,还调整了我的神经网络功能的参数,但是似乎无法阻止此错误的发生。我不确定是否已经发布了这样的问题,但是我找不到任何解决方案,因此,如果有人之前曾见过这样的问题,可以将我链接到该解决方案。

我也已经标准化了“ WicketPerInnings”的目标列

Wnn <- neuralnet(
  WicketFormula,
  WTrain,
  algorithm = "rprop+",
  hidden = c(4,2),
  stepmax = 1e+03,
  threshold = 0.2,
  rep = 40,
  lifesign = 'full',
  learningrate = 0.01,
  startweights =  NULL,
  err.fct = "sse",
  linear.output = TRUE
)

WicketFormula <-
  "WicketPerInnings~ world_cup_matches+No_of_Matches + No_of_Innings_bowled+No_of_Balls_bowled + No_of_Runs_given+No_of_Wickets + Bowling_Ave + Economy_rate+Bowling_Strike_Rate + Span"

str(WTrain)给出

 $ Country             : chr  "Sri Lanka" "Bangladesh" "South Africa" "India" ...
 $ world_cup_matches   : num  2 1 0 0 9 0 0 0 0 6 ...
 $ No_of_Matches       : num  102 2 7 16 77 10 24 5 10 136 ...
 $ No_of_Innings_batted: num  84 2 4 5 72 8 22 3 8 113 ...
 $ No_of_Not_Out       : num  7 1 3 1 3 2 2 1 2 23 ...
 $ Runs_Scored         : num  1624 5 32 6 991 ...
 $ Highest_Score       : num  95 0 0 0 50 17 0 0 20 100 ...
 $ Batting_Average     : num  21.1 5 32 1.5 14.4 ...
 $ No_of_Balls_Faced   : num  2254 5 25 19 1461 ...
 $ Batting_Strike_Rate : num  72 100 128 31.6 67.8 ...
 $ No_of_Innings_bowled: num  10 2 7 16 75 9 12 5 10 117 ...
 $ No_of_Balls_bowled  : num  264 78 378 686 3385 ...
 $ No_of_Runs_given    : num  225 66 323 609 2865 ...
 $ No_of_Wickets       : num  2 1 7 24 67 5 6 8 13 69 ...
 $ Bowling_Ave         : num  112.5 66 46.1 25.4 42.8 ...
 $ Economy_rate        : num  5.11 5.07 5.12 5.32 5.07 4.99 3.76 4.17 2.8 4.79 ...
 $ Bowling_Strike_Rate : num  132 78 54 28.5 50.5 88 53.3 26.2 40.3 54.1 ...
 $ Span                : num  11 0 0 4 8 7 7 5 4 12 ...
 $ RunPerInnings       : num  19.3 2.5 8 1.2 13.8 ...
 $ WicketPerInnings    : num  0.0374 0.1337 0.2941 0.4545 0.2599 ...````

summary(WTrain) gives
````   Country          world_cup_matches No_of_Matches    No_of_Innings_batted No_of_Not_Out     Runs_Scored      Highest_Score    Batting_Average  No_of_Balls_Faced
 Length:756         Min.   : 0.000    Min.   :  1.00   Min.   :  1.00       Min.   : 0.000   Min.   :    1.0   Min.   :  0.00   Min.   : 0.000   Min.   :    1    
 Class :character   1st Qu.: 0.000    1st Qu.:  9.00   1st Qu.:  5.00       1st Qu.: 1.000   1st Qu.:   27.0   1st Qu.:  0.00   1st Qu.: 7.185   1st Qu.:   47    
 Mode  :character   Median : 0.000    Median : 26.00   Median : 15.50       Median : 4.000   Median :  120.0   Median : 11.00   Median :13.860   Median :  182    
                    Mean   : 5.152    Mean   : 54.51   Mean   : 40.45       Mean   : 8.757   Mean   :  899.3   Mean   : 30.32   Mean   :16.519   Mean   : 1184    
                    3rd Qu.: 7.000    3rd Qu.: 68.25   3rd Qu.: 44.25       3rd Qu.:12.000   3rd Qu.:  623.2   3rd Qu.: 50.00   3rd Qu.:24.000   3rd Qu.:  858    
                    Max.   :46.000    Max.   :463.00   Max.   :452.00       Max.   :80.000   Max.   :18426.0   Max.   :219.00   Max.   :95.000   Max.   :21367    
 Batting_Strike_Rate No_of_Innings_bowled No_of_Balls_bowled No_of_Runs_given  No_of_Wickets    Bowling_Ave      Economy_rate    Bowling_Strike_Rate
 Min.   :  6.25      Min.   :  1.00       Min.   :    2      Min.   :    1.0   Min.   :  1.0   Min.   :  1.00   Min.   : 1.500   Min.   :  2.00     
 1st Qu.: 54.37      1st Qu.:  6.75       1st Qu.:  232      1st Qu.:  186.8   1st Qu.:  5.0   1st Qu.: 27.82   1st Qu.: 4.327   1st Qu.: 34.95     
 Median : 69.17      Median : 17.00       Median :  674      Median :  546.5   Median : 15.0   Median : 34.41   Median : 4.865   Median : 42.95     
 Mean   : 69.01      Mean   : 37.65       Mean   : 1697      Mean   : 1312.4   Mean   : 41.9   Mean   : 39.24   Mean   : 4.901   Mean   : 48.15     
 3rd Qu.: 81.36      3rd Qu.: 48.00       3rd Qu.: 2081      3rd Qu.: 1656.2   3rd Qu.: 48.5   3rd Qu.: 43.94   3rd Qu.: 5.350   3rd Qu.: 53.92     
 Max.   :328.57      Max.   :365.00       Max.   :18433      Max.   :12066.0   Max.   :523.0   Max.   :201.00   Max.   :11.140   Max.   :222.00     
      Span        RunPerInnings    WicketPerInnings
 Min.   : 0.000   Min.   : 0.250   Min.   :0.0000  
 1st Qu.: 2.000   1st Qu.: 4.419   1st Qu.:0.1872  
 Median : 5.000   Median : 9.426   Median :0.2941  
 Mean   : 5.668   Mean   :12.630   Mean   :0.2990  
 3rd Qu.: 9.000   3rd Qu.:19.177   3rd Qu.:0.3904  
 Max.   :23.000   Max.   :49.220   Max.   :1.0000  ````

after running the code as it is, i encounter the error "Error in if (ncol.matrix < rep) { : argument is of length zero" and cannot proceed with prediction or anything else.

1 个答案:

答案 0 :(得分:0)

也是让我把头发拔掉了。

我发现此问题已合并到母版:https://github.com/bips-hb/neuralnet/pull/21

但是似乎还没有进入CRAN。

所以我通过github

安装了该库。
devtools::install_github("bips-hb/neuralnet")

它停止给出此错误。要安装它,您可能需要在计算机上安装R tools