- Introduced by
- Marco Ribeiro, Sameer Singh & Carlos Guestrin
- Year
- 2016
- Type
- post-hoc local explanation
- Family
- Explainable AI
What does it do?
LIME, introduced by Ribeiro, Singh, and Guestrin in 2016, explains an individual prediction of any black-box classifier by fitting a simple surrogate model in the neighbourhood of that one prediction.
It does not attempt to describe the global model. Its purpose is to make the reasons for a specific output legible to end-users, domain experts, and auditors, even when the underlying model is a deep neural network or an ensemble.
The intuition behind the method
Suppose a credit-scoring model rejects a loan application and you want to know why. LIME creates many slightly altered copies of that application, records how the black-box score changes for each copy, and then fits a simple weighted linear model to these records. Copies that resemble the original count more than distant ones. Features with large coefficients in the fitted model are the main local drivers of the decision. The result describes the model's behaviour around this one application, not across all possible applications.
History
LIME was presented in 2016 by Marco Tulio Ribeiro, Sameer Singh, and Carlos Guestrin in the ACM SIGKDD paper "Why Should I Trust You?": Explaining the predictions of any classifier. The paper frames explanation as a means of assessing whether a single prediction can be trusted, and it proposes a local surrogate model as the explanation for that prediction.
When to use it
Choose LIME when you need instance-level explanations of a model you cannot inspect or modify, such as a neural network, a boosted ensemble, or a remote prediction API, and you can query the model for predictions. It is applicable to tabular, text, and image inputs. The method assumes that the model behaves approximately linearly within the sampled neighbourhood, so it is more appropriate when local behaviour is reasonably smooth. Avoid relying on LIME alone when you need a stable attribution across repeated runs, when features are strongly correlated and perturbation would create unrealistic inputs, when the feature space is very high-dimensional, or when you need a global account of model behaviour. In those cases, SHAP (which rests on Shapley values from cooperative game theory, see the FAQ, and whose per-instance attributions can be combined across a dataset) or counterfactual explanations (for contrastive reasoning) are alternatives to consider.
Limitations and considerations
- Local validity only: the surrogate describes the model near the explained instance and need not reflect its behaviour in other regions of the input space.
- Run-to-run variability: the neighbourhood is generated by random sampling, so changing the random seed or the number of samples can alter the selected features and their coefficients.
- Dependence on sigma: the kernel width determines which samples dominate the fit, and the method does not prescribe a single principled way to choose it.
- Out-of-distribution neighbours: perturbed samples can fall in regions where the black box was never trained, so the fidelity of the surrogate there may not reflect the model's behaviour on realistic inputs.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Model-agnostic: it needs only the ability to query the black box for predictions, so the model's internals and training procedure can remain unchanged.
- Instance-level output: each explanation is fitted to one prediction, so it reflects the features that mattered for that case rather than an average over the dataset.
- Sparse, readable output: restricting the surrogate to K features yields a short list of signed coefficients that non-specialists can read.
- Common interface across modalities: the same framework produces explanations for tabular features, word presence in text, and superpixel regions in images.
Applications
- Medical decision support: showing which recorded clinical features contributed to a model's high-risk flag for a particular patient, so that a clinician can review the basis for it.
- Credit decisions: listing the main feature-level reasons behind an opaque scoring model's approval or denial of a specific application.
- Text classification: highlighting which words in a single review or document were switched on in the perturbed samples that most changed the classifier's output.
- Image classification: producing superpixel-level masks that indicate which image regions most affected a model's predicted class for one image.
- Fraud alert review: identifying which transaction features drove an ensemble model's alert for a given transaction, to support analyst review.
How it works
How it works
LIME generates a synthetic neighbourhood around the instance by perturbing its interpretable representation x'. For tabular data, feature values are resampled around the instance; for text, words are switched on or off; for images, superpixels are switched on or off. Each perturbed sample z' is a binary or simple numeric vector in the interpretable space, and it is mapped back to the original input space before the black box is queried.
Formula
z' \sim \mathcal{Z}(x'),\quad \text{sample } z \in \mathbb{R}^d \text{ near } x'Each perturbed sample is weighted by pi_x'(z) = exp(-D(x,z)^2 / sigma^2), so its weight decays with distance D from the explained instance. The kernel width sigma sets how quickly that decay happens. Samples close to the instance dominate the fit, which focuses the surrogate on fidelity in the immediate neighbourhood of the prediction being explained.
Formula
\pi_{x'}(z) = \exp\!\left(-\frac{D(x,z)^2}{\sigma^2}\right)A simple, interpretable model g from the class G is fitted to the weighted neighbourhood samples, with the black-box output f as the target. The penalty Omega(g) restricts the complexity of g so that only a small number of features are active. The minimisation trades off weighted fidelity to f against this complexity penalty.
Formula
\xi(x) = \arg\min_{g\,\in\,G}\; \mathcal{L}(f,\,g,\,\pi_{x'}) + \Omega(g)The fitted surrogate gives coefficients beta_j for the K retained features. Each coefficient indicates the direction and approximate size of a feature's influence on the output being explained, such as a predicted value or a class probability, within the local neighbourhood. The explanation is therefore only valid near x'. Because the surrogate is fitted by minimising a proximity-weighted loss against the black-box output, its weighted fit to the model's outputs in the neighbourhood indicates how faithfully it reproduces the model there. When that local fit is poor, the coefficients should not be read as a reliable account of the model's behaviour. Stability should also be checked: rerun the explanation with different random seeds and sample counts, and treat large changes in the selected features or their coefficients as a sign that the explanation is not yet dependable.
Formula
\hat{y} = g(z') = \beta_0 + \sum_{j=1}^{K} \beta_j z'_j,\quad K \ll dCommon pitfalls
- Treating coefficients as global importances: they describe the local neighbourhood of one prediction, and extrapolating them to the whole data distribution is not supported by the method.
- Ignoring feature dependence: in its tabular mode, LIME perturbs features independently of one another, which can create implausible combinations when features are strongly correlated and distort the local explanation.
- Equating explanation with correctness: a faithful local surrogate shows what the model did for an instance; it does not establish that the prediction is correct or fair.
- Setting the number of explanation features too high: a large K may improve the surrogate's fit but produces an explanation too long for a human reader, which undermines the purpose of the sparse model.
Frequently asked questions
How is LIME different from SHAP?
Both methods explain individual predictions of black-box models, but they rest on different foundations. SHAP values are defined through Shapley values from cooperative game theory, which give them a unique axiomatic characterisation. LIME is a heuristic local fit whose result depends on the random perturbation sample, so repeated runs can differ. For a given problem, the choice depends on whether a theoretically grounded attribution or a flexible local surrogate better suits the analysis.
How many perturbed samples are needed for a reliable LIME explanation?
The sample count is a user-set parameter, and no fixed number is guaranteed to suffice. Highly non-linear decision boundaries or high-dimensional feature spaces can require more samples before the coefficients stabilise. A practical check is to rerun the explanation with different random seeds and sample counts, and to increase the number of samples if the selected features or their coefficients change substantially between runs.
Can LIME explain regression models as well as classifiers?
The original paper frames LIME as a way to explain the predictions of classifiers. The procedure itself only needs the black-box output to approximate near the instance, so it can in principle be applied to a continuous predicted value by fitting the same locally weighted linear surrogate, and the coefficients would then indicate which features most strongly influence that value in the local neighbourhood. Regression use is therefore an extension of the original framing rather than the setting the source establishes. Check the documentation of the implementation you use, and validate the explanations for your own regression model before relying on them.
Related methods
Sources
Ribeiro, M. T., Singh, S., & Guestrin, C. (2016). "Why should I trust you?": Explaining the predictions of any classifier. ACM SIGKDD, 1135–1144.
Open DOI reference