ModelOriented / ingredients

Effects and Importances of Model Ingredients
https://modeloriented.github.io/ingredients/
GNU General Public License v3.0
37 stars 19 forks source link

How to make ceteris_paribus plots for multiple models? #110

Closed hbaniecki closed 4 years ago

hbaniecki commented 4 years ago
library(DALEX)
library(ingredients)
library(ranger)
​
​
#:# easy for one observation
no <- titanic_imputed[1,]
​
m1 <- glm(survived~. , data = titanic_imputed)
e1 <- explain(m1, titanic_imputed, titanic_imputed$survived, label = "glm_henry")
cp1 <- ceteris_paribus(e1, no)
​
m2 <- ranger(survived~. , data = titanic_imputed)
e2 <- explain(m2, titanic_imputed, titanic_imputed$survived, label = "rpart_henry")
cp2 <- ceteris_paribus(e2, no)
​
​
plot(cp1, cp2, color="_label_", variables = "age")
​
​
#:# harder for multiple observations
no <- titanic_imputed[1:2,]
​
m1 <- glm(survived~. , data = titanic_imputed)
e1 <- explain(m1, titanic_imputed, titanic_imputed$survived, label = "glm")
cp1 <- ceteris_paribus(e1, no)
cp1$`_ids_` <- ifelse(cp1$`_ids_`==1,"glm_henry","glm_jacob")
​
m2 <- ranger(survived~. , data = titanic_imputed)
e2 <- explain(m2, titanic_imputed, titanic_imputed$survived, label = "ranger")
cp2 <- ceteris_paribus(e2, no)
cp2$`_ids_` <- ifelse(cp2$`_ids_`==1,"ranger_henry","ranger_jacob")
​
​
plot(cp1, cp2, color="_ids_", variables = "fare")