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

Weighted Sampling for Local Neighborhoods

Understanding exponential kernel weighting to focus on samples close to the instance being explained.

Weighted Sampling for Local Neighborhoods

What you'll learn: How LIME uses exponential kernel weighting to emphasize nearby samples when building local explanations.

The Core Problem

When LIME generates perturbed samples around an instance you want to explain, not all perturbations are equally useful. Samples very far from your original instance don't reveal much about local model behavior—they're exploring a different region of the feature space entirely.

Exponential Kernel Weighting

LIME solves this by assigning weights to perturbed samples based on their proximity to the instance being explained. The closer a perturbed sample is to the original, the higher its weight in training the local surrogate model.

The exponential kernel is commonly used:

weight = exp(-distance² / kernel_width²)

Think of it like a spotlight: the instance you're explaining sits at the center under bright light, while samples farther away fade into darkness. When fitting the interpretable model (like linear regression), heavily weighted samples have more influence—LIME learns to approximate the black-box model where it matters most.

Why This Matters

Without weighting, LIME might fit a local model that explains behavior across a broad, irrelevant region. With proper weighting:

  • The explanation focuses on the decision boundary near your instance
  • The surrogate model accurately captures local behavior
  • You get explanations that are truly local, not semi-global

The kernel_width parameter controls how quickly weights decay—narrow kernels create very localized explanations, while wider kernels incorporate more distant samples.

Key Takeaway: Exponential kernel weighting ensures LIME's local surrogate model prioritizes samples close to the instance being explained, making explanations genuinely local and faithful to nearby model behavior.