TL;DR
LIME explains one prediction of any classifier, even one whose inside nobody can read. It perturbs the input many times, asks the black box for each perturbed version, weights the versions by how close they are to the original, and fits a short weighted linear model to those answers. The weights of that small model are the explanation. The authors show it is faithful near the input, and they add submodular pick, a way to choose a few explained predictions that together show how the whole model behaves.
Builds on: Supervised Learning, Lasso Regression, Kernel Function, Weighted Least Squares · Leads to: SHAP
Why it mattered
The paper gave practitioners a model-agnostic tool for asking "why did the model say this?" It was built for text and image classifiers, including a random forest on averaged word2vec embeddings and a deep image network. The authors showed that a single explanation can expose a problem that accuracy hides. In their running example, a text classifier scored 94% held-out accuracy on a subset of the 20 newsgroups data, yet its explanation leaned on words such as "Posting" and "Host", which carry no information about religion. The paper was presented at KDD in August 2016. Its core move, explaining a prediction by fitting something simple near it, is now a standard entry in the interpretability toolkit.
The problem
A model that is accurate on a validation set can still be wrong for the wrong reasons. Validation data can differ from data in the wild. Training data can carry leaked signal, such as an identifier that happens to predict the label. Validation accuracy is therefore not enough on its own. The paper argues that users need two kinds of trust: trust in a single prediction, enough to act on it, and trust in the model as a whole, enough to deploy it.
Existing options were weak for this. Some models are interpretable by design, such as a short Decision Tree or a sparse Logistic Regression, but the paper notes that a supersparse linear model with 5 to 10 features is unsuitable for text. Other methods approximate the whole model globally, which makes them hard to keep accurate near any one input. The paper asks for three properties of an explainer: it must be interpretable to the user, locally faithful to the model near the input, and model-agnostic, so it treats the model as a black box. A fourth goal is a global view, built from several explained predictions.
How it works
Take one tiny instance and trace what LIME does. The numbers in this walkthrough are made up for illustration. They are not from the paper.
flowchart LR A["Instance x: great fun movie"] --> B["Interpretable form x': 1 1 1 (word present)"] B --> C["Sample z' by switching words off"] C --> D["Map back to text and ask the black box f"] D --> E["Weight each sample by closeness to x'"] E --> F["Fit a sparse weighted linear model g"] F --> G["Explanation: the top K word weights"]
-
Start with the instance and the interpretable form. The text is "great fun movie". Its interpretable form is a binary vector with one entry per word:
x' = [1, 1, 1], meaning all three words are present. The classifier itself may use word embeddings or other features that a person cannot read. LIME does not need them to be readable. Check: the vector has three entries because the sentence has three words. -
Ask the black box about perturbed copies. LIME switches off random subsets of the words. Four samples might be:
[1, 1, 1](nothing removed),[1, 0, 1](removes "fun"),[0, 1, 0](removes "great" and "movie"), and[1, 1, 0](removes "movie"). For each one, LIME rebuilds the text and asks the black box for its score. Suppose the scores are 0.90, 0.80, 0.20 and 0.85. Check: each sample gets one score, and the first sample is the original text. -
Weight each sample by how close it is. The closer a sample is to the original, the more it should count. Use the fraction of removed words as the distance
D: 0, 1/3, 2/3 and 1/3 for the four samples. With a width of 0.5, the weight isexp(-D^2 / 0.25), which gives 1.00, 0.64, 0.17 and 0.64. Check: the sample with nothing removed has weight 1, and the sample with two words removed has the smallest weight. ForD = 2/3:D^2 = 0.444, divided by 0.25 is 1.778, andexp(-1.778)is about 0.17. -
Fit a small linear model that is allowed only K words. Find weights
wso that a weighted sum of word presences matches the black box's scores, with each sample counting by its weight. Limit the model toK = 2nonzero weights. Suppose the fit keeps "great" with weight +0.30 and "fun" with weight +0.08, and sets "movie" to zero. Check: the explanation is two numbers, which a person can read. -
Read the explanation. "great" pushes the score up strongly, "fun" a little, and "movie" not at all, within the neighbourhood of this sentence. The samples that keep "great" score 0.80 or more, and the one that removes it scores 0.20, which is why the fit gives "great" the largest weight. That is the answer to "why this score?" It is an answer about this input, not about the model in general, and that limit is the point of the method.
The paper's own runs follow the same steps. Images use super-pixels instead of words: the interpretable form is one bit per super-pixel, and a removed super-pixel is greyed out. The paper's Figure 4 shows this for one prediction of Google's Inception network.
The math
Definition. For a model f, an instance x with interpretable form x', a family G of interpretable models, a
locality weight π_x, a loss L and a complexity measure Ω, the explanation is the model g in G that best
balances fidelity and simplicity:
Here \mathcal{L} says how far g is from f near x, and Ω(g) says how hard g is to read. The paper sets
G to sparse linear models, g(z') = w_g · z'.
Step 1 in symbols: sampling
Draw perturbed interpretable vectors z' by choosing a random number of the nonzero entries of x' and switching them
off. Map each z' back to the original representation z and record the label f(z). The collection \mathcal{Z}
holds the pairs (z', f(z)).
Step 2 in symbols: the locality weight
The weight is an exponential kernel on a distance D:
The distance is cosine distance for text and L2 distance for images, and σ sets the width of the neighbourhood. Samples
near x get a weight near 1, and far samples get a weight near 0. In the walkthrough, D was the fraction of removed
words and σ = 0.5, which gives π = exp(-0.444) ≈ 0.64 for D = 1/3.
Step 3 in symbols: the weighted loss
This is a Weighted Least Squares objective: each squared error counts by its locality weight. Because the weights
fall off with distance, the fit is driven by samples near x, which is what makes the explanation local.
Step 4 in symbols: the sparsity limit
For text, Ω(g) = ∞ when the count of nonzero weights ‖w_g‖_0 exceeds K, and Ω(g) = 0 otherwise. Solving the
full problem with this constraint is intractable. The paper's approximation, called K-LASSO, first selects K features
with a Lasso Regression fit along its Regularization Path, then learns their weights by weighted least squares.
In the walkthrough, that selection kept "great" and "fun".
Step 5 in symbols: submodular pick
To pick B explained instances that cover the model's important features, build an n × d' matrix W where
W_ij = |w_gij| is the importance of feature j in the explanation of instance i. The global importance of feature
j is
The coverage of a set V of instances is the total importance of features that appear in at least one explanation in
V:
Choosing V with |V| ≤ B to maximise coverage is NP-hard, which means no known method solves every case quickly.
Coverage is submodular: each new instance adds no more coverage than the one before it would have. For such functions,
the greedy rule (add the instance with the largest marginal gain at each step) is guaranteed to reach
at least 1 - 1/e, about 63%, of the best possible coverage. The paper's Algorithm 2 does exactly this.
Results
Faithfulness. The authors trained two classifiers that are interpretable by themselves (sparse logistic regression and decision trees), each limited to 10 features per prediction, so the true important features are known. For each test prediction they measured the fraction of true features that the explanation recovers. LIME recovered more than 90% for both classifiers on both datasets (books and DVDs, 2000 instances each, split 1600 for training and 400 for testing). The parzen baseline recovered much less, which the authors attribute to the difficulty of approximating a high-dimensional classifier globally. The greedy baseline was close to parzen on logistic regression but much worse on decision trees.
Simulated trust. When a simulated user has to decide which predictions to trust, LIME gives the highest F1 score on the trustworthy predictions, averaged over 100 runs, for all four black-box models on both datasets. For example, on the books data with logistic regression, LIME scores 96.6, against 84.0 for parzen, 53.7 for greedy and about 14.6 for random. The authors report these differences as significant at p = 0.01.
Model choice. In a setup with 10 artificial noisy features, two random forests had validation accuracy within 0.1% of each other but test accuracy differing by at least 5%. Averaged over 800 runs, a simulated user who saw explanations of the validation instances picked the better forest more often with submodular pick than with random pick, especially when only a few explanations were shown.
Human subjects. On the 20 newsgroups data, a classifier with 94.0% test accuracy was judged against a cleaner one with 88.6%, but the first scored only 57.3% on a separate religion dataset, against 69.0% for the cleaner one. With explanations, Mechanical Turk users with basic religion knowledge chose the better classifier far more often than test accuracy would suggest. Submodular pick improved their choices over random pick, and LIME outperformed greedy. In the feature-engineering round, crowd workers removed words from explanations and the classifier's accuracy on the religion dataset rose across rounds, with each subject taking 3.6 minutes per round, just under 11 minutes in total per classifier. In the husky-versus-wolf task, 27 graduate students saw a model that had learned to look at snow. After the explanations, 3 of 27 still trusted the bad model, down from 10 of 27, and 25 of 27 mentioned snow as a possible feature, up from 12 of 27. The authors call the sample small.
Limits. The explanation is local, so it says nothing about the model far from the input. Its answer depends on the
perturbation scheme, the width σ and the choice of K; the paper's experiments fix K = 10. Explanations can also
miss behaviour that the interpretable representation cannot express, since the explanation is only as rich as the
representation it uses. The human studies use small samples and a tiny set of tasks.
A good explanation is evidence for trust, not a proof of correctness, and an explanation that looks reasonable can still
rest on a feature a reader does not expect.
Reading guide
The paper's sections, in order, and the lessons that each one needs:
- §1 Introduction and §2 The case for explanations: Precision and Recall and Train, Validation and Test Sets for why validation accuracy can mislead, Overfitting for the same issue from the other side.
- §3 LIME, sections 3.1 to 3.4: Euclidean Distance and Cosine Similarity for the locality distances, Kernel Function for the exponential kernel, Weighted Least Squares for the loss, and Lasso Regression with Regularization Path for the K-LASSO step.
- §3.5 and §3.6, the text and image examples: Bag of Words for the text representation, Support Vector Machine for the classifier in the example, and Convolutional Neural Network with Inception Module for the image network.
- §4 Submodular pick: Greedy Algorithm for the selection rule, and NP-hardness for why it is approximated.
- §5 Simulated user experiments: Decision Tree, Logistic Regression, Random Forest and word2vec for the models in the experiments, and Cross-Validation for how their parameters were tuned.
- §6 Human subjects, §7 Related work, §8 Conclusion: no new prerequisites; they apply the ideas above.
Check yourself
QuestionWhy does LIME weight the sampled perturbations by distance from the instance?Show answer
Because the goal is local faithfulness. The fit should match the black box in the neighbourhood of the explained input,
so samples near the input must count more than far ones. The exponential kernel π_x(z) makes far samples count close
to zero, so the small linear model is shaped by the region that matters for this prediction.
QuestionIn the walkthrough, the four weights are 1.00, 0.64, 0.17 and 0.64, and the scores are 0.90, 0.80, 0.20 and 0.85. Which sample has the biggest say in the fit, and why?Show answer
The sample with weight 1.00, the original sentence with nothing removed. Its score of 0.90 is the most trusted point in the neighbourhood. The weights multiply each squared error in the loss, so this sample's error counts the most.
QuestionCompute the weight for a sample with D = 1/3 and σ = 0.5. Give the number to two decimal places.Show answer
Square the distance to get 1/9, about 0.111. Divide by 0.25 to get about 0.444. Apply the exponential:
exp(-0.444), about 0.64. The weight is 0.64.
QuestionWhy did the authors use submodular pick instead of picking instances at random, and what guarantee does the greedy rule give?Show answer
Random picks can show the same features again and again, while a few important features go unseen. Submodular pick
scores a set by the total importance of the features it covers, so each new instance must add new coverage. The problem
is NP-hard, but the greedy rule, which adds the instance with the largest marginal gain each time, achieves at least
1 - 1/e, about 63%, of the best possible coverage.
QuestionA doctor sees a LIME explanation for one patient's prediction and wants to know if the model is safe for all patients. What should they conclude?Show answer
The explanation describes the model's local behaviour near that one patient, not its behaviour across the population. It cannot establish that the model is safe. It can show a warning sign, such as a feature that should not matter, and that warning should prompt checks on held-out data. This is educational content about how explanations work, not medical advice.
Sources
- Ribeiro, Singh and Guestrin, "Why Should I Trust You?": Explaining the Predictions of Any Classifier, arXiv https://arxiv.org/abs/1602.04938
- Ribeiro, Singh and Guestrin, KDD 2016, DOI 10.1145/2939672.2939778