skip to content

When choosing between the lime and shap packages to explain individual predictions of a production model, which conditions decide the choice?

level: seniorimportance: must knowfreq 28%

answer

  1. start from the model, not the brand
  2. trees have an exact path
  3. numbers that add up, or a fit score
  4. model calls per explained row
  5. last release 2020 against 2026

basics

~20 s

The conditions decide, not the brand: a tree ensemble shap can read gets exact, additive attributions without sampling; a black box means sampling in either package; lime gives readable bin conditions without additivity, and its last release was in 2020.

solid answer

~50 s

Neither wins by default. **Model family**: shap's `TreeExplainer` is documented as fast and exact for tree ensembles and checks that the attributions plus the expected value equal the output, while lime always samples, `num_samples=5000` predictions per row by default. **Black box behind a predict function**: both work and both pay in model calls; lime needs training data to build perturbations, shap a background dataset. **Additivity**: shap attributions plus the base value add up to the model output; lime's weights are coefficients of a ridge surrogate whose fit is reported by `score`, with no sum constraint. **Audience**: lime's binned conditions (`lead_time > 120.00`) read easily; shap gives a contribution per feature value. **Maintenance**: lime 0.2.0.1 (June 2020) is the last release and master's last commit is from July 2021, though the repository is not archived; shap released 0.52.0 in May 2026.

go deeper

for a junior

Recall the headline contrasts: lime fits a local linear surrogate by sampling, shap's tree explainer is exact for tree ensembles, and shap attributions add up to the output.

for a middle

Explain the cost on each side: lime's 5,000 predictions per row by default against shap's tree-structure path, and that shap's model-agnostic explainers also need a background dataset.

for a senior

Show the decision for a stated model and audience: model family, additivity, readability, cost arithmetic and the frozen dependency, ending with what would reverse the choice.

for a principal

Own the policy: whether production explanation paths keep a 2020-era dependency, who maintains it, and how explanations stay comparable if the tool changes.

## Start from the conditions, not the package "LIME or SHAP?" comes up in most explainability interviews, and the weak answer names a favourite. The strong answer lists the conditions that decide it and shows which way each one points. Both packages explain one prediction at a time, and both can treat the model as a function; they differ in what they compute, what the numbers promise, what they cost and how they are maintained. ## The deciding conditions | Condition | lime 0.2.0.1 | shap | |---|---|---| | Model access | a prediction function, plus training data to build perturbations | a prediction function plus a background dataset, or the model object itself for supported families | | Tree ensembles | no special path; always samples | `TreeExplainer`, documented as a fast and exact algorithm for tree ensembles | | What a number means | coefficient of a weighted ridge surrogate over binary conditions | a contribution that, with the base value, adds up to the model output | | Built-in check | `exp.score` (weighted R²) and `exp.local_pred` | `TreeExplainer` checks additivity by default (`check_additivity=True`) | | Text and images | word and superpixel explainers | its own maskers and explainers for text and images | | Releases | last release June 2020 | 0.52.0 in May 2026, a 0.53.0 release candidate in September 2026 | ## Model family and cost **A tree ensemble that shap can read.** For gradient-boosted trees (scikit-learn's histogram gradient boosting is among the model types `TreeExplainer` reads), shap computes attributions from the tree structure instead of sampling, and its additivity check raises an error when the result does not add up. lime has no such path: each explanation samples, by default 5,000 perturbed rows sent to `predict_proba`. For an airline scoring 10,000 bookings a night that is 10,000 × 5,000 = **50 million** model predictions plus a surrogate fit per row, and the result still depends on the random draw, fixed only through `random_state`. **A black box behind a predict function.** Here both packages sample, and the comparison turns on settings rather than names: - lime needs the training data to build perturbations, and spends `num_samples` predictions per row; - shap's model-agnostic explainers need a background dataset and also evaluate the model many times per row; - sampled results move with the random draw unless a seed is fixed, so either way the job should record its settings. ## What the numbers promise - shap attributions satisfy **local additivity**: the base value plus the row's attributions equals the model's output on the explained scale, so a reader can reconcile the explanation with the score. - lime's weights are the coefficients of a local linear fit. They need not sum to anything; how well the fit matched the model is a separate number, `exp.score`, with the surrogate's own prediction in `exp.local_pred`. - lime's default discretisation produces conditions such as `lead_time > 120.00` that an analyst can read without knowing the feature's scale; shap reports a contribution for each feature's actual value. Why the Shapley construction yields additivity, and when any local explanation is faithful to its model, are theory questions answered elsewhere; the package choice needs only the property. ## Maintenance as a fact The lime package's last PyPI release is 0.2.0.1, from 26 June 2020. The repository's master branch had its last commit on 29 July 2021 and carries arguments the release lacks. The repository is not archived. The release declares Python 3.5 or newer and leaves its dependencies (numpy, scipy, scikit-learn, scikit-image, matplotlib, tqdm) unpinned, with only old minimums on scikit-learn and scikit-image, so it runs against whatever versions the environment resolves. shap is actively released. Neither fact decides the choice alone, but a team adopting lime adopts a frozen dependency it may have to patch itself. ## A decision procedure 1. **Identify the model family.** A supported tree ensemble points to shap's exact path; a black box puts both packages on sampling. 2. **Ask whether attributions must reconcile with the prediction.** If reviewers will add them up, additivity matters. 3. **Ask who reads the result.** Binned conditions may suit analysts; per-feature contributions suit reviewers comparing rows. 4. **Do the cost arithmetic** on both sides: rows per night times model calls per row. 5. **Check the dependency budget.** Can the team carry a package with no release since 2020? 6. **Pilot both on a sample** against what the readers need, then record the decision. A good answer ends with a choice for the stated conditions, and names the condition that would reverse it.

  • How does the lime-or-shap choice change for a text classifier instead of a tree ensemble?
    The exact tree path disappears: both packages explain text through a prediction function over strings, lime's `LimeTextExplainer` by removing words and shap through a text masker. The choice then rests on cost per document, whether attributions must add up to the output, how readers want words highlighted, and whether the team can carry lime's frozen release.
  • How do you state lime's maintenance status in a design review without overstating it?
    Give the dates: last PyPI release 0.2.0.1 on 26 June 2020, last master commit on 29 July 2021, repository not archived as of October 2026. Then state the consequence: no upstream fixes are coming, so the team pins versions, tests lime against its own numpy and scikit-learn upgrades, and owns any patch.

  • SHAP is always the better choice because it is newer.
  • LIME weights add up to the predicted probability.
  • LIME is cheap because it needs only predict_proba.
  • shap has to sample even for tree ensembles.
  • lime's repository is archived, so it cannot be installed.

Assumes lime 0.2.0.1 (last release, June 2020) and shap 0.52.0 (May 2026); the maintenance comparison changes if either package ships a new release.