Nothing
knitr::opts_chunk$set(fig.height = 6, fig.width = 6, fig.align = "center")
This vignette shows usage of EIX package for titanic data. This dataset was copied from stablelearner package. With EIX package we explain XGBoost classification model concerning the survival problem. More details about EIX package here.
#devtools :: install_github("ModelOriented/EIX") library("EIX") library(data.table) set.seed(4) titanic_data<-data.table(na.omit(titanic_data)) knitr::kable(head(titanic_data)) library("Matrix") sparse_matrix <- sparse.model.matrix(survived ~ . - 1, data = titanic_data)
library("xgboost") param <- list(objective = "binary:logistic", max_depth = 2) xgb_model <- xgboost(sparse_matrix, params = param, label = titanic_data[, "survived"] == "yes", nrounds = 50, verbose = FALSE)
First let's plot the model.
lolli<-lollipop(xgb_model,sparse_matrix) plot(lolli, threshold=0.02)
Next we explore interactions using interactions() functions and its plot.
interactions<-interactions(xgb_model, sparse_matrix, option = "interactions") head(interactions, 15) plot(interactions)
importance<-importance(xgb_model, sparse_matrix, option = "both") head(importance, 15) plot(importance, radar=FALSE)
plot(importance)
Let's see an explanation of the prediction for an 18-year-old from England who has traveled 3rd class.
data <- titanic_data[27,] new_observation <- sparse_matrix[27,] wf<-waterfall(xgb_model, new_observation, data, option = "interactions") wf plot(wf)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.