bgreenwell / fastshap

Fast approximate Shapley values in R
https://bgreenwell.github.io/fastshap/
112 stars 18 forks source link

baseline is 0 #64

Closed mayer79 closed 1 year ago

mayer79 commented 1 year ago

@bgreenwell : one question about the baseline fnull:

When I run this code from the master branch, the baseline is 0. Same for ranger models.

library(fastshap)

fit <- lm(Sepal.Length ~ Sepal.Width + Petal.Length, data = iris)

shap <- fastshap::explain(
  fit, 
  X = iris[c("Sepal.Width", "Petal.Length")],
  nsim = 100, 
  pred_wrapper = predict,
  shap_only = FALSE  # Same with shap_only = TRUE
)

What am I doing wrong? :-)

mayer79 commented 1 year ago

Oh, simply setting adjust = TRUE seems to fix it!

bgreenwell commented 1 year ago

Yep, that was the intention. The baseline is not calculated unless it's needed for the adjustment; and will default to zero in that case. There's also a baseline argument to use if you don't want explain() to compute it from X.

mayer79 commented 1 year ago

Got it, thx.