ModelOriented / iBreakDown

Break Down with interactions for local explanations (SHAP, BreakDown, iBreakDown)
https://ModelOriented.github.io/iBreakDown/
GNU General Public License v3.0
81 stars 15 forks source link

Error in shap on model with one variable #93

Closed hbaniecki closed 3 years ago

hbaniecki commented 3 years ago

related to: ModelOriented/modelStudio#99

library(DALEX)
titanic_imputed_sub <- subset(titanic_imputed, select = c("survived", "class"))
model_titanic <- glm(survived ~ class, data = titanic_imputed_sub, family = "binomial")

# create an explainer for the model
explainer_titanic <- explain(model_titanic,
                             data = titanic_imputed_sub[,2, drop=FALSE],
                             y = titanic_imputed$survived,
                             label = "Titanic GLM")

sh <- iBreakDown::shap(explainer_titanic, titanic_imputed_sub[1,,drop=FALSE])
plot(sh)

library(ranger)
temp <- subset(HR, select = c("status", "age"))
model_ranger <- ranger(status ~., temp, probability = TRUE)
explainer_ranger <- explain(model_ranger,
                            data = temp[,2, drop=FALSE],
                            y = temp$status)
sh <- iBreakDown::shap(explainer_ranger, B=2,
                       new_observation = temp[1, ,drop=FALSE])
plot(sh)