bgreenwell / fastshap

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

Add lightgbm treeSHAP support #16

Closed mayer79 closed 3 years ago

mayer79 commented 3 years ago

Hello

I added a draft for supporting LightGBM's internal TreeSHAP algo, solving https://github.com/bgreenwell/fastshap/issues/15

Example

library(fastshap)
library(ggplot2)
library(xgboost)
library(lightgbm)

mod_xgb = xgb.train(
  params = list(objective = "reg:squarederror"),
  data = xgb.DMatrix(data.matrix(iris[, -1]), label = iris[[1]]),
  nrounds = 10,
  verbose = -2
)

mod_lgb = lgb.train(
  params = list(objective = "regression"),
  data = lgb.Dataset(data.matrix(iris[, -1]), label = iris[[1]]),
  nrounds = 10,
  verbose = -2
)

shap_xgb <- explain(mod_xgb, exact = TRUE, X = data.matrix(iris[, -1]))
autoplot(shap_xgb)

shap_lgb <- explain(mod_lgb, exact = TRUE, X = data.matrix(iris[, -1]))
autoplot(shap_lgb)

Let me know if something feels odd please.

mayer79 commented 3 years ago

@bgreenwell : hello Brandon, should I retry to push this LightGBM addon? (I don't think the CI fail is due to my change).

bgreenwell commented 3 years ago

@bgreenwell : hello Brandon, should I retry to push this LightGBM addon? (I don't think the CI fail is due to my change).

Hi @mayer79 not sure how I missed this PR. The fail is probably due Travis-CI no longer being supported. I’ll take a look at this PR in the next couple of days. Thanks a lot!! 🙏

mayer79 commented 3 years ago

@bgreenwell : hello Brandon, should I retry to push this LightGBM addon? (I don't think the CI fail is due to my change).

Hi @mayer79 not sure how I missed this PR. The fail is probably due Travis-CI no longer being supported. I’ll take a look at this PR in the next couple of days. Thanks a lot!! 🙏

No problem at all :-). Thanks a lot for looking into this.

bgreenwell commented 3 years ago

Hey @mayer79, sorry for the inconvenience, but would you mind submitting a PR for this new version? If not, I can easily grab your changes and just throw them in manually. Whatever is easiest.

mayer79 commented 3 years ago

Hey @mayer79, sorry for the inconvenience, but would you mind submitting a PR for this new version? If not, I can easily grab your changes and just throw them in manually. Whatever is easiest.

No issue at all! I repushed but there are some conflicts. As I don't have the permission to resolve them, we can do two things:

  1. You fix them.
  2. I update my fork with your changes and deal with the conflicts.
bgreenwell commented 3 years ago

@mayer79 I ended up just manually pulling in most of the changes and crediting your contribution in the NEWS file (hope that's OK); my git skills are questionable when it comes to merging with conflicts :/

Let me know if the new changes do not work on your end and thanks a bunch for this valuable contribution! (Always looking for help :)

mayer79 commented 3 years ago

Perfect fine. Thanks for the extra work!