Let’s compare three models: GLM and GBMs with 100 and 500 trees. For each we create explainer from DALEX package.
library(gbm)
library(DALEX)
library(dplyr)
model_gbm100 <- gbm(m2.price ~ ., data = apartments, n.trees = 100)
expl_gbm100 <- explain(
model_gbm100,
data = apartments,
y = apartments$m2.price,
label = "gbm [100 trees]"
)
model_gbm500 <- gbm(m2.price ~ ., data = apartments, n.trees = 500)
expl_gbm500 <- explain(
model_gbm500,
data = apartments,
y = apartments$m2.price,
label = "gbm [500 trees]"
)
model_glm <- glm(m2.price ~ ., data = apartments)
expl_glm <- explain(model_glm, data = apartments, y = apartments$m2.price)
It is not necessary to use dplyr’s pipes, but it’s designed to use pipes.
Oservations’ names are taken from rownames. For example let’s put district and surface as observation name.
apartments2 <- apartments
rownames(apartments2) <- paste0(
1:nrow(apartments2),
". ",
apartments2$surface,
"m2 ",
apartments2$district
)
create_arena(live = TRUE) %>%
push_model(expl_glm) %>%
push_observations(apartments2) %>%
run_server()