# NOT RUN {
# }
# NOT RUN {
library("ranger")
titanic_ranger_model <- ranger(survived~., data = titanic_imputed, num.trees = 50,
probability = TRUE)
explainer_ranger <- explain(titanic_ranger_model, data = titanic_imputed[,-8],
y = titanic_imputed$survived)
vi_ranger <- model_parts(explainer_ranger, type = "raw")
head(vi_ranger, 8)
plot(vi_ranger)
titanic_glm_model <- glm(survived~., data = titanic_imputed, family = "binomial")
explainer_glm <- explain(titanic_glm_model, data = titanic_imputed[,-8],
y = titanic_imputed$survived)
logit <- function(x) exp(x)/(1+exp(x))
vi_glm <- model_parts(explainer_glm, type = "raw",
loss_function = function(observed, predicted)
sum((observed - logit(predicted))^2))
head(vi_glm, 8)
plot(vi_glm)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab