Skip to content

Commit 9e0bbf7

Browse files
authored
Merge pull request #162 from martinju/fix_new_shapr_PR
Fix for new shapr package structure
2 parents 3a91c0b + c7b692d commit 9e0bbf7

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

R/shapviz.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,10 @@ shapviz.predict_parts <- function(object, ...) {
410410
#' @describeIn shapviz
411411
#' Creates a "shapviz" object from `shapr::explain()`.
412412
#' @export
413-
shapviz.shapr <- function(object, X = object[["x_test"]], collapse = NULL, ...) {
414-
dt <- as.matrix(object[["dt"]])
413+
shapviz.shapr <- function(object, X = as.data.frame(object$internal$data$x_explain), collapse = NULL, ...) {
414+
dt <- as.matrix(object[["shapley_values_est"]])
415415
shapviz.matrix(
416-
object = dt[, setdiff(colnames(dt), "none"), drop = FALSE],
416+
object = dt[, setdiff(colnames(dt), c("none","explain_id")), drop = FALSE],
417417
X = X,
418418
baseline = dt[1L, "none"],
419419
collapse = collapse

man/shapviz.Rd

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/basic_use.Rmd

+6-2
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,14 @@ library(shapviz)
163163
library(shapr)
164164

165165
fit <- lm(Sepal.Length ~ ., data = iris)
166-
x <- shapr(iris, fit)
167166
explanation <- shapr::explain(
168-
iris, approach = "ctree", explainer = x, prediction_zero = mean(iris$Sepal.Length)
167+
model = fit,
168+
x_train = iris[-1],
169+
x_explain = iris[-1],
170+
approach = "ctree",
171+
phi0 = mean(iris$Sepal.Length)
169172
)
173+
170174
shp <- shapviz(explanation)
171175
sv_importance(shp)
172176
sv_dependence(shp, "Sepal.Width")

0 commit comments

Comments
 (0)