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

Using XGboost with Kernel SHAP #179

Closed
DiliSR opened this issue Jul 24, 2018 · 14 comments
Closed

Using XGboost with Kernel SHAP #179

DiliSR opened this issue Jul 24, 2018 · 14 comments

Comments

@DiliSR
Copy link

DiliSR commented Jul 24, 2018

Hi,

Can we use xgboost with Kernel SHAP?

Thanks

@slundberg
Copy link
Collaborator

Yes you can, you just need to define a prediction function to pass to KernelExplainer. Though of course it will be a worse and much slower estimate than what TreeExplainer would give.

@DiliSR
Copy link
Author

DiliSR commented Jul 25, 2018

It give an error as booster object not callable. The model is the model that you have used in medical dataset.

@slundberg
Copy link
Collaborator

Right that's because you need to pass a function to KernelExplainer that accepts a numpy array and outputs a vector of model predictions.

@DiliSR
Copy link
Author

DiliSR commented Jul 27, 2018 via email

@DiliSR
Copy link
Author

DiliSR commented Jul 27, 2018

I have tried using
k=model.predict(xgb_test)
explainer_xgk = shap.KernelExplainer(k,med)

it givens an error as Provided model function fails when applied to the provided data set.

Could you please help me?

@DiliSR
Copy link
Author

DiliSR commented Jul 30, 2018

Hi,

Do you have any example that you have generate the SHAP values from Tree explainer and Kernel explainer using the same model (Xgboost)

Please help me on this.

@slundberg
Copy link
Collaborator

@Dilini-Sewwandi-Rajapaksha I am sorry this is causing you trouble. Unfortunately I often can't respond quickly to every issue on here since this is an open source project that I don't maintain as a full time job.

The problem with what you posted is something specific to Python, not SHAP. k as you have defined it is not a function but the output of the model.predict function. k = model.predict should be what you want. I don't have an example right now of using KernelExplainer for XGBoost, though I expect to as some point soon (couple weeks) as part of some benchmark tests I'll be pushing.

@DiliSR
Copy link
Author

DiliSR commented Jul 30, 2018

Thank you. After you have done with that please send me the link .

@noleto
Copy link

noleto commented Aug 1, 2018

Might be helpful?

=> How to use XGBoost with Kernel SHAP and Tree SHAP (using the same model)
https://gist.github.com/noleto/05dfa4a691ebbc8816c035b86d2d00d4

@DiliSR
Copy link
Author

DiliSR commented Aug 1, 2018

Thank you very much @noleto

@slundberg
Copy link
Collaborator

thanks!

@mayer79
Copy link

mayer79 commented Jan 17, 2021

@noleto: sweet workaround, thx. Would prefer of course if KernelExplainer would natively deal with pandas dfs.

@ajoules
Copy link

ajoules commented Apr 26, 2021

Hi,

Thank you for the above discussion - I just wanted to agree with Mayer79 as it would be great if one day we could feed the model predictions into Kernel SHAP (instead of the prediction function) as this would allow us to explain models built outside of Python.

Thank you Scott for all of your work on SHAP - the package is a game changer and myself and my colleagues are extremely grateful!

@detrin
Copy link

detrin commented Aug 27, 2023

Since @slundberg made it clear how to work with the KernelExplainer and there is provided gist example from @noleto I think we can close the issue for now @thatlittleboy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants