Navigation

Introduction to AI

Machine Learning

Deep Learning

Generative AI

Tools & Frameworks

General

Explainability and Interpretability in AI

Explainability and interpretability address a critical challenge: understanding how machine learning models make decisions. A model might predict a loan will be denied, but why? “The model said so” is insufficient for fairness, debugging, and regulatory compliance.

Interpretability techniques bridge the gap between “black box” predictions and human understanding.

Interpretability vs. Explainability

These terms overlap but differ slightly:

  • Interpretability: Ability to understand what a model learned (what features are important, how they interact).
  • Explainability: Ability to explain specific predictions (why did you deny this loan?).

A model might be interpretable (simple decision tree) but not explain specific predictions (many equally valid paths). Conversely, a complex model might explain individual predictions (via SHAP) without being globally interpretable.

Intrinsic Interpretability

Some models are inherently interpretable.

Linear Models

$$y = \beta_0 + \beta_1 x_1 + … + \beta_n x_n$$

Coefficients directly show feature importance. Positive $\beta_i$ means feature $i$ increases prediction; negative means it decreases.

Limitation: Assumes linear relationships; real-world phenomena are often non-linear.

Decision Trees

Hierarchical splits on features. Easy to trace a prediction by following branches.

        age < 30?
       /          \
    YES            NO
   /                \
credit > 700?       income > 50K?
/            \      /           \
YES      NO   YES     NO
approved denied approved denied

Limitation: Deep trees become uninterpretable; can overfit.

Rule-Based Models

Explicit rules: “If age < 25 AND credit < 600, deny. Else if…”

Advantage: Fully transparent.

Limitation: Difficult to achieve high accuracy; rules don’t capture complex patterns.

Post-Hoc Explanations

Explain decisions from a trained black-box model without modifying it.

LIME (Local Interpretable Model-agnostic Explanations)

Approximate a complex model locally with a simple, interpretable model:

  1. Perturb input: Generate variations of the input $x$ (add noise, remove features).
  2. Predict: Get predictions from the black-box model.
  3. Fit simple model: Fit a linear model (or decision tree) to the perturbed samples and their predictions.
  4. Extract explanation: Read off linear coefficients as feature importance.

$$\min_\theta \sum_i L(f(x + \delta_i), g(x + \delta_i; \theta)) + \lambda |\theta|_1$$

where $g$ is the simple model, $f$ is the black-box model, and $\delta_i$ are perturbations.

Advantage: Model-agnostic; works for any model.

Limitation: Local to one instance; expensive (requires many model evaluations); approximation quality depends on local linearity assumption.

SHAP (SHapley Additive exPlanations)

Uses game theory (Shapley values) to assign importance to each feature:

$$\phi_i = \sum_{S \subseteq {1,…,n} \setminus {i}} \frac{|S|!(n-|S|-1)!}{n!} (v(S \cup {i}) - v(S))$$

where $v(S)$ is the model’s prediction using features in set $S$ (other features marginalized out).

Interpretation: $\phi_i$ is feature $i$‘s average contribution to the prediction across all possible feature subsets.

Advantages:

  • Theoretically sound (satisfies desirable axioms).
  • Local and global interpretability.
  • Consistent (feature importance sums to prediction).

Limitation: Computationally expensive (exponential in number of features) — requires approximations (TreeSHAP for trees, KernelSHAP for general models).

Attention Visualization

For models with attention (e.g., transformers), visualize attention weights:

  • Self-attention: Which positions does each position attend to?
  • Cross-attention: Which input regions does the model focus on?

Attention maps provide interpretable summaries of model focus.

Limitation: Attention weights don’t directly explain decisions; they are correlates, not causes.

Saliency Maps and Gradient-Based Methods

Saliency Maps

Visualize which input regions most affect the prediction.

$$\text{Saliency}(x) = \left| \frac{\partial f(x)}{\partial x} \right|$$

Compute gradients of output with respect to input; high gradients indicate high sensitivity.

Application: Show which pixels in an image influence a classification.

Limitation: Gradients are noisy; neighboring pixels with opposite gradients cancel out; doesn’t capture non-local effects.

Integrated Gradients

Accumulate gradients along a path from a baseline (e.g., all zeros) to the actual input:

$$\text{IG}_i(x) = (x_i - x’_i) \int_0^1 \frac{\partial f(x’ + t \cdot (x - x’))}{\partial x_i} dt$$

Advantage: More stable and interpretable than raw saliency; satisfies useful axioms (sensitivity, implementation invariance).

Guided Backpropagation

Modify backpropagation to show which features positively contribute to the target class, suppressing negative contributions.

Trade-off: Better visualizations but less faithful to actual model computation.

Counterfactual Explanations

Explain by contrast: “What would need to change for a different prediction?”

Example: “Your loan was denied. It would be approved if your income were $75K+ (currently $45K) or your credit score were 750+ (currently 650).”

Algorithmic Generation

Generate minimal counterfactual explanations:

$$\min_{x’} L(x, x’) + \lambda |x’ - x|$$

where $L$ measures prediction difference (minimize to find $x’$ with different prediction) and $|x’ - x|$ measures distance (minimize for plausibility).

Advantage: Interpretable; actionable (tells people what to change).

Limitation: May suggest unrealistic counterfactuals; difficult to generate diverse counterfactuals.

Feature Importance

Measure which features most influence predictions.

Permutation Importance

Shuffle a feature; measure decrease in model performance:

$$\text{Importance}(i) = \text{Performance}{\text{original}} - \text{Performance}{\text{shuffled}_i}$$

Advantage: Model-agnostic; easy to compute.

Limitation: Ignores feature interactions; can be misleading if features are correlated.

Partial Dependence Plots (PDP)

Show marginal effect of a feature on predictions:

$$\text{PDP}(x_i) = \mathbb{E}{x{-i}} [f(x_i, x_{-i})]$$

Average prediction as a function of one feature, marginalizing over others.

Advantage: Interpretable; shows feature-prediction relationships.

Limitation: Assumes features are independent (unrealistic for correlated features).

Challenges

Fidelity

An explanation should be faithful to the model. Unfaithful explanations mislead. Verify explanations against actual model behavior.

Completeness

Good explanations should account for the model’s full decision. Simple explanations (top-3 features) may miss important interactions.

Contrastiveness

Explain what led to this prediction vs. another. Often more informative than absolute explanations.

Computational Cost

Explanation methods (SHAP) can be expensive. For interactive systems, latency matters.

Regulatory and Ethical Implications

GDPR Right to Explanation

EU General Data Protection Regulation (GDPR) grants individuals the right to explanation for algorithmic decisions affecting them.

Fair Lending

Fair lending laws (US) require lenders to explain credit decisions in terms of decision factors. Interpretability is legally mandated.

Best Practices

  1. Combine methods: Use multiple explanation techniques (LIME, SHAP, attention) to corroborate findings.
  2. Validate explanations: Check that explanations align with actual model behavior.
  3. Domain expertise: Involve domain experts; they can assess explanation plausibility.
  4. Transparency limits: Acknowledge explainability is incomplete; models are complex.
  5. Fairness check: Use explanations to audit for bias; ensure groups aren’t systematically disadvantaged.

Research Directions

  • Causal explanations: Move beyond correlation; explain causal mechanisms.
  • Temporal explanations: Explain sequences and time-series predictions.
  • Multimodal explanations: Explain predictions over images, text, and other modalities jointly.
  • Efficient explanation: Develop scalable methods for real-time, interactive explanation.

Explainability is increasingly critical for trustworthy, regulatory-compliant, and fair AI systems. As AI impacts society, transparency in decision-making is non-negotiable.