LIME (Local Interpretable Model-agnostic Explanations)

1) What it is

  • LIME = technique to explain individual predictions of any ML model.
  • Stands for Local Interpretable Model-agnostic Explanations.
  • Idea: Instead of explaining the whole black-box model, approximate it locally around the instance of interest with a simpler interpretable model (like linear regression).

LIME answers: “Why did the model predict THIS for THIS example?”


2) How it works (step by step)

  1. Take the instance you want to explain (e.g., a loan application).
  2. Create perturbed samples by slightly modifying the input features.
  3. Get predictions from the black-box model for these samples.
  4. Weight samples by proximity to the original instance (closer samples matter more).
  5. Fit a simple, interpretable model (like linear regression or decision tree) on this local neighborhood.
  6. Use the coefficients of this simple model to explain which features contributed most.

3) Example

Model predicts: Loan denied

  • LIME perturbs features like income, age, debt ratio.
  • Black-box predictions on these perturbed points are collected.
  • Local linear model shows:
    • Income (-0.4 contribution)
    • High debt (+0.3 contribution)
    • Employment length (+0.1 contribution)

Explanation: Low income + high debt pushed decision toward denial.


4) Strengths of LIME

Model-agnostic → works with any classifier/regressor.
Local focus → explains one prediction at a time.
Human-friendly → produces simple feature-weight explanations.


5) Limitations

Instability: Explanations can change if you perturb data differently.
Local approximation only: Doesn’t guarantee global faithfulness.
Computationally expensive: Requires many perturbations.
Correlated features: Hard to interpret weights when features interact.


6) Python Example

import lime
import lime.lime_tabular
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier

X, y = load_iris(return_X_y=True)
model = RandomForestClassifier().fit(X, y)

explainer = lime.lime_tabular.LimeTabularExplainer(X, feature_names=["f1","f2","f3","f4"], class_names=["setosa","versicolor","virginica"], discretize_continuous=True)

i = 0
exp = explainer.explain_instance(X[i], model.predict_proba, num_features=2)
exp.show_in_notebook()

7) LIME vs SHAP (quick compare)

AspectLIMESHAP
FoundationLocal surrogate modelsGame theory (Shapley values)
ScopeLocal explanations onlyLocal + global consistency
StabilityLess stable (random perturbations)More stable (theoretically grounded)
SpeedFaster for small datasetsCan be slower (esp. exact SHAP)
InterpretabilitySimple linear explanationsAdditive contributions, exact decomposition

Summary

  • LIME = explains black-box predictions by approximating the model locally with a simple surrogate.
  • Useful for instance-level interpretability.
  • Pros: simple, flexible, model-agnostic.
  • Cons: unstable, only local, approximation may not reflect true model logic.

Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.