Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for GradientBoostingClassifier using TreeExplainer #479

Open
SaadAhmed96 opened this issue Mar 7, 2019 · 9 comments
Open

Support for GradientBoostingClassifier using TreeExplainer #479

SaadAhmed96 opened this issue Mar 7, 2019 · 9 comments
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request stale Indicates that there has been no recent activity on an issue

Comments

@SaadAhmed96
Copy link

I am trying to use the GradientBoostingClassifier using the sklearn library. I wanted to known if its already supported or am I doing any mistake in implementation?

image

@slundberg
Copy link
Collaborator

It is because only the log odds prior is supported right now for the GradientBoostingClassifier: https://github.com/slundberg/shap/blob/b9e71b7d71e04d835d5ce6a000a5b7ea211c7d21/shap/explainers/tree.py#L472-L477

In order to support the PriorProbabilityEstimator another elif would need to be added that correctly sets the base_offset (the starting point the tree begin boosting from), and the units of the values in the leaves of the tree. Then a unit test would need to be added that checks that the sum of the SHAP values equals the model output as expected (this catches almost all types of errors). I'll add a help-wanted tag in case anyone wants to work on a PR for this :)

@slundberg slundberg added the help wanted Indicates that a maintainer wants help on an issue or pull request label Mar 8, 2019
@SaadAhmed96
Copy link
Author

Okay got it.
Thanks

@r-ichi
Copy link

r-ichi commented May 5, 2019

I'm not receiving any errors when trying to use sklearn's GB implementation, is it now correctly supported by any means? :/

Anyway, the package is great! thanks for all the effort!

@crankyelephant
Copy link

Hello!
I have a slightly different issue with applying TreeExplainer SHAP to scikit-learn's GradientBoostingClassifier. Generating SHAP values runs ok, but the expected_value of the Explainer doesn't really make sense. It returns something like -8, whereas it should be from [0,1].

Here is a piece of code I'm using:

model = GradientBoostingClassifier(criterion='friedman_mse', init=None,
              learning_rate=0.1, loss='deviance', max_depth=9,
              max_features=None, max_leaf_nodes=None,
              min_impurity_decrease=0.0, min_impurity_split=None,
              min_samples_leaf=1, min_samples_split=2,
              min_weight_fraction_leaf=0.0, n_estimators=600,
              n_iter_no_change=None, presort='auto', random_state=None,
              subsample=1.0, tol=0.0001, validation_fraction=0.1,
              verbose=0, warm_start=False)
model.fit(X_train, y_train)
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_test)

Running
explainer.expected_value
returns -7.8781 and force plots give nonsensical values for output value.

@desertnaut
Copy link

@crankyelephant it is not that straightforward; see the SO thread How to interpret base_value of GBT classifier when using SHAP?

@desertnaut
Copy link

@slundberg should we close the issue now?

@subsheep
Copy link

subsheep commented Jul 9, 2021

Indeed no errors when using sklearn's GradientBoostingClassifier with TreeExplainer.
Looking at a comment on a related issue (#232 (comment)), it seems that GB is now supported.
Should we close this issue then @slundberg, or I wonder if the support is still under development?

@RoyiAvital
Copy link

I can see that GradientBoostingClassifier is only supported for binary classification.
Is there a plan to extend it?

Copy link

This issue has been inactive for two years, so it's been automatically marked as 'stale'.

We value your input! If this issue is still relevant, please leave a comment below. This will remove the 'stale' label and keep it open.

If there's no activity in the next 90 days the issue will be closed.

@github-actions github-actions bot added the stale Indicates that there has been no recent activity on an issue label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request stale Indicates that there has been no recent activity on an issue
Projects
None yet
Development

No branches or pull requests

7 participants