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)

  1. Interpretable representation: binary masks z∈{0,1}dz \in \{0,1\}^d; zj=1z_j = 1 keeps xjx_j, zj=0z_j = 0 replaces it with the baseline value. Input for mask z: x(z)=z⊙x+(1−z)⊙x′x(z) = z\odot x + (1-z)\odot x'.
  2. Sample masks (always include the all-ones mask = the instance itself).
  3. Proximity weights: with distance D(z)=1−1d∑jzjD(z) = 1 - \frac{1}{d}\sum_j z_j (fraction of features removed), π(z)=exp⁡(−D2/σ2)\pi(z) = \exp(-D^2/\sigma^2), σ = kernel width.
  4. Weighted least squares: fit g(z)=β0+β⋅zg(z) = \beta_0 + \beta\cdot z minimising ∑π(z)(f(x(z))−g(z))2\sum \pi(z)(f(x(z)) - g(z))^2: solve with rows scaled by π\sqrt{\pi}. The coefficient βj\beta_j estimates the effect of including feature j. For a linear model ff, LIME recovers βj=wj(xj−xj′)\beta_j = w_j(x_j - x'_j) 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