library("DALEX")
library("iBreakDown")
set.seed(1313)
model_titanic_glm <- glm(survived ~ gender + age + fare,
data = titanic_imputed, family = "binomial")
explain_titanic_glm <- explain(model_titanic_glm,
data = titanic_imputed,
y = titanic_imputed$survived,
label = "glm")
s_glm <- shap(explain_titanic_glm, titanic_imputed[1, ])
s_glm
plotD3(s_glm)
if (FALSE) {
## Not run:
library("randomForest")
HR_small <- HR[2:500,]
m_rf <- randomForest(status ~. , data = HR_small)
new_observation <- HR_test[1,]
new_observation
p_fun <- function(object, newdata){predict(object, newdata=newdata, type = "prob")}
s_rf <- shap(m_rf,
data = HR_small[,-6],
new_observation = new_observation,
predict_function = p_fun)
plotD3(s_rf, time = 500)
}
Run the code above in your browser using DataLab