bgreenwell / fastshap

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

All shap values were 0. #57

Closed fysqy closed 1 year ago

fysqy commented 1 year ago

library(fastshap) library(randomForest) model1rf1 <- rf1[["finalModel"]] pfun <- function(model1rf1, newdata) { p_deri1rf1$Y }

Compute fast (approximate) Shapley values using 10 Monte Carlo repetitions

system.time({ # estimate run time set.seed(5038) shap <- fastshap::explain(model1rf1, X = deridata1_x, pred_wrapper = pfun, nsim = 10,) })

When I run the above code, all the shap values I get are 0.

bgreenwell commented 1 year ago

Hi @fysqy, can you provide a reproducible example for me to run on my end?

mayer79 commented 1 year ago

@fysqy Your predict function seems to be wrongly specified. It should return predictions calculated from the input of pfun

bgreenwell commented 1 year ago

Good catch @mayer79! @fysqy there should be plenty of examples in the docs and website, but feel free to reopen if you still have trouble.