Skip to content
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

support "censored regression" #152

Closed
simonpcouch opened this issue Sep 23, 2022 · 3 comments · Fixed by #207
Closed

support "censored regression" #152

simonpcouch opened this issue Sep 23, 2022 · 3 comments · Fixed by #207
Labels
feature a feature request or enhancement

Comments

@simonpcouch
Copy link
Collaborator

Will need to come after workflows/workflowsets support, but--

A good bit of conditional statements based on the mode will need to be adjusted, to start off!🏄

stacks/R/add_candidates.R

Lines 185 to 186 in 227efb6

# note whether classification or regression
.set_mode_ <- function(stack, candidates, name) {

if (attr(data_stack, "mode") == "regression") {

if (mode == "regression") {

@simonpcouch simonpcouch added the feature a feature request or enhancement label Oct 31, 2023
@TSI-PTG
Copy link

TSI-PTG commented Dec 28, 2023

Has there been any progress on this? I'm not successful with my attempts but maybe I'm doing something wrong.

library(tidymodels)
library(censored)
#> Loading required package: survival
library(stacks)
library(finetune)

tidymodels_prefer()

data(cancer)

lung <- lung %>%
    drop_na() %>%
    tibble() %>%
    mutate(surv = Surv(time, status))

lung_train <- lung %>% vfold_cv(strata = status, v = 5)

mod_glmnet <- proportional_hazards(penalty = tune(), mixture = tune()) %>%
    set_engine("glmnet") %>%
    set_mode("censored regression")


recipe_lung <- recipe(surv ~ ., data = lung) %>%
    update_role(c(inst, time, status), new_role = "ID")

workflow_lung <- workflow() %>%
    add_recipe(recipe_lung) %>%
    add_model(mod_glmnet)

tune_glmnet <- workflow_lung %>%
    tune_race_win_loss(
        lung_train,
        grid = 3,
        eval_time = 365,
        control = control_race(
            save_pred = TRUE,
            save_workflow = TRUE,
            allow_par = FALSE
        )
    )

stack_lung <- stacks() %>%
    add_candidates(tune_glmnet)
#> Error in `res[order(res$.row, res$.config), nms]`:
#> ! Can't subset columns that don't exist.
#> ✖ Columns `penalty` and `mixture` don't exist.
#> Backtrace:
#>      ▆
#>   1. ├─stacks() %>% add_candidates(tune_glmnet)
#>   2. ├─stacks::add_candidates(., tune_glmnet)
#>   3. ├─stacks:::add_candidates.tune_results(., tune_glmnet)
#>   4. │ └─... %>% .set_data_candidates(candidates, name, col_name)
#>   5. ├─stacks:::.set_data_candidates(., candidates, name, col_name)
#>   6. │ ├─... %>% dplyr::select(-.row)
#>   7. │ └─stacks:::collate_predictions(candidates)
#>   8. │   ├─tune::collect_predictions(x, summarize = TRUE) %>% ...
#>   9. │   ├─tune::collect_predictions(x, summarize = TRUE)
#>  10. │   ├─finetune:::collect_predictions.tune_race(x, summarize = TRUE)
#>  11. │   ├─base::NextMethod(summarize = summarize, parameters = parameters)
#>  12. │   └─tune:::collect_predictions.tune_results(...)
#>  13. │     └─tune:::average_predictions(x, parameters)
#>  14. │       └─tune:::surv_summarize(x, param_names, y_nms)
#>  15. │         ├─res[order(res$.row, res$.config), nms]
#>  16. │         └─tibble:::`[.tbl_df`(res, order(res$.row, res$.config), nms)
#>  17. │           └─tibble:::vectbl_as_col_location(...)
#>  18. │             ├─tibble:::subclass_col_index_errors(...)
#>  19. │             │ └─base::withCallingHandlers(...)
#>  20. │             └─vctrs::vec_as_location(j, n, names, missing = "error", call = call)
#>  21. ├─dplyr::select(., -.row)
#>  22. ├─tidyr::pivot_wider(...)
#>  23. ├─dplyr::mutate(., .config = process_.config(.config, df = ., name = col_name))
#>  24. ├─dplyr::select(...)
#>  25. ├─dplyr::mutate(., .config = if (".config" %in% names(.)) .config else NA_character_)
#>  26. ├─dplyr::ungroup(.)
#>  27. ├─dplyr::rename_with(., make.names, .cols = dplyr::starts_with(".pred"))
#>  28. └─vctrs (local) `<fn>`()
#>  29.   └─vctrs:::stop_subscript_oob(...)
#>  30.     └─vctrs:::stop_subscript(...)
#>  31.       └─rlang::abort(...)

Created on 2023-12-28 with reprex v2.0.2

@EmilHvitfeldt
Copy link
Member

As far as I know, there haven't been much progress yet. But we are still planning to make it happen!

@simonpcouch
Copy link
Collaborator Author

This will actually be a good bit more complicated than the kinds of changes in #157. The added functionality from accounting for evaluation times throughout stacks' internals is likely not worth the complexity, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants