library("DALEX")
model_titanic_glm <- glm(survived ~ gender + age + fare,
data = titanic_imputed, family = "binomial")
explain_titanic_glm <- explain(model_titanic_glm,
data = titanic_imputed[,-8],
y = titanic_imputed[,8],
verbose = FALSE)
cp_glm <- ceteris_paribus(explain_titanic_glm, titanic_imputed[1,])
cp_glm
plot(cp_glm, variables = "age")
# \donttest{
library("ranger")
model_titanic_rf <- ranger(survived ~., data = titanic_imputed, probability = TRUE)
explain_titanic_rf <- explain(model_titanic_rf,
data = titanic_imputed[,-8],
y = titanic_imputed[,8],
label = "ranger forest",
verbose = FALSE)
selected_passangers <- select_sample(titanic_imputed, n = 100)
cp_rf <- ceteris_paribus(explain_titanic_rf, selected_passangers)
cp_rf
plot(cp_rf, variables = "age") +
show_observations(cp_rf, variables = "age") +
show_rugs(cp_rf, variables = "age", color = "red")
selected_passangers <- select_sample(titanic_imputed, n = 1)
selected_passangers
cp_rf <- ceteris_paribus(explain_titanic_rf, selected_passangers)
plot(cp_rf) +
show_observations(cp_rf)
plot(cp_rf, variables = "age") +
show_observations(cp_rf, variables = "age")
plot(cp_rf, variables = "class")
plot(cp_rf, variables = c("class", "embarked"), facet_ncol = 1)
plot(cp_rf, variables = c("class", "embarked"), facet_ncol = 1, categorical_type = "bars")
plotD3(cp_rf, variables = c("class", "embarked", "gender"),
variable_type = "categorical", scale_plot = TRUE,
label_margin = 70)
# }
Run the code above in your browser using DataLab