if (FALSE) {
library("DALEX")
library("breakDown")
library("randomForest")
set.seed(1313)
# example with interaction
# classification for HR data
model <- randomForest(status ~ . , data = HR)
new_observation <- HRTest[1,]
data <- HR[1:1000,]
predict.function <- function(m,x) predict(m,x, type = "prob")[,1]
explainer_rf_fired <- explain(model,
data = HR[1:1000,1:5],
y = HR$status[1:1000] == "fired",
predict_function = function(m,x) predict(m,x, type = "prob")[,1],
label = "fired")
bd_rf <- break_down(explainer_rf_fired,
new_observation,
keep_distributions = TRUE)
bd_rf
plot(bd_rf)
plot(bd_rf, plot_distributions = TRUE)
bd_rf <- break_down(explainer_rf_fired,
new_observation,
check_interactions = FALSE,
keep_distributions = TRUE)
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 = apartmentsTest[1:1000,2:6],
y = apartmentsTest$m2.price[1:1000],
label = "rf")
bd_rf <- break_down(explainer_rf,
apartmentsTest[1,],
check_interactions = FALSE,
keep_distributions = TRUE)
bd_rf
plot(bd_rf)
plot(bd_rf, plot_distributions = TRUE)
}
Run the code above in your browser using DataLab