Course contentsShow
← Machine Learning and Deep Learning
Lesson 3227 of 3,53870. Interpretability: Feature-Based MethodsFree lesson

LIME for Image Classification

Using superpixel segmentation and perturbations to explain which image regions drive predictions.

LIME for Image Classification

What You'll Learn

You'll learn how LIME uses superpixel segmentation and perturbations to reveal which regions of an image drive a model's classification decision.

Why Images Need Special Treatment

Unlike tabular data where you perturb individual features, images have thousands of pixels. Perturbing single pixels would be inefficient and wouldn't capture meaningful visual regions. LIME solves this by grouping neighboring pixels into superpixels—coherent patches that represent objects or parts of objects.

The Superpixel Approach

A superpixel segmentation algorithm (like SLIC or Quickshift) divides your image into ~50-300 interpretable regions. These become your "features" for LIME. For a cat vs. dog classifier, superpixels might capture the ears, eyes, nose, or background.

How LIME Explains Image Predictions

  1. Segment: Break the image into superpixels
  2. Perturb: Generate variations by randomly turning superpixels "off" (masking them with gray or noise)
  3. Predict: Run each perturbed image through your classifier
  4. Weight: Assign higher weights to perturbations closer to the original (more superpixels present)
  5. Fit: Train a linear model on these weighted samples to identify which superpixels most influence the prediction
  6. Visualize: Highlight top positive superpixels (green) and negative ones (red)

The Result

You get a heatmap showing which image regions the model "looked at" to make its decision. If your dog classifier highlights the ears and snout, that's reassuring. If it highlights the grass background, you've found a problem.

Key Takeaway: LIME for images transforms the pixel space into interpretable superpixel features, then uses perturbation-based local approximation to explain which visual regions drove the model's prediction.