-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
check tune::compute_metrics for survival models #170
Comments
Looking at the code, I thought that we would need to add an With no changes, the function does pretty much what it should (*) library(tidymodels)
library(censored)
#> Loading required package: survival
lung_surv <- lung %>%
dplyr::mutate(surv = Surv(time, status), .keep = "unused")
metrics <- metric_set(concordance_survival, brier_survival_integrated, brier_survival)
times <- c(2, 50, 100)
set.seed(2193)
tune_res <-
proportional_hazards(penalty = tune(), engine = "glmnet") %>%
tune_grid(
surv ~ .,
resamples = vfold_cv(lung_surv, 2),
grid = tibble(penalty = c(0.001, 0.1)),
control = control_grid(save_pred = TRUE),
metrics = metrics,
eval_time = times
)
recomp <- compute_metrics(tune_res, metrics, summarize = TRUE)
original <- collect_metrics(tune_res)
all.equal(recomp, original)
#> [1] TRUE
stc_only <- compute_metrics(tune_res, metric_set(concordance_survival), summarize = TRUE)
stc_original <- collect_metrics(tune_res) %>% filter(.metric == "concordance_survival")
all.equal(stc_only, stc_original) # orginal has a .eval_time which is all NA
#> [1] "Names: 4 string mismatches"
#> [2] "Length mismatch: comparison on first 7 components"
#> [3] "Component 4: 'is.NA' value mismatch: 2 in current 0 in target"
#> [4] "Component 5: Mean relative difference: 0.6953599"
#> [5] "Component 6: Mean relative difference: 58.79083"
#> [6] "Component 7: Modes: character, numeric"
#> [7] "Component 7: target is character, current is numeric"
all.equal(stc_only, stc_original %>% select(-.eval_time))
#> [1] TRUE Created on 2024-01-19 with reprex v2.0.2 The only caveat is that the lack of an I'll look into where this is tested for survival models, but I think that we should leave the API as-is and see if there are requests for a subset of eval times. Also, I don't think that there are parity metrics for censored regression, so that is a moot point for that application. |
We've settled on leaving We do need to make some unit tests for survival models so I'll keep this open until then. |
Not sure if/where it is currently tested for this.
The text was updated successfully, but these errors were encountered: