mlr-org / mlr3book

Online version of Bischl, B., Sonabend, R., Kotthoff, L., & Lang, M. (Eds.). (2024). "Applied Machine Learning Using mlr3 in R". CRC Press.
https://mlr3book.mlr-org.com/
MIT License
254 stars 59 forks source link

Is auto_tuner() applicable to survival analysis models #727

Closed beiwo07 closed 1 year ago

beiwo07 commented 1 year ago

Hi! I used auto_tuner() to perform nested resampling on my models trained based on time-to-event data, which gives me an error message as below.

Error in UseMethod("as_resampling") : no applicable method for 'as_resampling' applied to an object of class "c('LearnerSurvCVGlmnet', 'LearnerSurv', 'Learner', 'R6')".

My code looks like something like this:

task_w<- as_task_surv(df_w, time= "survival_months", event="vital_status_composite")

resampling_in<- rsmp("cv", folds=4) #for inner cv 

resampling_out<- rsmp("cv", folds=3) #for outter cv

measure<- msr("surv.cindex")

grid_search<- tnr("grid_search", resolution= 5, batch_size=10)

glmnet<- lrn("surv.cv_glmnet", 
             alpha= to_tune(0,1))

at_glmnet<- auto_tuner(
  tuner = grid_search,
  learner = glmnet, 
  resampling = resampling_in, 
  measure = measure
)

instance_glmnet<- resample(task_w, at_glmnet, glmnet, resampling_out, store_models= TRUE)
beiwo07 commented 1 year ago

I found my error when using resample(). The nested resampling runs fine now with my data.