library("DALEX")
library("ingredients")
library("ranger")
# smaller data, quicker example
titanic_small <- select_sample(titanic_imputed, n = 500, seed = 1313)
# \donttest{
# build a model
model_titanic_rf <- ranger(survived ~., data = titanic_small, probability = TRUE)
explain_titanic_rf <- explain(model_titanic_rf,
data = titanic_small[,-8],
y = titanic_small[,8],
label = "ranger forest",
verbose = FALSE)
selected_passangers <- select_sample(titanic_small, n = 100)
cp_rf <- ceteris_paribus(explain_titanic_rf, selected_passangers)
pdp_rf_p <- aggregate_profiles(cp_rf, type = "partial", variable_type = "numerical")
pdp_rf_p$`_label_` <- "RF_partial"
pdp_rf_c <- aggregate_profiles(cp_rf, type = "conditional", variable_type = "numerical")
pdp_rf_c$`_label_` <- "RF_conditional"
pdp_rf_a <- aggregate_profiles(cp_rf, type = "accumulated", variable_type = "numerical")
pdp_rf_a$`_label_` <- "RF_accumulated"
plotD3(pdp_rf_p, pdp_rf_c, pdp_rf_a, scale_plot = TRUE)
pdp <- aggregate_profiles(cp_rf, type = "partial", variable_type = "categorical")
pdp$`_label_` <- "RF_partial"
plotD3(pdp, variables = c("gender","class"), label_margin = 70)
# }
Run the code above in your browser using DataLab