Explainable AI (XAI) Intermediate 12 minutes

LIME: Local Surrogate Explanations

Approximating the model's behaviour around a single example with a simple linear model, and the reasons for its instability.

Your progress in the track0%

The algorithm

  1. Choose the example \(x\).
  2. Generate perturbed samples \(z_1, \dots, z_N\) around it.
  3. Get \(f(z_i)\) from the original model.
  4. Give each sample a weight \(\pi_x(z_i)\) that decreases with distance from \(x\).
  5. Train a linear model \(g\) on the interpretable features with the weights.

$$\xi(x) = \arg\min_{g \in G} \; \mathcal{L}(f, g, \pi_x) + \Omega(g)$$

where \(\Omega\) is the complexity of the explanation, such as the number of features.

A tabular example

# pip install lime
from lime.lime_tabular import LimeTabularExplainer
explainer = LimeTabularExplainer(X_tr.values, feature_names=list(X.columns),
                                 class_names=["malignant", "benign"], discretize_continuous=True,
                                 random_state=0)
exp = explainer.explain_instance(X_te.values[0], rf.predict_proba, num_features=6, num_samples=5000)
print(exp.as_list())

(The example assumes rf andX_tr andX_te from the feature importance lesson.)

Images and texts

  • Text: removing words at random; the explanation highlights the influential words.
  • Images: splitting the image into superpixels and hiding some of them.

Limits

The problemDetail
InstabilityDifferent results between runs
Defining the neighbourhoodThe choice of kernel width changes the explanation
Unrealistic samplesPerturbing features independently produces out-of-distribution examples
Can be fooledA model can be built that behaves differently on perturbed samples and so hides its bias

Use LIME as an initial exploration tool, and do not rely on it alone for an important decision.

Lesson terms

Superpixels
Homogeneous regions of an image used as units of explanation instead of individual pixels.
Local surrogate model
A simple model trained to imitate the behaviour of the complex model in the neighbourhood of a specific example.

Abstract

LIME generates perturbed samples around the example to be explained, gets the model's predictions for them, then trains a simple linear model weighted by closeness to the example. The coefficients of this model are the explanation. It works with tabular data, texts and images (through superpixel regions). Its drawbacks: the results depend on the perturbation method, the kernel width and the number of samples, explanations may differ between two runs, and it has been shown that it can be fooled by models designed to do so.

Review questions

  1. What determines the "neighbourhood" in LIME?

    The method for generating perturbed samples, and the kernel function and its width, which give more weight to nearby samples.

  2. How do we check the stability of a LIME explanation?

    We repeat the explanation with different seeds and more samples and compare the top features.

Sources and references

  1. Ribeiro, Singh & Guestrin (2016) — "Why Should I Trust You?" Explaining the Predictions of Any Classifier
  2. LIME GitHub Repository
  3. Slack et al. (2020) — Fooling LIME and SHAP

Complete the lesson