Extras - workflowsets

Practical Machine Learning with tidymodels

Startup

library(tidymodels)

set.seed(123)
cls_split <- initial_split(cls_data_2026, prop = 0.8)
cls_train <- training(cls_split)
cls_test <- testing(cls_split)

set.seed(123)
cls_folds <- vfold_cv(cls_train, v = 10)

# decrease cost_complexity from its default 0.01 to make a more
# complex and performant tree. see `?decision_tree()` to learn more.
tree_spec <- decision_tree(cost_complexity = 0.0001, mode = "classification")

rf_spec <- rand_forest(trees = 1000, mode = "classification")

How can we compare multiple model workflows at once?

Evaluate a workflow set

wf_set <- workflow_set(list(class ~ .), list(tree_spec, rf_spec))
wf_set
#> # A workflow set/tibble: 2 × 4
#>   wflow_id              info             option    result    
#>   <chr>                 <list>           <list>    <list>    
#> 1 formula_decision_tree <tibble [1 × 4]> <opts[0]> <list [0]>
#> 2 formula_rand_forest   <tibble [1 × 4]> <opts[0]> <list [0]>

Evaluate a workflow set

wf_set_fit <- wf_set |>
  workflow_map("fit_resamples", resamples = cls_folds)
wf_set_fit
#> # A workflow set/tibble: 2 × 4
#>   wflow_id              info             option    result   
#>   <chr>                 <list>           <list>    <list>   
#> 1 formula_decision_tree <tibble [1 × 4]> <opts[1]> <rsmp[+]>
#> 2 formula_rand_forest   <tibble [1 × 4]> <opts[1]> <rsmp[+]>

Evaluate a workflow set

wf_set_fit |>
  rank_results()
#> # A tibble: 6 × 9
#>   wflow_id         .config .metric   mean std_err     n preprocessor model  rank
#>   <chr>            <chr>   <chr>    <dbl>   <dbl> <int> <chr>        <chr> <int>
#> 1 formula_rand_fo… pre0_m… accura… 0.929  0.00619    10 formula      rand…     1
#> 2 formula_rand_fo… pre0_m… brier_… 0.0499 0.00440    10 formula      rand…     1
#> 3 formula_rand_fo… pre0_m… roc_auc 0.978  0.00441    10 formula      rand…     1
#> 4 formula_decisio… pre0_m… accura… 0.921  0.00747    10 formula      deci…     2
#> 5 formula_decisio… pre0_m… brier_… 0.0612 0.00539    10 formula      deci…     2
#> 6 formula_decisio… pre0_m… roc_auc 0.959  0.00635    10 formula      deci…     2

The first metric of the metric set is used for ranking. Use rank_metric to change that.

Lots more available with workflow sets, like collect_metrics(), autoplot() methods, and more!

Your turn

When do you think a workflow set would be useful?

Discuss with your neighbors!