Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upIssue when predicting probabilities with multinom and one observation #827
Comments
|
That should do it but please test on your data. If you don't want to install from github, you can source the file in |
When predicting probability from a multinom model, if there is only one observation in the new data set, the predict function of the train class is flashing an error.
Reproductible exemple:
Error:
I guess it comes from the fact that output of predict.nnet in case of multiple observations is a matrix whereas in the case of one observation it is a named vector.
Session Info:
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] caret_6.0-76 ggplot2_2.2.1 lattice_0.20-35 nnet_7.3-12
[5] MASS_7.3-47
loaded via a namespace (and not attached):
[1] Rcpp_0.12.11 magrittr_1.5 splines_3.4.1
[4] munsell_0.4.3 colorspace_1.3-2 rlang_0.1.2
[7] foreach_1.4.3 minqa_1.2.4 stringr_1.2.0
[10] car_2.1-5 plyr_1.8.4 tools_3.4.1
[13] parallel_3.4.1 pbkrtest_0.4-7 grid_3.4.1
[16] gtable_0.2.0 nlme_3.1-131 mgcv_1.8-17
[19] pacman_0.4.6 quantreg_5.33 e1071_1.6-8
[22] class_7.3-14 MatrixModels_0.4-1 iterators_1.0.8
[25] lme4_1.1-13 lazyeval_0.2.0 tibble_1.3.3
[28] Matrix_1.2-10 nloptr_1.0.4 reshape2_1.4.2
[31] ModelMetrics_1.1.0 codetools_0.2-15 stringi_1.1.5
[34] compiler_3.4.1 scales_0.5.0 stats4_3.4.1
[37] SparseM_1.77