Model Explainability Tools

Compare SHAP and LIME explanations side by side. Enter your model features, configure the explanation method, and generate interactive feature attribution visualizations with faithfulness metrics and interpretation confidence scores.

Configure Your Model

Select your model type and prediction task. The explanation methods adapt their interpretation strategy based on the architecture.

Model Features

Add the features your model uses. Enter a name and the current input value for each feature.

Explanation Export


    

Understanding Model Explainability: SHAP vs LIME

Model explainability has become a non-negotiable requirement for deploying machine learning in regulated industries. When a credit model denies a loan, a medical model recommends a treatment, or an insurance model sets a premium, stakeholders demand to know why. The two dominant frameworks for post-hoc model explanation are SHAP (SHapley Additive exPlanations) and LIME (Local Interpretable Model-agnostic Explanations). Both produce feature-level attributions that explain individual predictions, but they approach the problem from fundamentally different mathematical foundations, and their differences have practical consequences for trust, consistency, and regulatory compliance.

SHAP is grounded in cooperative game theory. It treats each feature as a player in a coalition game and uses Shapley values to allocate the prediction across features in a way that satisfies four desirable properties: efficiency (attributions sum to the prediction), symmetry (features that contribute equally receive equal attribution), dummy (features that contribute nothing receive zero attribution), and additivity (attributions for combined models equal the sum of individual attributions). These properties are not approximate heuristics but mathematical theorems, which gives SHAP explanations a theoretical rigor that other methods lack.

How SHAP Computes Feature Attributions

The core Shapley value formula requires evaluating the model on every possible subset of features, computing each feature's marginal contribution across all coalitions. For n features, this requires 2^n model evaluations, which is computationally intractable for models with more than 15-20 features. In practice, SHAP uses approximations tailored to model architecture. TreeSHAP exploits the structure of tree-based models to compute exact Shapley values in polynomial time O(TLD), where T is the number of trees, L is the maximum number of leaves, and D is the maximum tree depth. This makes SHAP practical for XGBoost, LightGBM, and Random Forest models with thousands of features. For neural networks, DeepSHAP combines Shapley values with backpropagation (DeepLIFT rules) to propagate attributions through layers efficiently. KernelSHAP is the model-agnostic fallback that approximates Shapley values using weighted linear regression on sampled coalitions, trading exactness for universality.

How LIME Builds Local Explanations

LIME takes a fundamentally different approach. Instead of computing exact attributions via game theory, LIME approximates the model's behavior locally around a specific prediction by building a simple interpretable surrogate model (typically a linear model or decision tree). The process works in four steps: (1) generate perturbed samples around the input by randomly toggling features on and off, (2) compute the original model's predictions on all perturbed samples, (3) weight each sample by its proximity to the original input using an exponential kernel, (4) fit a weighted linear model to the perturbed dataset. The coefficients of this linear model become the feature attributions. LIME's advantage is speed and model-agnosticism: it needs only query access to the model, not knowledge of its internals. However, the perturbation sampling introduces randomness. Running LIME twice on the same input can yield different explanations because the random perturbations differ between runs. This instability is a significant concern for regulated applications where explanations must be reproducible.

Faithfulness and Stability Metrics

An explanation is only useful if it is faithful to the model's actual reasoning. Faithfulness metrics measure how well an explanation reflects what the model truly relies on. Perturbation faithfulness removes the top-attributed features and measures the resulting prediction change. If the explanation is faithful, removing highly attributed features should cause the largest change. Monotonicity checks that features with higher attribution consistently cause larger prediction changes when removed. Infidelity computes the expected difference between the explanation's predicted impact and the actual impact across random perturbations. Stability measures whether similar inputs produce similar explanations. SHAP generally scores higher on faithfulness and stability because its mathematical foundation guarantees consistency. LIME scores higher on speed and can provide rule-based explanations (via decision tree surrogates) that are more intuitively readable than numeric attributions.

Security Implications of Model Explanations

From a security perspective, model explanations are a double-edged sword. They provide transparency for stakeholders but also leak information to adversaries. SHAP values reveal feature importance rankings, which help attackers craft adversarial examples that target the most influential features. If an attacker knows that "credit_score" has the highest SHAP value for a loan approval model, they can focus their manipulation on that single feature rather than guessing. LIME explanations similarly reveal which features the model attends to locally, enabling targeted adversarial perturbations. Organizations must balance transparency requirements against information leakage risks. Best practices include: restricting explanation access to authenticated users, rate limiting explanation queries separately from prediction queries, monitoring for explanation harvesting patterns, and applying differential privacy to SHAP values when explanations are exposed externally.

Choosing the Right Method for Your Use Case

For regulatory compliance (EU AI Act, GDPR Article 22, ECOA), SHAP is the safer choice because its mathematical guarantees make explanations reproducible and auditable. For real-time user-facing explanations where speed matters more than theoretical guarantees (recommendation explanations, content moderation reasoning), LIME's speed advantage makes it practical. For tree-based models, TreeSHAP provides the best of both worlds: exact Shapley values with computational efficiency. For deep learning models, the choice depends on whether you need local explanations (LIME or DeepSHAP) or global feature importance (aggregated SHAP values across a dataset). The interactive tool above lets you see how both methods attribute importance to your features, compare their outputs, and measure faithfulness metrics so you can make an informed decision for your deployment.

Emerging Alternatives and the Future of Explainability

The explainability landscape is evolving beyond SHAP and LIME. Concept-based explanations (TCAV, ACE) explain predictions in terms of human-understandable concepts rather than raw features, making them more accessible for non-technical stakeholders. Counterfactual explanations answer "what would need to change for a different prediction?" which aligns with how humans naturally reason about decisions. Attention-based explanations for transformers visualize which input tokens the model focuses on, though research has shown attention weights do not always correspond to feature importance. Mechanistic interpretability aims to reverse-engineer neural network internals to understand how features are computed, not just which features matter. As the EU AI Act enforcement begins in August 2026, these methods will become increasingly important for compliance with transparency and explainability requirements for high-risk AI systems.

Frequently Asked Questions

What is the difference between SHAP and LIME for model explainability?

SHAP uses game-theoretic Shapley values to compute exact feature contributions with mathematical guarantees of consistency, efficiency, and symmetry. LIME builds a local surrogate model around a single prediction by perturbing inputs and fitting a simple interpretable model. SHAP provides global consistency but is computationally expensive. LIME is faster but can produce inconsistent explanations across similar inputs because the perturbation sampling introduces randomness.

When should I use SHAP instead of LIME?

Use SHAP when you need mathematically guaranteed feature attributions that sum exactly to the model output, when consistency across explanations matters for regulatory or audit contexts, when you need both local and global explanations, or when working with tree-based models where TreeSHAP provides exact values efficiently. Use LIME when speed is critical, when working with opaque models where SHAP kernel methods are too slow, or when you need rule-based explanations.

How do I measure if a model explanation is faithful?

Key faithfulness metrics include perturbation faithfulness (removing top-attributed features should cause the largest prediction change), monotonicity (higher attribution features should have larger impact when removed), infidelity (expected difference between predicted and actual change), and stability (similar inputs should produce similar explanations). A faithful explanation correctly identifies which features the model actually relies on.

Can SHAP and LIME explanations be used for regulatory compliance?

Yes. SHAP is generally preferred for compliance because its Shapley value foundation provides mathematical guarantees. LIME explanations may face scrutiny because their inherent randomness means the same input can produce different explanations across runs. Both are used under GDPR Article 22, the EU AI Act, and financial regulations like SR 11-7.

What are the computational costs of SHAP vs LIME?

LIME typically runs in 1-5 seconds per explanation. Kernel SHAP scales as O(2^n) for n features in the exact case, though approximations reduce this. TreeSHAP runs in O(TLD) time. For deep learning models, DeepSHAP and GradientSHAP use backpropagation-based approximations that run in seconds but sacrifice some theoretical guarantees.

ML

Michael Lip

Builder of Zovo Tools — free developer utilities with no tracking. LockML helps ML engineers compare models, audit security, and build safer AI systems.