bgreenwell / fastshap

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

Question, not issue SHAP Values or shapley values? #25

Closed trilliumtechnical closed 1 year ago

trilliumtechnical commented 2 years ago

Maybe I am just very confused: Does this package calculate shapley values or SHAP values? In the book Interpretable Machine Learning, a distinction is made between shapley values and SHAP values. My interpretation of the documentation and this issue (Shap values don't add up to prediction values ) is that SHAP values are calculated if exact = TRUE (I am using xgboost). Thanks for a great package.

bgreenwell commented 2 years ago

Hi @trilliumtechnical, I wouldn't get too hung up on the terminology. This package computes Shapley values using a Monte Carlo approach (this is equivalent to the approach taken by several R packages, and also the sampling shap explainer in the Python shap package); the code used here is just a more efficient implementation by comparison. SHAP provides an alternative view of Shapley explanations that connects several algorithms together in the same framework, including LIME. Within SHAP, there are several approaches to computing Shapley values, such as the one used in this package. SHAP also includes Kernal SHAP (an approximation of Shapley values using kernels) and Tree SHAP (an efficient procedure for obtaining Shapley values from tree-based models). XGBoost, for example, implements Tree SHAP.

The approximate Shapley estimation procedures, like sample SHAP (this package) and Kernel SHAP, result in feature contributions that don't satisfy the additive property (i.e., that the Shapley explanations sum to the difference between the prediction you're trying to explain, and the average prediction across the entire learning sample/training data). This package borrows the same "correction" (turn on by setting adjust=TRUE) used by the shap package for Kernel SHAP so that the additive property is satisfied.

When exact=TRUE, fastshap simply uses the exact Tree SHAP procedure already available in XGBoost and LightGBM (or an additive linear model), as opposed to the approximate Monte Carlo approach used for all other models.

Does that help answer your question(s)?

bgreenwell commented 2 years ago

We are in the process of writing a paper that will hopefully bring more clarity to the landscape of R packages and Shapley value algorithms they implement: https://github.com/bgreenwell/rjournal-shapley.

trilliumtechnical commented 2 years ago

Thanks for your response. I am still trying to digest it and I will read your paper soon.