Skip to content

Commit

Permalink
Merge pull request #61 from bgreenwell/devel
Browse files Browse the repository at this point in the history
support tibbles
  • Loading branch information
bgreenwell committed May 5, 2023
2 parents 9252e78 + dc17223 commit 664fedb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@
/Users/bgreenwell/Dropbox/devel/fastshap/slowtests/slowtest-benchmark.R="29ADFB84"
/Users/bgreenwell/Dropbox/devel/fastshap/slowtests/slowtest-parallel.R="7B058F98"
/Users/bgreenwell/Dropbox/devel/fastshap/slowtests/test-shapviz.R="7F402C66"
/Users/bgreenwell/Dropbox/devel/fastshap/vignettes/ABC.Rmd="3B3641FE"
/Users/bgreenwell/Dropbox/devel/fastshap/vignettes/fastshap.Rmd="536A2979"
/Users/bgreenwell/Dropbox/devel/fastshap/vignettes/rjarticle/greenwell.Rmd="CF8A3E77"
/Users/bgreenwell/Dropbox/trees/book.tex="4ECC8BA9"
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

## Miscellaneous

* The `X` and `newdata` arguments of `explain()` should now work with [tibble](https://cran.r-project.org/package=tibble) [(#20)](https://github.com/bgreenwell/fastshap/issues/20).

* Minor change to `explain.lgb.Booster()` to support breaking changes in [lightgbm](https://cran.r-project.org/package=lightgbm) v4.0.0. (Thanks to @jameslamb and @Mayer79.)

* The dependency on [matrixStats](https://cran.r-project.org/package=matrixStats) has been removed in favor of using R's internal `apply()` and `var()` functions.
Expand Down
15 changes: 9 additions & 6 deletions R/explain.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,18 @@ explain.default <- function(object, feature_names = NULL, X = NULL, nsim = 1,
pred_wrapper = NULL, newdata = NULL, adjust = FALSE,
baseline = NULL, shap_only = TRUE, parallel = FALSE,
...) {

# Compute baseline/average training prediction (fnull) and predictions
# associated with each explanation (fx); if `adjust = FALSE`, then the
# baseline is not needed and defaults to zero.
if (is.null(X)) {
stop("Training features required for approximate Shapley values. Please ",
"supply them via the `X` argument; see `?fastshap::explain` for ",
"details.", call. = FALSE)
}
if (inherits(X, what = "tbl_df")) {
X <- as.data.frame(X)
}
if (is.null(newdata)) {
newdata <- X # explain all rows of background data set
}
Expand All @@ -260,11 +268,6 @@ explain.default <- function(object, feature_names = NULL, X = NULL, nsim = 1,
}

# Deal with other NULL arguments
if (is.null(X)) {
stop("Training features required for approximate Shapley values. Please ",
"supply them via the `X` argument; see `?fastshap::explain` for ",
"details.", call. = FALSE)
}
if (is.null(feature_names)) {
feature_names = colnames(X)
}
Expand Down

0 comments on commit 664fedb

Please sign in to comment.