giuseppec / iml

iml: interpretable machine learning R package

Home Page:https://giuseppec.github.io/iml/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mlr survival model not supported

GaspardDebussche opened this issue · comments

Hi,

I am trying to perform a shapley analysis for survival models and I followed this advice: #83.

After building a learner like this:

tsk = makeSurvTask(
  id="surv",  
  data=data,  
  target=c("surv_time", "surv_cens"),  
  weights = NULL,  
  blocking = NULL,  
  coordinates = NULL,  
  fixup.data = "warn",  
  check.data = TRUE  
)  

lrn = makeLearner("surv.coxph")  
mod = train(lrn, tsk)

Then when doing this:

predictor = Predictor$new(mod, data = subset(data, select = -c(surv_time, surv_cens)), y = data[,c('surv_time', 'surv_cens')])

I have the following error:

Error in inferTaskFromModel.WrappedModel(model) : 
  mlr task type <surv> not supported

Would you know how to bypass this?

The workaround ist to define a predict.fun. I have not tested it, but it should be something like this:

predict_fun = function(newdata){
tsk = makeSurvTask(
  id="surv",  
  data=newdata,  
  target=c("surv_time", "surv_cens"),  
  weights = NULL,  
  blocking = NULL,  
  coordinates = NULL,  
  fixup.data = "warn",  
  check.data = TRUE  
) 
# This following line might need some modification to return only a vector or data.frame with one column
predict(mod, tsk)
}

predictor = Predictor$new(data = subset(data, select = -c(surv_time, surv_cens)))], predict.fun = predict_fun)