datarekha
Machine Learning Medium Asked at AirbnbAsked at UberAsked at GoogleAsked at MicrosoftAsked at LinkedIn

What is the difference between SHAP and LIME for model interpretability?

The short answer

SHAP assigns each feature a contribution value based on Shapley values from cooperative game theory, providing globally consistent and locally accurate explanations with a solid theoretical foundation. LIME approximates the model locally around a single prediction using a simpler interpretable model, which is fast but can produce inconsistent explanations across similar inputs.

How to think about it

Both SHAP and LIME answer “why did the model predict this?” for a single instance, but they use fundamentally different mechanisms and have different reliability guarantees.

SHAP (SHapley Additive exPlanations)

SHAP computes the Shapley value of each feature: the average marginal contribution of that feature across all possible subsets of features. This comes from cooperative game theory — features are “players” and the model output is the “payout.”

Key properties:

  • Efficiency: contributions sum to the prediction (minus the base rate). No “missing” explanation.
  • Consistency: if a model changes so that a feature contributes more, its SHAP value cannot decrease.
  • Local accuracy: the linear explanation matches the model output exactly for each instance.

TreeSHAP computes exact Shapley values for tree-based models in O(TLD²) time, making it practical for XGBoost/LightGBM/Random Forests. For neural nets, use KernelSHAP or DeepSHAP.

LIME (Local Interpretable Model-agnostic Explanations)

LIME perturbs the input around the instance of interest, queries the black-box model on the perturbed samples, and fits a simple linear model weighted by proximity to the original point. The linear model’s coefficients are the “explanation.”

Key properties:

  • Model-agnostic: works on any model with a predict function.
  • Fast and flexible: easy to apply to text and images with custom perturbation strategies.
  • No theoretical guarantee of consistency: different random seeds or perturbation strategies can produce noticeably different explanations for the same input.

Head-to-head

PropertySHAPLIME
TheoryShapley (game theory)Local linear approximation
ConsistencyGuaranteedNot guaranteed
Global explanationsYes (aggregate over dataset)Not directly
SpeedFast for trees; slow for othersFast for most models
Handles correlated featuresImperfectlyImperfectly
import shap

explainer = shap.TreeExplainer(model)           # fast exact for tree models
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values, X_test)          # global feature importance

# Single prediction waterfall
shap.waterfall_plot(shap.Explanation(
    values=shap_values[0],
    base_values=explainer.expected_value,
    data=X_test.iloc[0],
))
Learn it properly Interpretability: SHAP vs LIME

Keep practising

All Machine Learning questions

Explore further

Skip to content