LIME: Local Interpretable Model-agnostic Explanations
Intuition
A complex model may be curved globally but almost linear in a small neighbourhood of one input. LIME samples variations of the instance, asks the model about them, and fits a simple linear model that is accurate near the instance.
Precise explanation (Ribeiro et al., 2016, tabular variant used here)
- Interpretable representation: binary masks ; keeps , replaces it with the baseline value. Input for mask z: .
- Sample masks (always include the all-ones mask = the instance itself).
- Proximity weights: with distance (fraction of features removed), , σ = kernel width.
- Weighted least squares: fit minimising : solve with rows scaled by . The coefficient estimates the effect of including feature j. For a linear model , LIME recovers exactly (same as XA-01/XA-11).
Worked example
f(x) = 2x₀ − x₁, x = (3, 1), baseline 0 → β = [6, −1], β₀ = 0, for any set of masks that spans the space.
Common mistakes
- Fitting on raw perturbed features instead of the binary masks (changes what β means).
- Forgetting the weights (fits a global, not local, model).
- Too few samples → unstable explanations (re-run with other seeds to check).
Why this matters
LIME is a widely used model-agnostic local explainer; implementing it shows exactly which design choices (baseline, kernel width, sampling) affect explanations.
References
- "Why Should I Trust You?": Explaining the Predictions of Any Classifier — Marco Tulio Ribeiro, Sameer Singh, Carlos Guestrin (
S025) - Interpretable Machine Learning (3rd edition) — Christoph Molnar (
S024)