-
Notifications
You must be signed in to change notification settings - Fork 3
/
EIX.Rmd
90 lines (58 loc) · 2.13 KB
/
EIX.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
title: "The EIX R package"
date: "`r format(Sys.time(), '%d-%m-%Y')`"
output:
html_document:
toc: true
toc_float: true
---
This report aims to present the capabilities of the package `EIX`.
The document is a part of the paper "Landscape of R packages for eXplainable Machine Learning", S. Maksymiuk, A. Gosiewska, and P. Biecek.
(https://arxiv.org/abs/2009.13248). It contains a real life use-case with a hand of [titanic_imputed](https://modeloriented.github.io/DALEX/reference/titanic.html) data set described in Section *Example gallery for XAI packages* of the article.
We did our best to show the entire range of the implemented explanations. Please note that the examples may be incomplete. If you think something is missing, feel free to make a pull request at the GitHub repository [MI2DataLab/XAI-tools](https://github.com/MI2DataLab/XAI-tools).
The list of use-cases for all packages included in the article is [here](http://xai-tools.drwhy.ai/).
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
```
Load [`titanic_imputed`](https://modeloriented.github.io/DALEX/reference/titanic.html) data set.
```{r}
data(titanic_imputed, package = "DALEX")
head(titanic_imputed)
```
```{r}
library(xgboost)
library(EIX)
```
Fit a xgboost to the titanic imputed data.
```{r}
library("Matrix")
X <- sparse.model.matrix(survived ~ . - 1, data = titanic_imputed)
xgb_model <- xgboost(X, titanic_imputed$survived, nrounds = 10, params = list(objective = "binary:logistic"), prediction = TRUE)
```
# Model parts
## Interaction measure
```{r}
interactions <- interactions(xgb_model, X, option = "interactions")
plot(interactions)
```
## Variable Importance
```{r}
importance <- importance(xgb_model, X, option = "both")
plot(importance)
```
# Predict parts
## Interaction based explanation of single observation
```{r}
new_observation <- X[27,]
wf <- waterfall(xgb_model, new_observation, titanic_imputed[27,], option = "interactions")
plot(wf)
```
# Model diagnostics
```{r}
lolli <- lollipop(xgb_model, X)
plot(lolli, threshold=0.02)
```
# Session info
```{r}
sessionInfo()
```