# NOT RUN {
library("DALEX")
library("iBreakDown")
# Toy examples, because CRAN angels ask for them
titanic <- na.omit(titanic)
set.seed(1313)
titanic_small <- titanic[sample(1:nrow(titanic), 500), c(1,2,6,9)]
model_titanic_glm <- glm(survived == "yes" ~ gender + age + fare,
data = titanic, family = "binomial")
explain_titanic_glm <- explain(model_titanic_glm,
data = titanic_small[,-9],
y = titanic_small$survived == "yes")
bd_rf <- local_attributions(explain_titanic_glm, titanic_small[1, ])
bd_rf
plot(bd_rf, max_features = 3)
# }
# NOT RUN {
## Not run:
library("randomForest")
set.seed(1313)
# 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],
y = HR$status[1:1000])
bd_rf <- local_attributions(explainer_rf,
new_observation)
bd_rf
plot(bd_rf)
plot(bd_rf, baseline = 0)
# example for regression - apartment prices
# here we do not have interactions
model <- randomForest(m2.price ~ . , data = apartments)
explainer_rf <- explain(model,
data = apartments_test[1:1000,2:6],
y = apartments_test$m2.price[1:1000])
bd_rf <- local_attributions(explainer_rf,
apartments_test[1,])
bd_rf
plot(bd_rf, digits = 1)
bd_rf <- local_attributions(explainer_rf,
apartments_test[1,],
keep_distributions = TRUE)
plot(bd_rf, plot_distributions = TRUE)
# }
Run the code above in your browser using DataLab