Closed topepo closed 9 months ago
Same for select_best()
, select_by_one_std_err()
and select_by_pct_loss()
.
Also applies when a static metric is used.
Surfaced in https://github.com/tidymodels/tune/pull/703 - those tests may need updating when closing this issue.
Also to look into: autoplot()
and int_pctl()
.
The tuning functions and fit_resamples()
currently error when supplying eval_time
for a static survival metric and for non-censored-regression models in general. Should they also warn instead?
Here's a reprex with tune_grid()
as one of the tuning functions but this should then also apply to tune_bayes()
and the finetune functions.
library(tidymodels)
library(censored)
#> Loading required package: survival
# mode is not censored regression -----------------------------------------
set.seed(2193)
tune_res <-
linear_reg(penalty = tune(), engine = "glmnet") %>%
tune_grid(
mpg ~ .,
resamples = vfold_cv(mtcars, 2),
grid = grid,
metrics = metric_set(rmse),
eval_time = 10
)
#> Error:
#> ! Evaluation times are only used for dynamic and integrated survival metrics.
#> Backtrace:
#> ▆
#> 1. ├─linear_reg(penalty = tune(), engine = "glmnet") %>% ...
#> 2. ├─tune::tune_grid(...)
#> 3. └─tune:::tune_grid.model_spec(...)
#> 4. ├─tune::tune_grid(...)
#> 5. └─tune:::tune_grid.workflow(...)
#> 6. └─tune:::tune_grid_workflow(...)
#> 7. └─tune:::check_eval_time(eval_time, metrics)
#> 8. └─rlang::abort(...)
set.seed(2193)
tune_res <-
linear_reg(penalty = 0.1, engine = "glmnet") %>%
fit_resamples(
mpg ~ .,
resamples = vfold_cv(mtcars, 2),
metrics = metric_set(rmse),
eval_time = 10
)
#> Error:
#> ! Evaluation times are only used for dynamic and integrated survival metrics.
#> Backtrace:
#> ▆
#> 1. ├─linear_reg(penalty = 0.1, engine = "glmnet") %>% ...
#> 2. ├─tune::fit_resamples(...)
#> 3. └─tune:::fit_resamples.model_spec(...)
#> 4. ├─tune::fit_resamples(...)
#> 5. └─tune:::fit_resamples.workflow(...)
#> 6. └─tune:::resample_workflow(...)
#> 7. └─tune:::tune_grid_workflow(...)
#> 8. └─tune:::check_eval_time(eval_time, metrics)
#> 9. └─rlang::abort(...)
# static metric -----------------------------------------------------------
lung_surv <- lung %>%
dplyr::mutate(surv = Surv(time, status), .keep = "unused")
set.seed(2193)
tune_res <-
proportional_hazards(penalty = tune(), engine = "glmnet") %>%
tune_grid(
surv ~ .,
resamples = vfold_cv(lung_surv, 2),
grid = grid,
metrics = metric_set(concordance_survival),
eval_time = 10
)
#> Error:
#> ! Evaluation times are only used for dynamic and integrated survival metrics.
#> Backtrace:
#> ▆
#> 1. ├─... %>% ...
#> 2. ├─tune::tune_grid(...)
#> 3. └─tune:::tune_grid.model_spec(...)
#> 4. ├─tune::tune_grid(...)
#> 5. └─tune:::tune_grid.workflow(...)
#> 6. └─tune:::tune_grid_workflow(...)
#> 7. └─tune:::check_eval_time(eval_time, metrics)
#> 8. └─rlang::abort(...)
set.seed(2193)
tune_res <-
proportional_hazards(penalty = 0.1, engine = "glmnet") %>%
fit_resamples(
surv ~ .,
resamples = vfold_cv(lung_surv, 2),
metrics = metric_set(concordance_survival),
eval_time = 10
)
#> Error:
#> ! Evaluation times are only used for dynamic and integrated survival metrics.
#> Backtrace:
#> ▆
#> 1. ├─... %>% ...
#> 2. ├─tune::fit_resamples(...)
#> 3. └─tune:::fit_resamples.model_spec(...)
#> 4. ├─tune::fit_resamples(...)
#> 5. └─tune:::fit_resamples.workflow(...)
#> 6. └─tune:::resample_workflow(...)
#> 7. └─tune:::tune_grid_workflow(...)
#> 8. └─tune:::check_eval_time(eval_time, metrics)
#> 9. └─rlang::abort(...)
Created on 2023-11-22 with reprex v2.0.2
I think that it should be a warning. It is unneeded but won't cause bad results.
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.
These functions should warn (but not error) when
eval_time
is notNULL
in the following cases:For non-survival models and for survival models with a static metric
fit_resamples()
tune_grid()
tune_bayes()
tune_race_anova()
works but https://github.com/tidymodels/finetune/issues/91tune_race_win_loss()
https://github.com/tidymodels/finetune/issues/92tune_sim_anneal()
For non-survival models and for survival models without a dynamic metric
show_best()
andselect_best()
work but message text is not as closely aligned as it could be https://github.com/tidymodels/tune/issues/811select_by_one_std_err()
andselect_by_pct_loss()
usechoose_eval_time()
, thus same comment asselect_best()
autoplot()
#706int_pctl()
fit_best()
And bringing it all together: https://github.com/tidymodels/tune/issues/811
And the exception, for consistency within the function (with how the choice of metric is treated)
augment()
should not take an eval_time argshow_best()
should throw a warning ifeval_time
is used but the metric selected is not dynamic. See last line:Created on 2023-07-20 with reprex v2.0.2