Closed MosquitoFan closed 1 year ago
Hello @MosquitoFan,
I think the issue is that the wrong kind of explainer is created (from the DALEX
package) as making the pipeline doesn't give the correct class to the pipeline object. (We would expect it to be LearnerSurv
).
However, the possible fix is simple:
explain()
function with explain_survival()
when creating your explainer. explainer <- explain_survival(model = xgb_lrn, data = train, y = Surv(time[!fold == i1],event[!fold == i1]), predict_function = function(model,newdata){ predict(model, newdata, predict_type = "<Prediction>")$crank }, predict_survival_function = function(model,newdata,times){ t(predict(model, newdata, predict_type = "<Prediction>")$distr$survival(times)) }, predict_cumulative_hazard_function = function(model,newdata,times){ t(predict(model, newdata, predict_type = "<Prediction>")$distr$cumHazard(times)) } )
I've tested it on some of my data and it works. Let me know if it solved your issue :)
P.S.
If you see residuals ...
in the last line of output when creating an explainer you're creating a DALEX
not a survex
explainer.
Hi mikolaj,
Thank you so much, it works and the plot looks beautiful!
I used the mlr3 and mlr3proba with surv.xgboost as follows, since xgboost cannot output survival matrix so I used a pipeline, `xgb_task = TaskSurv$new("train", backend = data.frame(train), time = "time", event = "event")
xgb_lrn = as_learner(ppl(c("distrcompositor"), lrn("surv.xgboost", objective = "survival:cox", nrounds=300L, eta=0.1), form = "ph")) `
then I try to explain the model, I set the predict_survival_function and predict_cumulative_hazard_function, which could be successfully conducted when I run them,
explainer <- explain(model = xgb_lrn, data = train, y = Surv(time[!fold == i1],event[!fold == i1]), predict_function = function(model,newdata){ predict(model, newdata, predict_type = "<Prediction>")$crank }, predict_survival_function = function(model,newdata,times){ t(predict(model, newdata, predict_type = "<Prediction>")$distr$survival(times)) }, predict_cumulative_hazard_function = function(model,newdata,times){ t(predict(model, newdata, predict_type = "<Prediction>")$distr$cumHazard(times)) } )
predict(explainer,train)
to get the risk scoreHowever, I meet error when adding output_type
model_parts(explainer)
model_performance(explainer)
I don't know what's wrong with my code.