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")
bd_glm <- local_interactions(explain_titanic_glm, titanic_imputed[1, ],
interaction_preference = 500)
bd_glm
plot(bd_glm, max_features = 2)
if (FALSE) {
library("randomForest")
# example with interaction
# classification for HR data
model <- randomForest(status ~ . , data = HR)
new_observation <- HR_test[1,]
explainer_rf <- explain(model,
data = HR[1:1000,1:5])
bd_rf <- local_interactions(explainer_rf,
new_observation)
bd_rf
plot(bd_rf)
# example for regression - apartment prices
# here we do not have intreactions
model <- randomForest(m2.price ~ . , data = apartments)
explainer_rf <- explain(model,
data = apartments_test[1:1000,2:6],
y = apartments_test$m2.price[1:1000])
new_observation <- apartments_test[1,]
bd_rf <- local_interactions(explainer_rf,
new_observation,
keep_distributions = TRUE)
bd_rf
plot(bd_rf)
plot(bd_rf, plot_distributions = TRUE)
}
Run the code above in your browser using DataLab