I'm running into an issue using a custom grid with tune_sim_anneal()
. Im trying to follow the approach i saw in this workflowsets
issue using option_add
to specify the grid i want to use for a given workflow ID.
When i use this approach with tune_grid
it works, but when i use tune_sim_anneal
I get an error - see reprex below:
library(tidymodels)
#> Warning: package 'tidymodels' was built under R version 4.1.3
#> Warning: package 'broom' was built under R version 4.1.3
#> Warning: package 'dials' was built under R version 4.1.3
#> Warning: package 'scales' was built under R version 4.1.3
#> Warning: package 'dplyr' was built under R version 4.1.3
#> Warning: package 'ggplot2' was built under R version 4.1.3
#> Warning: package 'infer' was built under R version 4.1.3
#> Warning: package 'modeldata' was built under R version 4.1.3
#> Warning: package 'parsnip' was built under R version 4.1.3
#> Warning: package 'purrr' was built under R version 4.1.3
#> Warning: package 'recipes' was built under R version 4.1.3
#> Warning: package 'rsample' was built under R version 4.1.3
#> Warning: package 'tibble' was built under R version 4.1.3
#> Warning: package 'tidyr' was built under R version 4.1.3
#> Warning: package 'tune' was built under R version 4.1.3
#> Warning: package 'workflows' was built under R version 4.1.3
#> Warning: package 'workflowsets' was built under R version 4.1.3
#> Warning: package 'yardstick' was built under R version 4.1.3
data(parabolic)
set.seed(1)
split <- initial_split(parabolic)
train_set <- training(split)
test_set <- testing(split)
set.seed(2)
train_resamples <- bootstraps(train_set, times = 5)
logistic_reg_spec <-
logistic_reg(penalty = tune(),
mixture = tune()) %>%
set_engine("glmnet")
workflow <-
workflow_set(
preproc = list("formula" = class ~ .),
models = list(lm = logistic_reg_spec)
) %>%
option_add(id = "formula_lm", grid = grid_max_entropy(extract_parameter_set_dials(logistic_reg_spec), size = 10))
#confirm grid is there
workflow %>%
unnest(option) %>%
select(option) %>%
unnest(option)
#> # A tibble: 10 x 2
#> penalty mixture
#> <dbl> <dbl>
#> 1 4.84e- 5 0.0522
#> 2 1.17e-10 0.872
#> 3 8.92e- 7 0.941
#> 4 1.02e- 3 0.645
#> 5 2.97e- 1 0.496
#> 6 9.18e- 7 0.300
#> 7 2.21e-10 0.0617
#> 8 5.89e-10 0.441
#> 9 6.33e- 1 0.942
#> 10 6.71e- 1 0.118
grid_search_results <-
workflow %>%
workflowsets::workflow_map(
seed = 1503,
fn = "tune_grid",
resamples = train_resamples,
metrics = metric_set(roc_auc)
)
#> Warning: package 'glmnet' was built under R version 4.1.3
#grid search with custom grid looks ok
grid_search_results
#> # A workflow set/tibble: 1 x 4
#> wflow_id info option result
#> <chr> <list> <list> <list>
#> 1 formula_lm <tibble [1 x 4]> <opts[3]> <tune[+]>
sim_anneal_results <-
workflow %>%
workflowsets::workflow_map(
seed = 9999,
fn = "tune_sim_anneal",
resamples = train_resamples,
metrics = metric_set(roc_auc)
)
#> Warning: The `...` are not used in this function but one or more objects were
#> passed: 'grid'
# there's an error using tune_sim_anneal with a custom grid
sim_anneal_results %>%
unnest(result) %>%
select(result) %>%
unnest(result)
#> # A tibble: 1 x 1
#> result
#> <try-errr>
#> 1 Error in tune_sim_anneal_workflow(object, resamples = resamples, iter = iter,~