OptiLIME is a framework that automates the selection of the kernel width hyperparameter in Local Interpretable Model-agnostic Explanations (LIME). It directly addresses the core instability problem of standard LIME, where different random seeds can produce contradictory feature importance rankings for the same prediction. The method defines stability as the concordance of explanations across repeated runs and frames the selection as a constrained optimization problem.
Glossary
OptiLIME

What is OptiLIME?
OptiLIME is an optimization framework that automatically selects the optimal kernel width for a LIME explanation by balancing the trade-off between local fidelity and the stability of the explanation across different runs.
The algorithm searches for the largest kernel width that maintains a user-specified minimum level of local fidelity, measured by the surrogate model's R-squared. A wider kernel enforces greater locality, reducing variance in the explanation by averaging over more consistent perturbed samples. This provides a mathematically principled, rather than heuristic, solution to the fidelity-interpretability trade-off, ensuring explanations are both faithful to the local decision boundary and reproducible.
Key Features of OptiLIME
OptiLIME provides a rigorous, data-driven methodology for automatically tuning the critical kernel width hyperparameter in LIME explanations, eliminating manual guesswork and ensuring both high local fidelity and run-to-run stability.
Stability-Fidelity Trade-off
Formalizes the core tension in local explanations as a mathematical optimization problem. OptiLIME defines stability as the Pearson correlation coefficient of feature importance weights across multiple runs, and fidelity as the R-squared score of the surrogate model. It systematically traces the Pareto frontier between these two objectives to identify the optimal operating point.
Automated Kernel Width Selection
Replaces ad-hoc manual tuning of the exponential kernel's sigma parameter with a deterministic algorithm. The framework evaluates candidate kernel widths by generating explanations at each setting and measuring the resulting stability-fidelity pair. It selects the largest kernel width that maintains a user-specified minimum stability threshold, maximizing local fidelity without sacrificing reproducibility.
Stability Index Metric
Introduces a quantitative Stability Index to measure explanation robustness. For a given kernel width, multiple LIME explanations are generated with different random seeds. The index computes the average pairwise correlation of feature importance vectors. A value approaching 1.0 indicates near-identical explanations across runs, while lower values signal sensitivity to perturbation sampling noise.
Local Fidelity Score
Quantifies how well the sparse linear surrogate approximates the black-box model's decision boundary in the local neighborhood. OptiLIME uses the coefficient of determination (R²) on the weighted perturbed samples as the fidelity metric. A score of 0.95 means the surrogate captures 95% of the variance in the black-box's local predictions, ensuring the explanation faithfully represents model behavior.
Pareto Frontier Analysis
Generates a Pareto frontier visualization plotting stability against fidelity for a range of kernel widths. This curve reveals the inherent trade-off: narrow kernels yield high-fidelity but unstable explanations, while wide kernels produce stable but lower-fidelity approximations. The optimal kernel width lies at the knee point of this curve, where marginal gains in one objective begin to severely penalize the other.
Domain-Agnostic Applicability
Operates as a wrapper around standard LIME, inheriting its model-agnostic property. OptiLIME can tune kernel widths for any data modality—tabular, text, or image—without requiring access to model internals. It only needs the black-box prediction function and a perturbation sampling strategy, making it deployable across diverse enterprise ML pipelines without architectural changes.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Clear answers to the most common technical questions about the OptiLIME framework for stabilizing local explanations.
OptiLIME is an optimization framework that automatically selects the optimal kernel width for a LIME explanation by balancing the trade-off between local fidelity and explanation stability. It works by running LIME multiple times with different kernel widths on the same instance, then identifying the largest kernel width that produces explanations with a stability index above a user-defined threshold. The framework formalizes the intuition that a kernel width that is too small leads to high-variance, unstable explanations, while one that is too large violates the locality assumption and degrades fidelity. By algorithmically finding the sweet spot, OptiLIME removes the need for manual hyperparameter tuning, which is often the most brittle and subjective part of generating a LIME explanation.
Related Terms
Core concepts that interact with the stability-driven optimization of local explanations.
Kernel Width
The hyperparameter directly optimized by OptiLIME. It controls the effective size of the local neighborhood by determining how quickly sample weights decay with distance from the instance.
- A narrow width enforces strict locality but can lead to high variance.
- A wide width smooths the explanation but may violate the local linearity assumption.
- OptiLIME finds the maximum width that preserves fidelity while maximizing stability.
Explanation Stability
The property that a local explanation remains consistent across multiple runs with different random seeds. OptiLIME directly targets this metric.
- Instability arises from the random perturbation sampling process.
- A stable explanation indicates that the identified features are robust signals rather than artifacts.
- OptiLIME defines stability as the concordance of feature rankings across repeated explanations.
Local Fidelity
A measure of how accurately the surrogate model approximates the black-box model in the immediate neighborhood. OptiLIME treats this as a constraint.
- Measured by the R-squared of the surrogate model on the weighted perturbed samples.
- OptiLIME enforces a minimum fidelity threshold to ensure the explanation remains meaningful.
- The framework explicitly balances fidelity against the kernel width to prevent over-smoothing.
Perturbation Sampling
The process of generating a synthetic neighborhood by randomly masking or altering features of the original instance. This randomness is the root cause of explanation instability.
- For text, this involves token masking.
- For images, this involves superpixel masking.
- OptiLIME's optimization directly counteracts the variance introduced by this sampling without requiring more samples.
Sparse Linear Model
The interpretable surrogate used within the LIME framework. OptiLIME optimizes the kernel width used to train this model.
- Uses Lasso regression to select only a few important features.
- The resulting coefficients become the feature importance scores.
- OptiLIME ensures these sparse weights are reproducible across different random seeds.
Fidelity-Interpretability Trade-off
The fundamental balancing act that OptiLIME automates. A complex surrogate may be more faithful but less interpretable, while a simple one may lose precision.
- OptiLIME focuses on a sub-problem: the fidelity-stability trade-off.
- A kernel width that is too small yields high fidelity but low stability.
- The framework finds the Pareto-optimal point where stability is maximized without sacrificing fidelity below a set threshold.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us