Need help understanding what triggers "ncol.matrix < rep" error.
I have browsed through the source code for neuralnet https://rdrr.io/cran/neuralnet/src/R/neuralnet.r, and also tweak with the parameters of the my neuralnet function but i cannot seem to stop this error from occuring. I am not sure if such question has already been posted, but i cannot find any solution so, if anyone has seen such question before, can you link me to the solution.
I have also normalise the target column of "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) gives
$ 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.
While the meaning of the error message “argument is of length zero” is not obvious at first, it makes sense once you understand what is causing it. This fact also makes it an easy error to fix. This error message occurs when using a For Loop with a dataframe using with an incorrect column name.
So when in the situation above, we called a non-existent column name as argument in a logical statement the compiler returned our error message. The reason for the precise error message makes sense, given the fact that the length of a non-existing column is zero.
The RStudio console returns the error message “argument is of length zero”. The reason for this is that we have used an empty data object in the logical condition within the if-statement (i.e. x1 > 5). This is not possible in R and therefore the RStudio console returns an error. Next, I’ll explain how to solve this problem…
This error usually occurs when you attempt to make some logical comparison within an if statement in R, but the variable that you’re using in the comparison is of length zero. Two examples of variables with length zero are numeric () or character (0). The following example shows how to resolve this error in practice.
It was having me pulling my hair out too.
I found this issue had been merged to master: https://github.com/bips-hb/neuralnet/pull/21.
But doesn't seem like it has made it to CRAN yet.
So I installed the library through github
devtools::install_github("bips-hb/neuralnet")
And it stopped giving this error. To get it to install, you may need to install R tools on your machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With