I'm running into an issue using option_add
to update parameter ranges for a model spec in my workflowset. I want to update the range of the mtry
parameter, which only applies to 1 of my model specifications, xgb_spec
. Using this as a reference (r - Tune recipe in workflow set with custom range (or value) - Stack Overflow) I set the range then update it using option_add
, specifying the relevant model spec in the id
argument.
But when I run workflow_map
, i get an error: All options should be named
. In the option_add
documentation, there is a ...
argument for "... a list of named options." It kinda seems that relates to the error i'm getting, but i am not sure what to add here, or if i even need to add anything at all.
I'm not sure if i'm getting that error because i'm only trying to update 1 model spec instead of all 3 (maybe that means the options
for the other 2 are not named? Or if it has to do with not naming the option I am updating? or maybe a combination of both?
Reprex below:
library(tidymodels)
#> Warning: package 'tidymodels' was built under R version 4.1.1
#> Registered S3 method overwritten by 'tune':
#> method from
#> required_pkgs.model_spec parsnip
#> Warning: package 'dials' was built under R version 4.1.1
#> Warning: package 'ggplot2' was built under R version 4.1.1
#> Warning: package 'infer' was built under R version 4.1.1
#> Warning: package 'parsnip' was built under R version 4.1.1
#> Warning: package 'tune' was built under R version 4.1.1
#> Warning: package 'workflows' was built under R version 4.1.1
#> Warning: package 'workflowsets' was built under R version 4.1.1
#> Warning: package 'yardstick' was built under R version 4.1.1
library(discrim)
#> Warning: package 'discrim' was built under R version 4.1.1
#>
#> Attaching package: 'discrim'
#> The following object is masked from 'package:dials':
#>
#> smoothness
library(workflowsets)
library(finetune)
#> Warning: package 'finetune' was built under R version 4.1.1
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)
mars_disc_spec <-
discrim_flexible(prod_degree = tune()) %>%
set_engine("earth")
reg_disc_sepc <-
discrim_regularized(frac_common_cov = tune(),
frac_identity = tune()) %>%
set_engine("klaR")
cart_spec <-
decision_tree(cost_complexity = tune(),
min_n = tune()) %>%
set_engine("rpart") %>%
set_mode("classification")
xgb_spec <-
boost_tree(
trees = 700,
tree_depth = tune(),
min_n = tune(),
loss_reduction = tune(),
sample_size = tune(),
mtry = tune(),
learn_rate = tune()
) %>%
set_engine("xgboost") %>%
set_mode("classification")
mtry_param <-
parameters(mtry()) %>%
update(mtry = mtry(c(0, 20)))
all_workflows <-
workflow_set(
preproc = list("formula" = class ~ .),
models = list(regularized = reg_disc_sepc, xgb = xgb_spec, cart = cart_spec)
) %>%
option_add(mtry_param, id = "formula_xgb")
class_metrics <-
metric_set(roc_auc, accuracy, sens, spec, mn_log_loss)
race_ctrl <-
control_race(
verbose = TRUE,
allow_par = TRUE,
save_pred = TRUE,
parallel_over = "everything",
save_workflow = TRUE
)
doParallel::registerDoParallel()
wf_res <-
all_workflows %>%
workflow_map(fn = "tune_race_anova",
resamples = train_resamples,
grid = 10,
metrics = class_metrics,
control = race_ctrl
)
#> Error: Problem with `mutate()` column `option`.
#> i `option = purrr::map(option, append_options, dots)`.
#> x All options should be named.
#> Execution stopped; returning current results
Created on 2021-10-22 by the reprex package (v2.0.1)