topepo / caret

caret (Classification And Regression Training) R package that contains misc functions for training and plotting classification and regression models
http://topepo.github.io/caret/index.html
1.61k stars 634 forks source link

About predict.knn3 #1314

Open winkingonly opened 1 year ago

winkingonly commented 1 year ago

Hello caret team, when I use predict.knn3 get error。If I use stats::predict(knn_model,testset[-1],type="prob"),there are no errors. I don't know why。 I want Predictions from k-Nearest Neighbors. Thank you.

main code: ... trcl=trainControl(method="cv", number =10) trgrid<-expand.grid(k=seq(1,10,1)) knn_model <- train(label ~ ., data = trainset,method= "knn", trControl = trcl,tuneGrid = trgrid) pre<-caret::predict(knn_model,testset[-1],type="prob") Error: Error: 'predict' is not an exported object from 'namespace:caret'

R version 4.0.2 (2020-06-22) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=Chinese (Simplified)_China.936 [2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936 [4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936

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

other attached packages: [1] caret_6.0-92 lattice_0.20-41 ggplot2_3.3.3

sessionInfo() loaded via a namespace (and not attached): [1] Rcpp_1.0.5 pillar_1.4.7 compiler_4.0.2
[4] gower_0.2.2 plyr_1.8.6 iterators_1.0.13
[7] class_7.3-17 tools_4.0.2 packrat_0.5.0
[10] rpart_4.1-15 ipred_0.9-9 lubridate_1.7.9.2
[13] lifecycle_0.2.0 tibble_3.0.3 nlme_3.1-148
[16] gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.10
[19] Matrix_1.2-18 foreach_1.5.2 prodlim_2019.11.13
[22] e1071_1.7-9 stringr_1.4.0 withr_2.4.1
[25] dplyr_1.0.2 pROC_1.17.0.1 generics_0.1.0
[28] vctrs_0.3.4 recipes_0.1.15 stats4_4.0.2
[31] grid_4.0.2 nnet_7.3-14 tidyselect_1.1.0
[34] data.table_1.13.0 glue_1.4.2 R6_2.5.0
[37] survival_3.1-12 lava_1.6.8.1 reshape2_1.4.4
[40] purrr_0.3.4 magrittr_2.0.1 ModelMetrics_1.2.2.2 [43] scales_1.1.1 codetools_0.2-16 ellipsis_0.3.1
[46] MASS_7.3-51.6 splines_4.0.2 timeDate_3043.102
[49] colorspace_1.4-1 proxy_0.4-26 stringi_1.5.3
[52] munsell_0.5.0 crayon_1.4.0