Hyperparameter tuning of models of baguette

Hi everyone,

I was trying to train four models including bagged decision tree, multivariate adaptive regression splines (MARS), bagged MARS, and rulefit models, to tune hyperparameter using bayesian optimization, and to stack those models. However, the running failed. Do anyone can help me ?

library(pacman)
p_load(tidymodels, tidyverse, finetune, themis, baguette, xrf, rules, stacks, naivebayes, discrim, plsmod, poissonreg, workflowsets, doParallel, recipeselectors, keras, prospectr, sparsediscrim, treesnip, lightgbm)
#registerDoParallel(2)

data("iris")

hyperspectral_data <- iris

set.seed(1234)

hyperspectral_split <- initial_split(hyperspectral_data, prop = 0.7, strata = "Species")
hyperspectral_training <- training(hyperspectral_split)
hyperspectral_testing  <- testing(hyperspectral_split)

set.seed(5678)
k_cv <- vfold_cv(hyperspectral_training, v = 5, repeats = 5)

hyper_rep_raw    <- hyperspectral_training %>%
  recipe(Species ~ ., ) 

Bagged_dc_model <- bag_tree(cost_complexity = tune(), tree_depth = tune(), min_n = tune(), class_cost = tune()) %>%
  set_mode("classification") %>% 
  set_engine("rpart", times = 25) 

mars_model <- mars(num_terms = tune(), prod_degree = tune()) %>%    
  set_engine("earth") %>% 
  set_mode("classification")

bag_mars_model <- bag_mars(num_terms = tune(), prod_degree = tune()) %>%    
  set_engine("earth") %>% 
  set_mode("classification")  

rule_model <- rule_fit(trees = tune(), min_n = tune(), tree_depth = tune(), learn_rate = tune(), loss_reduction = tune(), sample_size = tune(), penalty = tune()) %>% 
  set_engine("xrf") %>% 
  set_mode("classification") 

chi_models <- workflow_set(preproc = list(raw = hyper_rep_raw), 
                           models  = list(Bagged_dc_model = Bagged_dc_model,
                                          mars_model = mars_model,
                                          bag_mars_model = bag_mars_model,
                                          rule_model = rule_model),
                           cross = TRUE) 

set.seed(2021)
tune_bayes_models_res <- chi_models %>% 
  workflow_map("tune_bayes", resamples = k_cv, initial = 5 , iter = 8,
               metrics  = metric_set(accuracy, roc_auc), verbose = TRUE, 
               control  = control_stack_bayes()
  ) 
#> i 1 of 4 tuning:     raw_Bagged_dc_model
#> x Fold1, Repeat1: preprocessor 1/1, model 1/5: Error in `cost_matrix()`: `cost` can only b...
#> Warning: All models failed. See the `.notes` column.
#> x 1 of 4 tuning:     raw_Bagged_dc_model failed with: Error in estimate_tune_results(unsummarized) :   All of the models failed. See the .notes column.
#> i 2 of 4 tuning:     raw_mars_model
#> ! Fold1, Repeat1: preprocessor 1/1, model 1/2: glm.fit: algorithm did not converge, glm.fi...
#> Warning: All models failed. See the `.notes` column.
#> x 2 of 4 tuning:     raw_mars_model failed with: Error in estimate_tune_results(unsummarized) :   All of the models failed. See the .notes column.
#> i 3 of 4 tuning:     raw_bag_mars_model
#> ! Fold1, Repeat1: preprocessor 1/1, model 1/4: glm.fit: algorithm did not converge, glm.fi...
#> x Fold1, Repeat1: preprocessor 1/1, model 1/4 (predictions): Error in `stop_subscript()`: ...
#> Warning: All models failed. See the `.notes` column.
#> x 3 of 4 tuning:     raw_bag_mars_model failed with: Error in estimate_tune_results(unsummarized) :   All of the models failed. See the .notes column.
#> i 4 of 4 tuning:     raw_rule_model
#> ! There are 7 tuning parameters and 5 grid points were requested. This is
#>   likely to cause numerical issues in the first few search iterations.
#> x Fold1, Repeat1: preprocessor 1/1, model 1/5: Error in `stop_vctrs()`: Can't combine `..1...
#> New names:
#> * . -> ....1
#> * . -> ....2
#> * . -> ....3
#> * . -> ....4
#> * . -> ....5
#> * ...
#> x Fold1, Repeat1: preprocessor 1/1, model 3/5: Error in xgb.model.dt.tree(model = m): Non-...
#> x Fold1, Repeat1: preprocessor 1/1, model 4/5: Error in xgb.model.dt.tree(model = m): Non-...
#> x Fold1, Repeat1: preprocessor 1/1, model 5/5: Error in xgb.model.dt.tree(model = m): Non-...
#> x Fold2, Repeat1: preprocessor 1/1, model 1/5: Error in `stop_vctrs()`: Can't combine `..1...
#> ! The Gaussian process model is being fit using 7 features but only has 1
#>   data points to do so. This may cause errors or a poor model fit.
#> ! Gaussian process model: 数据长度超过了矩阵的大小
#> x Gaussian process model: Error in GP_deviance(beta = row, X = X, Y = Y, n...
#> x Optimization stopped prematurely; returning current results.
#> v 4 of 4 tuning:     raw_rule_model (7m 55s)

grid_ens <- stacks() %>%
  add_candidates(tune_bayes_models_res) 
#> Error: The second argument to add_candidates() should inherit from one of
#> * `tune_results` or `workflow_set`, but its class is try-error.

Created on 2021-12-31 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                         
#>  version  R version 4.1.2 (2021-11-01)  
#>  os       Windows 7 x64                 
#>  system   x86_64, mingw32               
#>  ui       RTerm                         
#>  language (EN)                          
#>  collate  Chinese (Simplified)_China.936
#>  ctype    Chinese (Simplified)_China.936
#>  tz       Asia/Taipei                   
#>  date     2021-12-31                    
#> 
#> - Packages -------------------------------------------------------------------
#>  package         * version     date       lib
#>  assertthat        0.2.1       2019-03-21 [2]
#>  backports         1.4.0       2021-11-23 [1]
#>  baguette        * 0.1.1       2021-07-14 [1]
#>  base64enc         0.1-3       2015-07-28 [2]
#>  BBmisc            1.11        2017-03-10 [2]
#>  bdsmatrix         1.3-4       2020-01-13 [2]
#>  broom           * 0.7.10      2021-10-31 [1]
#>  butcher           0.1.4       2021-03-19 [2]
#>  C50               0.1.5       2021-06-01 [2]
#>  cellranger        1.1.0       2016-07-27 [2]
#>  checkmate         2.0.0       2020-02-06 [2]
#>  class             7.3-19      2021-05-03 [2]
#>  cli               3.1.0       2021-10-27 [1]
#>  codetools         0.2-18      2020-11-04 [2]
#>  colorspace        2.0-2       2021-06-24 [1]
#>  corpcor           1.6.9       2017-04-01 [2]
#>  crayon            1.4.2       2021-10-29 [1]
#>  Cubist            0.3.0       2021-05-28 [2]
#>  data.table        1.14.3      2021-12-04 [1]
#>  DBI               1.1.1       2021-01-15 [2]
#>  dbplyr            2.1.1       2021-04-06 [2]
#>  dials           * 0.0.10      2021-09-10 [2]
#>  DiceDesign        1.9         2021-02-13 [2]
#>  digest            0.6.29      2021-12-01 [1]
#>  discrim         * 0.1.3       2021-07-21 [1]
#>  doParallel      * 1.0.16      2020-10-16 [2]
#>  dplyr           * 1.0.7       2021-06-18 [2]
#>  earth           * 5.3.0       2020-10-11 [2]
#>  ellipse           0.4.2       2020-05-27 [2]
#>  ellipsis          0.3.2       2021-04-29 [2]
#>  evaluate          0.14        2019-05-28 [2]
#>  fansi             0.5.0       2021-05-25 [2]
#>  fastmap           1.1.0       2021-01-25 [2]
#>  fastmatch         1.1-0       2017-01-28 [2]
#>  finetune        * 0.1.0.9000  2021-12-07 [1]
#>  FNN               1.1.3       2019-02-15 [2]
#>  forcats         * 0.5.1       2021-01-27 [2]
#>  foreach         * 1.5.1       2020-10-15 [2]
#>  Formula         * 1.2-4       2020-10-16 [2]
#>  fs                1.5.1       2021-11-30 [1]
#>  furrr             0.2.3       2021-06-25 [2]
#>  future            1.23.0      2021-10-31 [1]
#>  future.apply      1.8.1       2021-08-10 [2]
#>  fuzzyjoin         0.1.6       2020-05-15 [1]
#>  generics          0.1.1       2021-10-25 [2]
#>  ggplot2         * 3.3.5       2021-06-25 [2]
#>  ggrepel           0.9.1       2021-01-15 [2]
#>  glmnet            4.1-2       2021-06-24 [2]
#>  globals           0.14.0      2020-11-22 [2]
#>  glue              1.5.1       2021-11-30 [1]
#>  gower             0.2.2       2020-06-23 [2]
#>  GPfit             1.0-8       2019-02-08 [2]
#>  gridExtra         2.3         2017-09-09 [2]
#>  gtable            0.3.0       2019-03-25 [2]
#>  hardhat           0.1.6       2021-07-14 [2]
#>  haven             2.4.3.9000  2021-10-29 [2]
#>  highr             0.9         2021-04-16 [2]
#>  hms               1.1.1       2021-09-26 [2]
#>  htmltools         0.5.2.9000  2021-12-04 [1]
#>  httr              1.4.2       2020-07-20 [2]
#>  igraph            1.2.6       2020-10-06 [2]
#>  infer           * 1.0.0       2021-08-13 [2]
#>  inum              1.0-4       2021-04-12 [2]
#>  ipred             0.9-12      2021-09-15 [2]
#>  iterators       * 1.0.13      2020-10-15 [2]
#>  jsonlite          1.7.2       2020-12-09 [2]
#>  keras           * 2.7.0.9000  2021-11-26 [2]
#>  knitr             1.36        2021-09-29 [2]
#>  lattice           0.20-44     2021-05-02 [2]
#>  lava              1.6.10      2021-09-02 [2]
#>  lhs               1.1.3       2021-09-08 [2]
#>  libcoin           1.0-8       2021-02-08 [2]
#>  lifecycle         1.0.1       2021-09-24 [2]
#>  lightgbm        * 3.3.1       2021-10-30 [1]
#>  listenv           0.8.0       2019-12-05 [2]
#>  lubridate         1.8.0       2021-10-07 [2]
#>  magrittr          2.0.1       2020-11-17 [2]
#>  MASS              7.3-54      2021-05-03 [2]
#>  mathjaxr          1.4-0       2021-03-01 [2]
#>  Matrix            1.3-4       2021-06-01 [2]
#>  matrixStats       0.59.0      2021-06-01 [2]
#>  mixOmics          6.14.0      2020-10-27 [2]
#>  mlr               2.19.0      2021-02-22 [2]
#>  modeldata       * 0.1.1       2021-07-14 [2]
#>  modelr            0.1.8       2020-05-19 [2]
#>  munsell           0.5.0       2018-06-12 [2]
#>  mvtnorm           1.1-2       2021-06-07 [2]
#>  naivebayes      * 0.9.7       2021-11-21 [2]
#>  nnet              7.3-16      2021-05-03 [2]
#>  pacman          * 0.5.3       2021-12-17 [1]
#>  parallelly        1.29.0      2021-11-21 [1]
#>  parallelMap       1.5.0       2020-03-26 [2]
#>  ParamHelpers      1.14        2020-03-24 [2]
#>  parsnip         * 0.1.7       2021-07-21 [1]
#>  partykit          1.2-13      2021-03-03 [2]
#>  pillar            1.6.4       2021-10-18 [2]
#>  pkgconfig         2.0.3       2019-09-22 [2]
#>  plotmo          * 3.6.0       2020-09-13 [2]
#>  plotrix         * 3.8-1       2021-01-21 [2]
#>  plsmod          * 0.1.1       2020-10-28 [1]
#>  plyr              1.8.6       2020-03-03 [2]
#>  png               0.1-7       2013-12-03 [2]
#>  poissonreg      * 0.1.1       2021-08-07 [1]
#>  prettyunits       1.1.1       2020-01-24 [2]
#>  pROC              1.18.0      2021-09-03 [2]
#>  prodlim           2019.11.13  2019-11-17 [2]
#>  prospectr       * 0.2.1       2020-10-23 [2]
#>  purrr           * 0.3.4       2020-04-17 [2]
#>  R6              * 2.5.1       2021-08-19 [2]
#>  RANN              2.6.1       2019-01-08 [2]
#>  rARPACK           0.11-0      2016-03-10 [2]
#>  RColorBrewer      1.1-2       2014-12-07 [2]
#>  Rcpp              1.0.7       2021-07-07 [2]
#>  readr           * 2.0.2       2021-09-27 [2]
#>  readxl            1.3.1       2019-03-13 [2]
#>  recipes         * 0.1.17      2021-09-27 [2]
#>  recipeselectors * 0.0.1       2021-02-03 [2]
#>  reprex            2.0.1       2021-08-05 [2]
#>  reshape2          1.4.4       2020-04-09 [2]
#>  reticulate        1.22-9000   2021-12-04 [1]
#>  rlang           * 0.99.0.9001 2021-12-07 [1]
#>  rmarkdown         2.11        2021-09-14 [2]
#>  ROSE              0.0-4       2021-06-14 [2]
#>  rpart           * 4.1-15      2019-04-12 [2]
#>  rsample         * 0.1.1       2021-11-08 [1]
#>  RSpectra          0.16-0      2019-12-01 [2]
#>  rstudioapi        0.13        2020-11-12 [2]
#>  rules           * 0.1.2       2021-08-07 [1]
#>  rvest             1.0.2       2021-10-16 [2]
#>  scales          * 1.1.1       2020-05-11 [1]
#>  sessioninfo       1.1.1       2018-11-05 [2]
#>  shape             1.4.6       2021-05-19 [2]
#>  sparsediscrim   * 0.3.0       2021-07-01 [1]
#>  stacks          * 0.2.1.9000  2021-12-07 [1]
#>  stringi           1.7.6       2021-11-29 [1]
#>  stringr         * 1.4.0       2019-02-10 [2]
#>  styler            1.4.1       2021-03-30 [2]
#>  survival          3.2-11      2021-04-26 [2]
#>  TeachingDemos   * 2.12        2020-04-07 [2]
#>  tensorflow        2.7.0.9000  2021-11-30 [2]
#>  tfruns            1.5.0       2021-02-26 [2]
#>  themis          * 0.1.4.9000  2021-06-24 [2]
#>  tibble          * 3.1.6       2021-11-07 [1]
#>  tidymodels      * 0.1.4       2021-10-01 [1]
#>  tidyr           * 1.1.4       2021-09-27 [2]
#>  tidyselect        1.1.1       2021-04-30 [2]
#>  tidyverse       * 1.3.1.9000  2021-10-29 [2]
#>  timeDate          3043.102    2018-02-21 [2]
#>  treesnip        * 0.1.0.9000  2021-12-30 [1]
#>  tune            * 0.1.6       2021-07-21 [2]
#>  tzdb              0.2.0       2021-10-27 [2]
#>  unbalanced        2.0         2015-06-26 [2]
#>  usethis           2.1.3.9000  2021-12-01 [2]
#>  utf8              1.2.2       2021-07-24 [2]
#>  vctrs           * 0.3.8       2021-04-29 [2]
#>  whisker           0.4         2019-08-28 [2]
#>  withr             2.4.3       2021-11-30 [1]
#>  workflows       * 0.2.4       2021-10-12 [2]
#>  workflowsets    * 0.1.0.9000  2021-10-29 [2]
#>  xfun              0.27        2021-10-18 [2]
#>  xgboost           1.4.1.1     2021-04-22 [2]
#>  xml2              1.3.2       2020-04-23 [2]
#>  xrf             * 0.2.0       2020-05-03 [1]
#>  yaml              2.2.1       2020-02-01 [2]
#>  yardstick       * 0.0.9.9000  2021-12-07 [1]
#>  zeallot           0.1.0       2018-01-28 [2]
#>  source                                       

Can you try the computations for one of the workflows that failed (without using the workflow set)?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.