Skip to content

Commit f74d7c3

Browse files
committed
Add unit test
1 parent db38b00 commit f74d7c3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ ks_class <- kernelshap(fit_class, X = iris, bg_X = iris) |>
251251
sv_importance(ks_class)
252252
```
253253

254+
![](man/figures/README-prob-class.svg)
255+
256+
![](man/figures/README-fact-class.svg)
257+
254258
## Meta-learning packages
255259

256260
Here, we provide some working examples for "tidymodels", "caret", and "mlr3".

tests/testthat/test-kernelshap-multioutput.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ test_that("SHAP + baseline = prediction works with case weights", {
8787
expect_equal(rowSums(sY$S[[2L]]) + sY$baseline[2L], predsY[5:10, 2L])
8888
})
8989

90+
test_that("factor predictions work", {
91+
pf <- function(m, X) factor(X[, "v1"], levels = 0:1, labels = c("zero", "one"))
92+
X <- cbind(v1 = 0:1, v2 = 0)
93+
out <- kernelshap(1, X = X, bg_X = X, pred_fun = pf, verbose = FALSE)
94+
expect_equal(colnames(out$S$zero), c("v1", "v2"))
95+
expect_equal(names(out$S), c("zero", "one"))
96+
expect_equal(out$predictions, cbind(zero = 1:0, one = 0:1))
97+
})

0 commit comments

Comments
 (0)