Inferensys

Glossary

Kernel Width

A hyperparameter controlling the effective size of the local neighborhood by determining how quickly sample weights decay with distance from the original instance, balancing local fidelity and explanation stability.
Control room desk with laptops and a large orchestration network display.
LOCALITY HYPERPARAMETER

What is Kernel Width?

Kernel width is a hyperparameter in Local Interpretable Model-agnostic Explanations (LIME) that controls the effective size of the local neighborhood by determining how quickly sample weights decay with distance from the original instance.

Kernel width is the scaling parameter of the exponential kernel function that defines the locality of a LIME explanation. It governs the radius of the neighborhood around the instance being explained, assigning a weight of 1.0 to the original instance and exponentially smaller weights to perturbed samples as their distance increases. A smaller kernel width enforces strict locality, fitting the surrogate model to only the most similar samples, while a larger width smooths the explanation over a broader region of the local decision boundary.

Selecting the optimal kernel width involves balancing the fidelity-interpretability trade-off. An excessively narrow width can produce unstable, high-variance explanations that change dramatically across runs due to insufficient sampling density. Conversely, an overly wide kernel violates the locality assumption, causing the linear surrogate to approximate a non-linear decision surface poorly and reducing local fidelity. Frameworks like OptiLIME automate this selection by optimizing for explanation stability while maintaining predictive accuracy.

Local Fidelity Control

Key Characteristics of Kernel Width

The kernel width hyperparameter defines the effective radius of the local neighborhood in LIME, directly controlling the bias-variance trade-off between explanation stability and fidelity to the black-box model's decision boundary.

01

Neighborhood Radius Definition

Kernel width determines how quickly sample weights decay with cosine distance or Euclidean distance from the original instance. A small kernel width creates a tight, highly local neighborhood where only very similar perturbed samples receive significant weight. A large kernel width flattens the weighting function, allowing more distant samples to influence the surrogate model training. This parameter effectively defines what 'local' means for a specific explanation, controlling the scope of the local decision boundary being approximated.

02

Fidelity-Interpretability Trade-off

Kernel width directly mediates the fidelity-interpretability trade-off in local explanations:

  • Narrow kernel: Captures highly local, non-linear decision boundaries with greater precision but produces unstable explanations sensitive to sampling noise
  • Wide kernel: Produces smoother, more stable explanations that approximate global behavior but may miss critical local variations
  • Optimal selection: Requires balancing the complexity of the underlying model's decision surface against the need for reproducible explanations The choice fundamentally determines whether the explanation captures genuine local structure or averages over a broader region.
03

Exponential Kernel Function

LIME employs an exponential kernel to convert distances into sample weights: weight = exp(-D(x, z)² / σ²), where σ (sigma) is the kernel width and D(x, z) is the distance between the original instance and a perturbed sample. This function ensures:

  • Samples identical to the original receive maximum weight of 1.0
  • Weights decay smoothly and exponentially with increasing distance
  • The rate of decay is controlled entirely by the kernel width parameter
  • Very distant samples receive near-zero weight, effectively excluding them from surrogate model training
04

Explanation Stability Control

Kernel width is the primary control for explanation stability across multiple runs with different random seeds. A kernel that is too narrow causes the explanation to overfit to the specific random perturbation samples generated in each run, producing inconsistent feature importance rankings. A kernel that is too wide produces stable but potentially misleading explanations that fail to capture local nuances. OptiLIME addresses this by automatically selecting the kernel width that maximizes stability while maintaining a minimum fidelity threshold, ensuring reproducible explanations.

05

Modality-Specific Tuning

Optimal kernel width varies significantly by data modality and feature representation:

  • Text data: Typically uses larger kernel widths due to the high-dimensional, sparse nature of TF-IDF or embedding representations where cosine distances can be large
  • Image data: Requires careful tuning against superpixel segmentation granularity, as the distance between superpixel masks affects neighborhood density
  • Tabular data: Depends on feature scaling and the density of the perturbation sampling strategy around the instance
  • Categorical features: May require specialized distance metrics that account for non-numeric feature spaces
06

Bayesian Uncertainty Integration

Bayesian LIME extends kernel width selection by incorporating uncertainty quantification. Rather than using a fixed kernel width, Bayesian approaches treat it as a random variable with a prior distribution, allowing the explanation to express confidence intervals around feature importance scores. This integration reveals when the chosen kernel width may be inappropriate—wide confidence intervals suggest the explanation is sensitive to the kernel width choice, indicating potential instability in the local approximation that practitioners should investigate before trusting the explanation.

LOCALITY PARAMETER COMPARISON

Small vs. Large Kernel Width

Trade-offs between narrow and wide kernel width settings in LIME explanations, controlling how quickly sample weights decay with distance from the target instance.

CharacteristicSmall Kernel WidthMedium Kernel WidthLarge Kernel Width

Locality Scope

Highly local

Moderately local

Near-global

Sample Weight Decay

Rapid (steep drop-off)

Gradual

Very slow (flat weights)

Local Fidelity

High (tight fit)

Balanced

Low (blurred fit)

Explanation Stability

Low (high variance)

Moderate

High (low variance)

Sensitivity to Noise

High

Moderate

Low

Risk of Overfitting

High

Moderate

Low

Risk of Underfitting

Low

Moderate

High

Decision Boundary Approximation

Captures fine local curvature

Balanced approximation

Captures only broad trends

Typical Use Case

Debugging a single anomalous prediction

General-purpose explanation

Understanding regional model behavior

Distance Metric Impact

Highly sensitive

Moderately sensitive

Minimally sensitive

Surrogate Model Complexity Required

Simpler model sufficient

Moderate complexity

More complex model may be needed

Equivalent Kernel Shape

Narrow Gaussian

Moderate Gaussian

Wide, near-uniform Gaussian

KERNEL WIDTH CLARIFIED

Frequently Asked Questions

Precise answers to the most common technical questions about the kernel width hyperparameter in Local Interpretable Model-agnostic Explanations (LIME), covering its role in defining locality, its impact on explanation stability, and practical tuning strategies.

Kernel width is a hyperparameter that controls the effective radius of the local neighborhood around the instance being explained by determining how quickly sample weights decay with distance. In the LIME framework, an exponential kernel (often a Radial Basis Function or RBF kernel) is applied to the perturbed samples: $weight = \exp(-\frac{distance^2}{kernel_width^2})$. A small kernel width assigns significant weight only to samples very close to the original instance, enforcing strict local fidelity but potentially introducing instability due to a sparse neighborhood. A large kernel width creates a broader, smoother weighting scheme that may capture more global behavior at the expense of local precision. The kernel width directly shapes the local decision boundary that the interpretable surrogate model approximates.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.