Skip to content

Commit

Permalink
Merge pull request #4 from mayer79/update_shap2
Browse files Browse the repository at this point in the history
Update SHAP markdown and html
  • Loading branch information
mayer79 authored Dec 20, 2023
2 parents 10406db + 5e5c54d commit 42fee86
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6,493 deletions.
2 changes: 1 addition & 1 deletion 14 - SHAP/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ The folder "rdata" contains the Parquet file "df.parquet", representing 1 mio ro
## Code output

- Python: Click on the ipynb file
- R: [shap_tutorial.html](https://htmlpreview.github.io/?https://github.com/JSchelldorfer/ActuarialDataScience/blob/master/14%20-%20SHAP/shap_tutorial.html) (please click on this link to preview html output; in order to see the table of contents properly, download the html and open it in your browser.)
- R: [shap.html](https://htmlpreview.github.io/?https://github.com/JSchelldorfer/ActuarialDataScience/blob/master/docs/shap.html) (please click on this link to preview html output; in order to see the table of contents properly, download the html and open it in your browser.)
45 changes: 16 additions & 29 deletions 14 - SHAP/shap_tutorial.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ library(farff) # 1.1.1 (required by OpenML)
library(OpenML) # 1.12 (if you download the data from OpenML)
library(withr) # 2.5.0
library(tidyverse) # 1.3.2
library(tidyverse) # 2.0.0
# Models
library(caret) # 6.0-93
library(keras) # 2.11.0
library(caret) # 6.0.94
library(keras) # 2.11.1
library(lightgbm) # 3.3.5
# SHAP
library(shapviz) # 0.6.0
library(kernelshap) # 0.3.4
library(shapviz) # 0.9.1
library(kernelshap) # 0.3.7
library(patchwork) # 1.1.2
# df <- arrow::read_parquet("rdata/df.parquet")
df <- getOMLDataSet(data.id = 45106L)$data
Expand Down Expand Up @@ -230,12 +231,10 @@ sv_importance(shap_lgb, kind = "bee")
Each figure uses the potentially strongest interacting feature on the color scale. Therefore, the colors differ from picture to picture (and later also from model to model).

```{r}
for (xvar in x) {
(sv_dependence(shap_lgb, xvar, alpha = 0.5) +
ggtitle(xvar) +
ylim(-0.5, 1.05)) %>%
print()
}
theme_set(theme_gray(base_size = 8))
sv_dependence(shap_lgb, x, alpha = 0.5) &
ylim(-0.5, 1.05)
```

## GLM with Kernel SHAP
Expand All @@ -247,12 +246,8 @@ system.time(
shap_glm <- shapviz(kernelshap(fit_glm, X = X_explain, bg_X = bg, verbose = FALSE))
)
for (xvar in x) {
(sv_dependence(shap_glm, xvar, alpha = 0.5) +
ggtitle(xvar) +
ylim(-0.5, 1.05)) %>%
print()
}
sv_dependence(shap_glm, x, alpha = 0.5) &
ylim(-0.5, 1.05)
```

## Neural net with Kernel SHAP
Expand All @@ -273,12 +268,8 @@ system.time(
)
# Dependence plots
for (xvar in x) {
(sv_dependence(shap_nn, xvar, alpha = 0.5) +
ggtitle(xvar) +
ylim(-0.5, 1.05)) %>%
print()
}
sv_dependence(shap_nn, x, alpha = 0.5) &
ylim(-0.5, 1.05)
```

## True model with Kernel SHAP
Expand All @@ -296,10 +287,6 @@ system.time(
)
)
for (xvar in x) {
(sv_dependence(shap_truth, xvar, alpha = 0.5) +
ggtitle(xvar) +
ylim(-0.5, 1.05)) %>%
print()
}
sv_dependence(shap_truth, x, alpha = 0.5) &
ylim(-0.5, 1.05)
```
3,209 changes: 0 additions & 3,209 deletions 14 - SHAP/shap_tutorial.html

This file was deleted.

1 change: 0 additions & 1 deletion docs/README.md

This file was deleted.

102 changes: 47 additions & 55 deletions docs/shap.html

Large diffs are not rendered by default.

3,198 changes: 0 additions & 3,198 deletions docs/shap_tutorial.html

This file was deleted.

0 comments on commit 42fee86

Please sign in to comment.