Skip to content

Commit 108eff8

Browse files
committed
removed shapviz from dependencies
1 parent 9daaf8e commit 108eff8

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

DESCRIPTION

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Authors@R:
66
Description: Implementation of the model-agnostic Kernel SHAP algorithm by
77
Ian Covert and Su-In Lee (2021)
88
<http://proceedings.mlr.press/v130/covert21a>. Due to its iterative
9-
nature, approximate standard errors of the SHAP values are provided
10-
and convergence is monitored. The package allows to work with any
11-
model that provides numeric predictions. Examples include linear
9+
nature, standard errors of the SHAP values are provided and
10+
convergence is monitored. The package allows to work with any model
11+
that provides numeric predictions. Examples include linear
1212
regression, logistic regression (logit or probability scale), other
1313
generalized linear models, generalized additive models, and neural
1414
networks. The package plays well together with meta-learning packages
15-
like 'caret' or 'mlr3'. Visuaizations can be done using the R package
15+
like 'caret' or 'mlr3'. Visualizations can be done using the R package
1616
'shapviz'.
1717
License: GPL (>= 2)
1818
Depends:
@@ -24,8 +24,5 @@ Imports:
2424
stats,
2525
utils
2626
Suggests:
27-
shapviz,
2827
testthat (>= 3.0.0)
2928
Config/testthat/edition: 3
30-
URL: https://github.com/mayer79/kernelshap
31-
BugReports: https://github.com/mayer79/kernelshap/issues

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22

33
## Introduction
44

5-
SHAP values [1] decompose model predictions into additive contributions of the features in a fair way. A model agnostic approach is called Kernel SHAP, introduced in [1], and investigated in detail in [2].
5+
SHAP values (Lundberg and Lee, 2017) decompose model predictions into additive contributions of the features in a fair way. A model agnostic approach is called Kernel SHAP, introduced in Lundberg and Lee (2017), and investigated in detail in Covert and Lee (2021).
66

7-
The "kernelshap" package implements the Kernel SHAP Algorithm 1 described in the supplement of [2]. An advantage of their algorithm is that SHAP values are supplemented by standard errors. Furthermore, convergence can be monitored and controlled.
7+
The "kernelshap" package implements the Kernel SHAP Algorithm 1 described in the supplement of Covert and Lee (2021). An advantage of their algorithm is that SHAP values are supplemented by standard errors. Furthermore, convergence can be monitored and controlled.
88

9-
The main function, `kernelshap()`, requires three key arguments:
9+
The main function `kernelshap()` has three key arguments:
1010

1111
- `X`: A matrix or data.frame of rows to be explained. Important: The columns should only represent model features, not the response.
1212
- `pred_fun`: A function that takes a data structure like `X` and provides one numeric prediction per row. Some examples:
1313
- `lm()`: `function(X) predict(fit, X)`
1414
- `glm()`: `function(X) predict(fit, X)` (link scale) or
1515
- `glm()`: `function(X) predict(fit, X, type = "response")` (response scale)
1616
- `mgcv::gam()`: Same as for `glm()`
17-
- Keras: `funciton(X) as.numeric(predict(fit, X))`
17+
- Keras: `function(X) as.numeric(predict(fit, X))`
1818
- mlr3: `function(X) fit$predict_newdata(X)$response`
1919
- caret: `function(X) predict(fit, X)`
2020
- `bg_X`: The background data used to integrate out "switched off" features. It should have the same column structure as `X`. A good size is around $50-200$ rows.
2121

2222
**Remarks**
2323

24-
- Visualizations: To visualize the result, you can use R package "shapviz".
25-
- Meta-learners: "kernelshap" plays well together with packages like "caret" and "mlr3".
26-
- Case weights: Passing `bg_w` allows to respect case weights of the background data.
27-
- Classification: If your model provides multiple outputs per observation, e.g., for a classification task, just pass the probabilities of one class via `pred_fun`. This is necessary since `kernelshap()` requires one numeric prediction per row.
28-
- Speed: If `X` and `bg_X` are matrices, the algorithm will often run much faster.
24+
- *Visualization:* To visualize the result, you can use R package "shapviz".
25+
- *Meta-learners:* "kernelshap" plays well together with packages like "caret" and "mlr3".
26+
- *Case weights:* Passing `bg_w` allows to weight background data.
27+
- *Classification:* `kernelshap()` requires one numeric prediction per row. Thus, the prediction function should provide probabilities only of a selected class.
28+
- *Speed:* If `X` and `bg_X` are matrices, the algorithm can runs faster. The faster the prediction function, the more this matters.
2929

3030
## Installation
3131

@@ -43,7 +43,7 @@ library(shapviz)
4343
fit <- lm(Sepal.Length ~ ., data = iris)
4444
pred_fun <- function(X) predict(fit, X)
4545

46-
# Crunch SHAP values (15 seconds)
46+
# Crunch SHAP values (9 seconds)
4747
s <- kernelshap(iris[-1], pred_fun = pred_fun, bg_X = iris[-1])
4848
s
4949

@@ -59,7 +59,7 @@ s
5959
# [2,] 2.463307e-16 5.661049e-16 1.110223e-15 1.755417e-16
6060

6161
# Plot with shapviz
62-
shp <- shapviz(s$S, s$X, s$baseline)
62+
shp <- shapviz(s) # for CRAN release: shapviz(s$S, s$X, s$baseline)
6363
sv_waterfall(shp, 1)
6464
sv_importance(shp)
6565
sv_dependence(shp, "Petal.Length")
@@ -80,11 +80,11 @@ library(shapviz)
8080
fit <- glm(I(Species == "virginica") ~ Sepal.Length + Sepal.Width, data = iris, family = binomial)
8181
pred_fun <- function(X) predict(fit, X, type = "response")
8282

83-
# Crunch SHAP values (10 seconds)
83+
# Crunch SHAP values (4 seconds)
8484
s <- kernelshap(iris[1:2], pred_fun = pred_fun, bg_X = iris[1:2])
8585

8686
# Plot with shapviz
87-
shp <- shapviz(s$S, s$X, s$baseline)
87+
shp <- shapviz(s) # for CRAN release: shapviz(s$S, s$X, s$baseline)
8888
sv_waterfall(shp, 51)
8989
sv_dependence(shp, "Sepal.Length")
9090
```
@@ -127,7 +127,7 @@ system.time(
127127
)
128128

129129
# Plot with shapviz
130-
shp <- shapviz(s$S, s$X, s$baseline)
130+
shp <- shapviz(s) # for CRAN release: shapviz(s$S, s$X, s$baseline)
131131
sv_waterfall(shp, 1)
132132
sv_importance(shp)
133133
sv_dependence(shp, "Petal.Length")
@@ -153,7 +153,7 @@ task_iris <- TaskRegr$new(id = "iris", backend = iris, target = "Sepal.Length")
153153
fit_lm <- lrn("regr.lm")
154154
fit_lm$train(task_iris)
155155
s <- kernelshap(iris, function(X) fit_lm$predict_newdata(X)$response, bg_X = iris)
156-
sv <- shapviz(s$S, s$X, s$baseline)
156+
sv <- shapviz(s) # for CRAN release: shapviz(s$S, s$X, s$baseline)
157157
sv_waterfall(sv, 1)
158158
sv_dependence(sv, "Species")
159159
```
@@ -176,7 +176,7 @@ fit <- train(
176176
)
177177

178178
s <- kernelshap(iris[1, -1], function(X) predict(fit, X), bg_X = iris[-1])
179-
sv <- shapviz(s$S, s$X, s$baseline)
179+
sv <- shapviz(s) # for CRAN release: shapviz(s$S, s$X, s$baseline)
180180
sv_waterfall(sv, 1)
181181
```
182182

cran-comments.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# kernelshap 0.1.0
22

33
This is the inital release of the Kernel SHAP algorithm as described in the article
4-
http://proceedings.mlr.press/v130/covert21a of Covert and Lee 2021.
4+
http://proceedings.mlr.press/v130/covert21a of Covert and Lee 2021. Along with SHAP values for any type of regression, the algorithm provides standard errors of the SHAP values. Furthermore, convergence is monitored.
55

66
## Checks
77

8-
- check_win_devel() -> Ok
9-
- check(manual = TRUE, cran = TRUE) -> usual warning on pdf compression.
8+
- check_win_devel() -> ok
9+
- check_rhub() ->
10+
- check(manual = TRUE, cran = TRUE) -> 0 errors | 0 warnings | 0 notes

packaging.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ use_description(
1818
Version = "0.1.0",
1919
Description = "Implementation of the model-agnostic Kernel SHAP algorithm by
2020
Ian Covert and Su-In Lee (2021) <http://proceedings.mlr.press/v130/covert21a>.
21-
Due to its iterative nature, approximate standard errors of the SHAP values are provided
21+
Due to its iterative nature, standard errors of the SHAP values are provided
2222
and convergence is monitored.
2323
The package allows to work with any model that provides numeric predictions.
2424
Examples include linear regression, logistic regression (logit or probability scale),
2525
other generalized linear models, generalized additive models, and
2626
neural networks. The package plays well together with meta-learning packages
27-
like 'caret' or 'mlr3'. Visuaizations can be done using the R package 'shapviz'.",
27+
like 'caret' or 'mlr3'. Visualizations can be done using the R package 'shapviz'.",
2828
`Authors@R` = "person('Michael', 'Mayer', email = 'mayermichael79@gmail.com', role = c('aut', 'cre'))",
2929
Depends = "R (>= 3.2.0)",
3030
LazyData = NULL
@@ -35,7 +35,7 @@ use_description(
3535
use_package("stats", "Imports")
3636
use_package("utils", "Imports")
3737

38-
use_package("shapviz", "Suggests")
38+
# use_package("shapviz", "Suggests")
3939

4040
use_gpl_license(2)
4141

@@ -87,10 +87,7 @@ install()
8787
# Run only if package is public(!) and should go to CRAN
8888
if (FALSE) {
8989
check_win_devel()
90-
# check_rhub()
91-
check_mac_release()
92-
check_win_release()
93-
check_win_oldrelease()
90+
check_rhub()
9491

9592
# Wait until above checks are passed without relevant notes/warnings
9693
# then submit to CRAN

0 commit comments

Comments
 (0)