PhilippPro / tuneRanger

Automatic tuning of random forests
33 stars 9 forks source link

How to use tuneRanger with makeSurvTask #12

Open sibipx opened 1 year ago

sibipx commented 1 year ago

Hi!

I used tuneRanger for binary and multiclass classification and I am happy with the results and the performance of the package. I would like to use it for survival problems as well.

The help page says "task The mlr task created by makeClassifTask, makeRegrTask or makeSurvTask." I don't seem to be able to make it work. A simple example below:

library(survival)
library(tuneRanger)

head(lung)

lung$status <- ifelse(lung$status == 2, 1, 0)
lung <- lung[complete.cases(lung),]

# build model
#measure <- list(auc)
measure <- NULL
task <- makeSurvTask(data = lung,
                     target = c("time", "status"))

parameters <- list(replace = TRUE)

res <- tuneRanger(task, measure = measure,
                  num.trees = 500, 
                  iters = 20, 
                  show.info = TRUE,
                  tune.parameters = c("mtry", "min.node.size"),
                  parameters = parameters)

gives me error below:

Computing y column(s) for design. Not provided. Error in UseMethod("getOOBPredsLearner") : no applicable method for 'getOOBPredsLearner' applied to an object of class "c('surv.ranger', 'RLearnerSurv', 'RLearner', 'Learner')"

Thanks for any help on this!

PhilippPro commented 4 months ago

Sorry for the late response. It would be needed to write a getOOBPredsLearner.surv.ranger like here.

https://github.com/mlr-org/mlr/blob/main/R/RLearner_regr_ranger.R

This does not exist yet.