tidymodels / censored

Parsnip wrappers for survival models
https://censored.tidymodels.org/
Other
123 stars 12 forks source link

Don't carry glmnet training data twice #265

Closed hfrick closed 12 months ago

hfrick commented 1 year ago

For glmnet, we need to keep the training data for prediction time and thus funnel it out of coxnet_train() by stashing it into $fit and then store it in model_fit$training_data - but we don't clean up the $fit slot afterward, so it's in there twice 😬

This is fit() but it also applies to fit_xy() https://github.com/tidymodels/censored/blob/f9eccb68a51159d55390ac592605600e5d659ef3/R/proportional_hazards.R#L16-L22

library(censored)
#> Loading required package: parsnip
#> Loading required package: survival
lung2 <- lung[-14, ]

glmn_fit <- proportional_hazards(penalty = 0.1) %>%
  set_engine("glmnet") %>%
  fit(Surv(time, status) ~ age + ph.ecog, data = lung2)

lobstr::obj_size(lung2)
#> 34.61 kB
lobstr::obj_size(glmn_fit)
#> 112.16 kB
lobstr::obj_size(glmn_fit$fit)
#> 64.10 kB
lobstr::obj_size(glmn_fit$fit$fit)
#> 9.54 kB

Created on 2023-04-26 with reprex v2.0.2

github-actions[bot] commented 11 months ago

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.