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

Error in `train` when `method = "bartMachine"` #1278

Open rachaelvp opened 2 years ago

rachaelvp commented 2 years ago

Hello,

Please see the example below that generates the following error: Error in if (grepl("adaptive", trControl$method) & nrow(tuneGrid) == 1) { : argument is of length zero. I believe this is because the grid function for method="bartMachine" does not return anything: https://github.com/topepo/caret/blob/0579b5dded32f5af9c4c6f4ef5a3898d3839c4d0/models/files/bartMachine.R#L12-L30.

Minimal reproducible example of error:

library(caret)
set.seed(83)
d <- SLC14_1()
fit <- train(x = as.matrix(d[,-15]), y = d[,15], method = "bartMachine")

Example continued, showing what's returned by the grid function for method="bartMachine":

models <- getModelInfo("bartMachine", regex = F)[[1]]
tuneGrid <- models$grid(x = as.matrix(d[,-15]), y = d[,15], len = 3)
tuneGrid

Session Info:

R version 4.1.2 (2021-11-01) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.2.1

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages: [1] caret_6.0-91 lattice_0.20-45 ggplot2_3.3.5

loaded via a namespace (and not attached): [1] tidyselect_1.1.2 purrr_0.3.4 reshape2_1.4.4
[4] listenv_0.8.0 rJava_1.0-6 splines_4.1.2
[7] colorspace_2.0-3 vctrs_0.3.8 generics_0.1.2
[10] stats4_4.1.2 utf8_1.2.2 survival_3.2-13
[13] prodlim_2019.11.13 rlang_1.0.2 ModelMetrics_1.2.2.2 [16] pillar_1.7.0 glue_1.6.2 withr_2.5.0
[19] DBI_1.1.2 foreach_1.5.2 lifecycle_1.0.1
[22] plyr_1.8.6 lava_1.6.10 stringr_1.4.0
[25] timeDate_3043.102 munsell_0.5.0 gtable_0.3.0
[28] future_1.24.0 recipes_0.2.0 codetools_0.2-18
[31] parallel_4.1.2 class_7.3-20 fansi_1.0.2
[34] itertools_0.1-3 bartMachine_1.2.6 Rcpp_1.0.8.3
[37] scales_1.1.1 ipred_0.9-12 parallelly_1.30.0
[40] digest_0.6.29 stringi_1.7.6 dplyr_1.0.8
[43] grid_4.1.2 hardhat_0.2.0 cli_3.2.0
[46] tools_4.1.2 missForest_1.4 magrittr_2.0.2
[49] tibble_3.1.6 randomForest_4.7-1 crayon_1.5.0
[52] future.apply_1.8.1 pkgconfig_2.0.3 ellipsis_0.3.2
[55] MASS_7.3-55 Matrix_1.4-0 data.table_1.14.2
[58] bartMachineJARs_1.1 pROC_1.18.0 lubridate_1.8.0
[61] gower_1.0.0 assertthat_0.2.1 iterators_1.0.14
[64] R6_2.5.1 globals_0.14.0 rpart_4.1.16
[67] nnet_7.3-17 nlme_3.1-155 compiler_4.1.2