library("DALEX")
if (FALSE) {
library("randomForest")
set.seed(59)
apartments_rf_model <- randomForest(m2.price ~ construction.year + surface + floor +
no.rooms + district, data = apartments)
explainer_rf <- explain(apartments_rf_model,
data = apartmentsTest[,2:6], y = apartmentsTest$m2.price)
apartments_small <- apartmentsTest[1:20,]
apartments_small_1 <- apartmentsTest[1,]
apartments_small_2 <- select_sample(apartmentsTest, n = 20)
apartments_small_3 <- select_neighbours(apartmentsTest, apartments_small_1, n = 20)
cp_rf <- ceteris_paribus(explainer_rf, apartments_small)
cp_rf_1 <- ceteris_paribus(explainer_rf, apartments_small_1)
cp_rf_2 <- ceteris_paribus(explainer_rf, apartments_small_2)
cp_rf_3 <- ceteris_paribus(explainer_rf, apartments_small_3)
cp_rf
cp_rf_y <- ceteris_paribus(explainer_rf, apartments_small, y = apartments_small$m2.price)
cp_rf_y1 <- ceteris_paribus(explainer_rf, apartments_small_1, y = apartments_small_1$m2.price)
cp_rf_y2 <- ceteris_paribus(explainer_rf, apartments_small_2, y = apartments_small_2$m2.price)
cp_rf_y3 <- ceteris_paribus(explainer_rf, apartments_small_3, y = apartments_small_3$m2.price)
plot(cp_rf_y, show_profiles = TRUE, show_observations = TRUE,
show_residuals = TRUE, color = "black",
alpha = 0.3, alpha_points = 1, alpha_residuals = 0.5,
size_points = 2, size_rugs = 0.5)
plot(cp_rf_y, show_profiles = TRUE, show_observations = TRUE,
show_residuals = TRUE, color = "black",
selected_variables = c("construction.year", "surface"),
alpha = 0.3, alpha_points = 1, alpha_residuals = 0.5,
size_points = 2, size_rugs = 0.5)
plot(cp_rf_y1, show_profiles = TRUE, show_observations = TRUE, show_rugs = TRUE,
show_residuals = TRUE, alpha = 0.5, size_points = 3,
alpha_points = 1, size_rugs = 0.5)
plot(cp_rf_y2, show_profiles = TRUE, show_observations = TRUE, show_rugs = TRUE,
alpha = 0.2, alpha_points = 1, size_rugs = 0.5)
plot(cp_rf_y3, show_profiles = TRUE, show_rugs = TRUE,
show_residuals = TRUE, alpha = 0.2, color_residuals = "orange", size_rugs = 0.5)
plot(cp_rf_y, show_profiles = TRUE, show_observations = TRUE, show_rugs = TRUE, size_rugs = 0.5,
show_residuals = TRUE, alpha = 0.5, color = "surface", as.gg = TRUE) +
scale_color_gradient(low = "darkblue", high = "darkred")
plot(cp_rf_y1, show_profiles = TRUE, show_observations = TRUE, show_rugs = TRUE,
show_residuals = TRUE, alpha = 0.5, color = "surface", size_points = 3)
plot(cp_rf_y2, show_profiles = TRUE, show_observations = TRUE, show_rugs = TRUE,
size = 0.5, alpha = 0.5, color = "surface")
plot(cp_rf_y, show_profiles = TRUE, show_rugs = TRUE, size_rugs = 0.5,
show_residuals = FALSE, aggregate_profiles = mean, color = "darkblue")
}
Run the code above in your browser using DataLab