Skip to content

Commit

Permalink
Merge pull request #162 from martinju/fix_new_shapr_PR
Browse files Browse the repository at this point in the history
Fix for new shapr package structure
  • Loading branch information
mayer79 authored Nov 16, 2024
2 parents 3a91c0b + c7b692d commit 9e0bbf7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions R/shapviz.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ shapviz.predict_parts <- function(object, ...) {
#' @describeIn shapviz
#' Creates a "shapviz" object from `shapr::explain()`.
#' @export
shapviz.shapr <- function(object, X = object[["x_test"]], collapse = NULL, ...) {
dt <- as.matrix(object[["dt"]])
shapviz.shapr <- function(object, X = as.data.frame(object$internal$data$x_explain), collapse = NULL, ...) {
dt <- as.matrix(object[["shapley_values_est"]])
shapviz.matrix(
object = dt[, setdiff(colnames(dt), "none"), drop = FALSE],
object = dt[, setdiff(colnames(dt), c("none","explain_id")), drop = FALSE],
X = X,
baseline = dt[1L, "none"],
collapse = collapse
Expand Down
7 changes: 6 additions & 1 deletion man/shapviz.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions vignettes/basic_use.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ library(shapviz)
library(shapr)

fit <- lm(Sepal.Length ~ ., data = iris)
x <- shapr(iris, fit)
explanation <- shapr::explain(
iris, approach = "ctree", explainer = x, prediction_zero = mean(iris$Sepal.Length)
model = fit,
x_train = iris[-1],
x_explain = iris[-1],
approach = "ctree",
phi0 = mean(iris$Sepal.Length)
)

shp <- shapviz(explanation)
sv_importance(shp)
sv_dependence(shp, "Sepal.Width")
Expand Down

0 comments on commit 9e0bbf7

Please sign in to comment.