ModelOriented / survex

Explainable Machine Learning in Survival Analysis
https://modeloriented.github.io/survex
GNU General Public License v3.0
101 stars 10 forks source link

Add `plot.model_profile` for two or more models #12

Closed hbaniecki closed 1 year ago

hbaniecki commented 2 years ago

plot.model_profile in DALEX/ingredients uses the color parameter to choose a dimension for plot splitting, e.g. by the model (label). This allows for comparing two models in one plot.

library(DALEX)

titanic_glm_model <- glm(survived~., data = titanic_imputed, family = "binomial")
explainer_glm <- explain(titanic_glm_model, data = titanic_imputed, verbose = FALSE)
expl_glm <- model_profile(explainer_glm)

library("ranger")
titanic_ranger_model <- ranger(survived~., data = titanic_imputed, num.trees = 50,
                               probability = TRUE)
explainer_ranger  <- explain(titanic_ranger_model, data = titanic_imputed, verbose = FALSE)
expl_ranger <- model_profile(explainer_ranger)

plot(expl_ranger$agr_profiles, expl_glm$agr_profiles, color = "_label_") 
plot(expl_ranger$agr_profiles, expl_glm$agr_profiles)

It would be nice to have similar functionality in survex

ve_rf <- model_profile(explainer_rf, variables = "age")
plot(ve_rf)
ve_cox <- model_profile(explainer_cox, variables = "age")
plot(ve_cox, ve_rf) # won't work

Firstly, at this moment the above code should return an error

The idea is to add some facet parameter, which by default is set to variables but can be changed to _label_ etc.

plot(ve_cox, ve_rf, facet="_label_")

Mockup:

image

Using:

(plot(ve_rf) + ggtitle("rsf")) +
  (plot(ve_cox) + ggtitle("cph")) + 
  plot_annotation(subtitle="")
mikolajsp commented 2 years ago

I agree this is useful functionality. I'm just wondering how to show this information in one plot.

Do you think one column per model would be a good way to show it? and then different variables in rows?

hbaniecki commented 2 years ago

Perhaps, the most popular use cases consider 1-2-4 variables and 1-2-3 models.