Closed jrosell closed 10 months ago
Thanks for the issue, @jrosell!
It seems like the all_configs
argument to the tune_race
collect_metrics()
method might be helpful for you!
library(tidymodels)
library(finetune)
library(discrim)
#>
#> Attaching package: 'discrim'
#> The following object is masked from 'package:dials':
#>
#> smoothness
data(two_class_dat, package = "modeldata")
set.seed(6376)
rs <- bootstraps(two_class_dat, times = 10)
# optimize an regularized discriminant analysis model
rda_spec <-
discrim_regularized(frac_common_cov = tune(), frac_identity = tune()) %>%
set_engine("klaR")
ctrl <- control_race(verbose_elim = TRUE)
set.seed(11)
grid_anova <-
rda_spec %>%
tune_race_anova(Class ~ ., resamples = rs, grid = 10, control = ctrl)
#> ℹ Racing will maximize the roc_auc metric.
#> ℹ Resamples are analyzed in a random order.
#> ℹ Bootstrap05: All but one parameter combination were eliminated.
plot_race(grid_anova)
A quick visual of the racing process:
This is reasonably well-reflected in collect_metrics()
output:
collect_metrics(grid_anova, all_configs = TRUE)
#> # A tibble: 20 × 8
#> frac_common_cov frac_identity .metric .estimator mean n std_err .config
#> <dbl> <dbl> <chr> <chr> <dbl> <int> <dbl> <chr>
#> 1 0.0691 0.0437 accuracy binary 0.811 10 0.00578 Prepro…
#> 2 0.0691 0.0437 roc_auc binary 0.886 10 0.00513 Prepro…
#> 3 0.199 0.595 accuracy binary 0.733 3 0.0139 Prepro…
#> 4 0.199 0.595 roc_auc binary 0.825 3 0.00535 Prepro…
#> 5 0.962 0.716 accuracy binary 0.719 3 0.0118 Prepro…
#> 6 0.962 0.716 roc_auc binary 0.814 3 0.00526 Prepro…
#> 7 0.271 0.910 accuracy binary 0.709 3 0.0130 Prepro…
#> 8 0.271 0.910 roc_auc binary 0.798 3 0.00501 Prepro…
#> 9 0.781 0.666 accuracy binary 0.726 3 0.0126 Prepro…
#> 10 0.781 0.666 roc_auc binary 0.818 3 0.00529 Prepro…
#> 11 0.481 0.453 accuracy binary 0.751 3 0.0117 Prepro…
#> 12 0.481 0.453 roc_auc binary 0.839 3 0.00524 Prepro…
#> 13 0.837 0.824 accuracy binary 0.711 3 0.0142 Prepro…
#> 14 0.837 0.824 roc_auc binary 0.805 3 0.00519 Prepro…
#> 15 0.605 0.385 accuracy binary 0.754 3 0.0117 Prepro…
#> 16 0.605 0.385 roc_auc binary 0.846 3 0.00522 Prepro…
#> 17 0.555 0.293 accuracy binary 0.774 3 0.0159 Prepro…
#> 18 0.555 0.293 roc_auc binary 0.856 3 0.00485 Prepro…
#> 19 0.392 0.154 accuracy binary 0.790 3 0.0133 Prepro…
#> 20 0.392 0.154 roc_auc binary 0.871 3 0.00459 Prepro…
Created on 2024-01-18 with reprex v2.1.0
Note the n
column, specifically. summarize = FALSE
would give the performance metrics for each configuration by resample, including those that weren't resampled fully if all_configs = TRUE
.
My fault. I was checking tune docs instead of finetune docs. https://finetune.tidymodels.org/reference/collect_predictions.html
Feature
In situations when one wants to analyze the intermediate results of a race, one shouldn't be required to know the internal data structure of the tune package and be able to use some function like collect_race or similar.
Here's an example of what we get with the current functions and what I expect to get.
Created on 2024-01-18 with reprex v2.1.0.9000