Description
I am trying to use tune_bayes()
to optimize two parameters in a decision tree but the function always crashes giving me a an error
#> i Gaussian process model
#> ! The Gaussian process model is being fit using 2 features but only has 0
#> data points to do so. This may cause errors or a poor model fit.
#> ! Gaussian process model: no non-missing arguments to min; returning Inf, ...
#> x Gaussian process model: Error in seq_len(n - 1L): argument must be coerc...
#> ! An error occurred when creating candidates parameters: Error in seq_len(n - 1L) :
#> argument must be coercible to non-negative integer
#> Error: `best` should be a single, non-missing numeric
With tune_grid()
the recipes and all work just fine but for some reason tune_bayes()
does not want to run. I tried to update the tuneable parameters to some other range using update(...)
but this did not help either. I do not understand why there seems to be no available data.
Reprex
library(tidyverse)
library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#> method from
#> required_pkgs.model_spec parsnip
titanic <- read_csv("train.csv")
#>
#> -- Column specification --------------------------------------------------------
#> cols(
#> PassengerId = col_double(),
#> Survived = col_double(),
#> Pclass = col_double(),
#> Name = col_character(),
#> Sex = col_character(),
#> Age = col_double(),
#> SibSp = col_double(),
#> Parch = col_double(),
#> Ticket = col_character(),
#> Fare = col_double(),
#> Cabin = col_character(),
#> Embarked = col_character()
#> )
titanic <- titanic %>%
mutate(
Survived = factor(
Survived,
levels = c(0, 1),
labels = c("Deceased", "Survived")
)
)
set.seed(123)
titanic_split <- initial_split(titanic, strata = Survived)
titanic_train <- training(titanic_split)
titanic_test <- testing(titanic_split)
set.seed(456)
titanic_folds <- vfold_cv(titanic_train, strata = Survived)
titanic_rec <- recipe(formula = Survived ~ ., data = titanic_train) %>%
update_role(PassengerId, new_role = "Id") %>%
step_mutate(Cabin = if_else(is.na(Cabin), "Missing", "Available")) %>%
step_impute_median(Age) %>%
step_mutate(
title = str_match(Name, ", ([:alpha:]+)\\."),
title = if_else(is.na(title[, 2]), "NA", title[, 2])
) %>%
step_other(title, threshold = 0.02, other = "Other") %>%
step_rm(Ticket, Embarked) %>%
update_role(Name, new_role = "Id") %>%
step_string2factor(all_nominal_predictors())
titanic_spec <-
decision_tree(mode = "classification", tree_depth = tune(), min_n = tune()) %>%
set_mode("classification") %>%
set_engine("rpart")
titanic_wf <- workflow() %>%
add_recipe(titanic_rec) %>%
add_model(titanic_spec)
params <- parameters(titanic_wf) %>%
finalize()
options(tidymodels.dark = TRUE)
#doParallel::registerDoParallel(cores = 6)
set.seed(14834)
titanic_tune <- tune_bayes(
object = titanic_wf,
resamples = titanic_folds,
param_info = params,
iter = 30,
initial = 5,
metrics = metric_set(sensitivity, specificity, mcc, roc_auc),
control = control_bayes(
verbose = TRUE,
no_improve = 5,
save_pred = TRUE,
pkgs = "tidyverse"
)
)
#>
#> > Generating a set of 5 initial parameter results
#> v Initialization complete
#>
#> Optimizing sensitivity using the expected improvement
#>
#> -- Iteration 1 -----------------------------------------------------------------
#>
#> i Current best: sensitivity=NA (@iter NA)
#> i Gaussian process model
#> ! The Gaussian process model is being fit using 2 features but only has 0
#> data points to do so. This may cause errors or a poor model fit.
#> ! Gaussian process model: no non-missing arguments to min; returning Inf, ...
#> x Gaussian process model: Error in seq_len(n - 1L): argument must be coerc...
#> ! An error occurred when creating candidates parameters: Error in seq_len(n - 1L) :
#> argument must be coercible to non-negative integer
#> Error: `best` should be a single, non-missing numeric
#> x Optimization stopped prematurely; returning current results.
Created on 2021-07-05 by the reprex package (v2.0.0)
Session infosessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 4.0.5 (2021-03-31)
#> os Windows 10 x64
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate German_Germany.1252
#> ctype German_Germany.1252
#> tz Europe/Berlin
#> date 2021-07-05
#>
#> - Packages -------------------------------------------------------------------
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.3)
#> backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.3)
#> broom * 0.7.6 2021-04-05 [1] CRAN (R 4.0.5)
#> cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.0.3)
#> class 7.3-18 2021-01-24 [2] CRAN (R 4.0.5)
#> cli 2.5.0 2021-04-26 [1] CRAN (R 4.0.3)
#> codetools 0.2-18 2020-11-04 [2] CRAN (R 4.0.5)
#> colorspace 2.0-1 2021-05-04 [1] CRAN (R 4.0.5)
#> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.4)
#> DBI 1.1.0 2019-12-15 [1] CRAN (R 4.0.3)
#> dbplyr 2.1.1 2021-04-06 [1] CRAN (R 4.0.5)
#> dials * 0.0.9 2020-09-16 [1] CRAN (R 4.0.4)
#> DiceDesign 1.9 2021-02-13 [1] CRAN (R 4.0.4)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3)
#> dplyr * 1.0.6 2021-05-05 [1] CRAN (R 4.0.5)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.0.3)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.3)
#> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.0.5)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.0.5)
#> forcats * 0.5.1 2021-01-27 [1] CRAN (R 4.0.5)
#> foreach 1.5.1 2020-10-15 [1] CRAN (R 4.0.3)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.3)
#> furrr 0.2.2 2021-01-29 [1] CRAN (R 4.0.5)
#> future 1.21.0 2020-12-10 [1] CRAN (R 4.0.3)
#> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.3)
#> ggplot2 * 3.3.3 2020-12-30 [1] CRAN (R 4.0.4)
#> globals 0.14.0 2020-11-22 [1] CRAN (R 4.0.3)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.3)
#> gower 0.2.2 2020-06-23 [1] CRAN (R 4.0.3)
#> GPfit 1.0-8 2019-02-08 [1] CRAN (R 4.0.4)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.3)
#> hardhat 0.1.5 2020-11-09 [1] CRAN (R 4.0.4)
#> haven 2.3.1 2020-06-01 [1] CRAN (R 4.0.3)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.0.5)
#> hms 1.0.0 2021-01-13 [1] CRAN (R 4.0.5)
#> htmltools 0.5.1.9005 2021-07-01 [1] Github (rstudio/htmltools@7fbab16)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.0.5)
#> infer * 0.5.4.9000 2021-03-27 [1] Github (tidymodels/infer@66d24a0)
#> ipred 0.9-11 2021-03-12 [1] CRAN (R 4.0.4)
#> iterators 1.0.13 2020-10-15 [1] CRAN (R 4.0.3)
#> jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.0.3)
#> knitr 1.33 2021-04-24 [1] CRAN (R 4.0.5)
#> lattice 0.20-41 2020-04-02 [2] CRAN (R 4.0.5)
#> lava 1.6.9 2021-03-11 [1] CRAN (R 4.0.4)
#> lhs 1.1.1 2020-10-05 [1] CRAN (R 4.0.4)
#> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.4)
#> listenv 0.8.0 2019-12-05 [1] CRAN (R 4.0.3)
#> lubridate 1.7.10 2021-02-26 [1] CRAN (R 4.0.4)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.3)
#> MASS 7.3-53.1 2021-02-12 [2] CRAN (R 4.0.5)
#> Matrix 1.3-2 2021-01-06 [2] CRAN (R 4.0.5)
#> modeldata * 0.1.0 2020-10-22 [1] CRAN (R 4.0.4)
#> modelr 0.1.8 2020-05-19 [1] CRAN (R 4.0.3)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.3)
#> nnet 7.3-15 2021-01-24 [2] CRAN (R 4.0.5)
#> parallelly 1.25.0 2021-04-30 [1] CRAN (R 4.0.5)
#> parsnip * 0.1.5.9003 2021-05-22 [1] Github (tidymodels/parsnip@46a2018)
#> pillar 1.6.1 2021-05-16 [1] CRAN (R 4.0.5)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.3)
#> plyr 1.8.6 2020-03-03 [1] CRAN (R 4.0.3)
#> pROC 1.17.0.1 2021-01-13 [1] CRAN (R 4.0.4)
#> prodlim 2019.11.13 2019-11-17 [1] CRAN (R 4.0.4)
#> ps 1.6.0 2021-02-28 [1] CRAN (R 4.0.5)
#> purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.0.3)
#> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.3)
#> Rcpp 1.0.6 2021-01-15 [1] CRAN (R 4.0.4)
#> readr * 1.4.0 2020-10-05 [1] CRAN (R 4.0.5)
#> readxl 1.3.1 2019-03-13 [1] CRAN (R 4.0.3)
#> recipes * 0.1.16.9000 2021-05-29 [1] Github (tidymodels/recipes@0806713)
#> reprex 2.0.0 2021-04-02 [1] CRAN (R 4.0.5)
#> rlang * 0.4.11.9000 2021-07-01 [1] Github (r-lib/rlang@dc03e44)
#> rmarkdown 2.9.1 2021-07-01 [1] Github (rstudio/rmarkdown@1ea3575)
#> rpart * 4.1-15 2019-04-12 [1] CRAN (R 4.0.5)
#> rsample * 0.1.0 2021-05-08 [1] CRAN (R 4.0.5)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.0.3)
#> rvest 1.0.0 2021-03-09 [1] CRAN (R 4.0.5)
#> scales * 1.1.1 2020-05-11 [1] CRAN (R 4.0.3)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.3)
#> stringi 1.6.2 2021-05-17 [1] CRAN (R 4.0.5)
#> stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.0.3)
#> survival 3.2-10 2021-03-16 [2] CRAN (R 4.0.5)
#> tibble * 3.1.2 2021-05-16 [1] CRAN (R 4.0.5)
#> tidymodels * 0.1.3 2021-04-19 [1] CRAN (R 4.0.5)
#> tidyr * 1.1.3 2021-03-03 [1] CRAN (R 4.0.5)
#> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.0.3)
#> tidyverse * 1.3.1 2021-04-15 [1] CRAN (R 4.0.5)
#> timeDate 3043.102 2018-02-21 [1] CRAN (R 4.0.3)
#> tune * 0.1.5.9000 2021-05-22 [1] Github (tidymodels/tune@b0e83a7)
#> utf8 1.2.1 2021-03-12 [1] CRAN (R 4.0.3)
#> vctrs * 0.3.8 2021-04-29 [1] CRAN (R 4.0.3)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.0.5)
#> workflows * 0.2.2 2021-03-10 [1] CRAN (R 4.0.4)
#> workflowsets * 0.0.2 2021-04-16 [1] CRAN (R 4.0.5)
#> xfun 0.24 2021-06-15 [1] CRAN (R 4.0.5)
#> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.5)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.3)
#> yardstick * 0.0.8 2021-03-28 [1] CRAN (R 4.0.5)
#>
#> [1] C:/Users/Albert/Documents/R/win-library/4.0
#> [2] C:/Program Files/R/R-4.0.5/library