Inferensys

Glossary

SHAP Values

SHAP (SHapley Additive exPlanations) values quantify the contribution of each feature to a specific machine learning model prediction using principles from cooperative game theory.
Data engineer managing feature store on laptop, feature definitions visible, casual data engineering session.
MODEL EXPLAINABILITY

What are SHAP Values?

SHAP (SHapley Additive exPlanations) is a game-theoretic framework for interpreting machine learning model predictions by assigning each feature an importance value for a particular prediction.

SHAP values quantify the contribution of each feature to a specific model prediction by computing Shapley values from cooperative game theory. The method fairly distributes the prediction difference from the average model output among the input features, ensuring that the sum of all feature attributions equals the exact difference between the model's prediction for that instance and the baseline expected value.

In financial fraud anomaly detection, SHAP values enable investigators to understand precisely why a transaction was flagged. For example, a high SHAP value for transaction_amount and time_since_last_txn provides auditable, regulator-ready justification for a block decision. The framework is model-agnostic, working with tree-based models like XGBoost and deep learning architectures, and includes specialized implementations such as TreeSHAP for fast, exact computations on gradient-boosted trees.

GAME-THEORETIC EXPLAINABILITY

Key Properties of SHAP Values

SHAP (SHapley Additive exPlanations) values decompose a model's prediction into the marginal contribution of each feature, ensuring a fair, consistent, and theoretically grounded attribution of importance.

01

Local Accuracy

The sum of all feature attributions plus the base value (average model output) always equals the model's actual prediction for that specific instance. This property guarantees that the explanation is a complete and faithful decomposition of the output, leaving no residual variance unaccounted for.

  • Mathematical Guarantee: f(x) = φ₀ + Σᵢ φᵢ
  • Practical Meaning: You can literally add up the SHAP values to reconstruct the prediction score.
  • Contrast: Unlike LIME, which fits a local surrogate that may not perfectly match the original prediction, SHAP is an exact additive decomposition.
Exact
Decomposition Fidelity
02

Missingness

A feature that is not present in the input (i.e., its value is missing or it was not used by the model) is guaranteed to receive a SHAP value of zero. This prevents the explanation from arbitrarily assigning importance to features that did not influence the decision.

  • Zero Attribution: If xᵢ is absent, φᵢ = 0.
  • Structural Integrity: Ensures that the explanation respects the actual feature space used by the model.
  • Implementation Note: This is handled by manipulating the feature's value to a background dataset reference during the estimation process.
0
Attribution for Absent Features
03

Consistency

If a model is changed so that a feature's contribution increases or stays the same regardless of other inputs, the SHAP value for that feature cannot decrease. This ensures that explanations are logically stable and that a feature's attributed importance monotonically tracks its true impact.

  • Monotonicity: If a feature becomes more important to the model, its SHAP value must reflect that.
  • Model Comparison: This property is critical for comparing two different models and trusting that a higher SHAP value genuinely means a larger effect.
  • Violation Example: Gain-based feature importance in tree models can violate this, making SHAP a more reliable alternative.
Monotonic
Attribution Behavior
04

Model Agnosticism

SHAP is a unified framework that connects game theory with local explanations. While it has model-specific fast implementations (TreeSHAP, DeepSHAP, LinearSHAP), the core KernelSHAP algorithm is fully model-agnostic and can explain any black-box function.

  • KernelSHAP: Uses a weighted linear regression on coalitions of features to estimate Shapley values for any model.
  • TreeSHAP: An exact, polynomial-time algorithm for tree-based models (XGBoost, LightGBM, Random Forest) that computes SHAP values without sampling error.
  • DeepSHAP: A high-speed approximation for deep learning models that combines SHAP with DeepLIFT.
Any Model
Compatibility
05

Interaction Values

Beyond individual feature effects, SHAP can decompose predictions into Shapley interaction values. These capture the synergistic or antagonistic effect between pairs of features that cannot be explained by their individual contributions alone.

  • Pairwise Effects: φᵢⱼ represents the pure interaction effect between feature i and feature j.
  • Fraud Use Case: In transaction monitoring, an interaction between a high transaction amount and a sudden change in device fingerprint might have a disproportionately large effect that individual SHAP values miss.
  • Visualization: SHAP dependence plots can be colored by an interacting feature to visually reveal these non-linear synergies.
Pairwise
Interaction Granularity
06

Global Interpretability

While SHAP values are locally computed for a single prediction, aggregating them across a dataset provides powerful global insights. A SHAP summary plot combines feature importance and feature effects into a single visualization.

  • Mean |SHAP|: The average absolute SHAP value for a feature indicates its global importance.
  • Feature Density: The spread of SHAP values reveals how a feature's impact varies across the population.
  • Directionality: The sign of the SHAP value shows whether a feature pushes the prediction higher or lower, distinguishing it from purely magnitude-based importance metrics.
Local + Global
Explanation Scope
EXPLAINABILITY COMPARISON

SHAP vs. Other Feature Importance Methods

A comparison of SHAP values against other common feature attribution methods used in financial fraud detection models, highlighting key differences in theoretical guarantees, consistency, and practical utility.

FeatureSHAPPermutation ImportanceGini/Default Importance

Theoretical Foundation

Game-theoretic Shapley values

Empirical performance degradation

Impurity reduction during training

Local Explanations (Single Prediction)

Global Explanations (Aggregate)

Consistency Guarantee

Handles Correlated Features Correctly

Model Agnostic

Computational Cost (Relative)

High

Medium

Low

Direction of Impact (Sign)

EXPLAINABLE AI

SHAP Values in Financial Fraud Detection

SHAP (SHapley Additive exPlanations) is a game-theoretic approach to explain the output of any machine learning model by computing the contribution of each feature to a specific prediction. In financial fraud detection, SHAP values provide the granular, auditable reasoning required to justify blocking a transaction to regulators and customers.

01

The Core Mechanism: Shapley Values

SHAP borrows from cooperative game theory to assign a fair payout to each feature for a prediction. It calculates the marginal contribution of a feature by comparing the model's output with and without that feature, averaged over all possible subsets of features. This ensures the sum of all feature attributions equals the difference between the actual prediction and the average prediction. For a fraud model, this means the exact dollar amount of a transaction's risk score can be decomposed and assigned to specific drivers like transaction amount, device fingerprint mismatch, or velocity of recent logins.

02

Local vs. Global Interpretability

SHAP operates on two critical levels for fraud analysis:

  • Local Explanations: Explain a single prediction. Why was this specific transaction flagged? A force plot can show that a high cross-border transfer amount pushed the risk score up by 0.4, while a recognized device ID pushed it down by 0.1.
  • Global Explanations: Aggregate local explanations to understand overall model behavior. A summary plot reveals that transaction amount is the most impactful feature globally, but time since last password change has a long tail of high-impact outliers, indicating its role in catching account takeover fraud.
03

SHAP vs. Other Feature Importance Methods

Unlike permutation importance, which measures a feature's overall impact on model performance, or built-in Gini importance from tree models, SHAP provides consistent, individualized explanations. Key advantages:

  • Consistency: If a model relies more on a feature, its SHAP value magnitude will not decrease.
  • Accuracy: SHAP respects feature interactions. Two features like transaction amount and account age might have a synergistic effect that simpler additive methods miss.
  • Model-Agnostic: KernelSHAP works with any model, while TreeSHAP is optimized for tree-based ensembles like XGBoost and LightGBM, which are common in fraud detection.
04

Regulatory Compliance and Model Auditing

Financial regulators increasingly require adverse action reasons for automated credit and fraud decisions. SHAP values provide a mathematically sound basis for generating these reasons. For a declined transaction, the explanation can be automatically generated: 'This transaction was blocked due to an unusually high transaction amount relative to the account's 30-day average and a device location inconsistent with the cardholder's home address.' This bridges the gap between a black-box deep learning model and the right to explanation mandated by regulations like GDPR and the Fair Credit Reporting Act (FCRA).

05

Detecting Model Bias and Data Leakage

Global SHAP analysis is a powerful debugging tool. If a protected attribute like geographic region or a proxy for it shows unexpectedly high SHAP importance, it signals potential bias requiring investigation. Similarly, if a feature like transaction ID or a highly granular user agent string has a dominant SHAP value, it strongly indicates data leakage—the model is memorizing identifiers rather than learning generalizable fraud patterns. This allows MLOps teams to catch critical flaws before a model is deployed to production.

06

Computational Considerations with TreeSHAP

Calculating exact Shapley values is computationally exponential. However, TreeSHAP, a variant specific to tree-based models, reduces the complexity to O(TLD^2) where T is the number of trees, L is the maximum number of leaves, and D is the maximum tree depth. This makes it feasible to generate explanations in milliseconds for real-time fraud scoring pipelines. For deep learning models used in sequence-based fraud detection, DeepSHAP uses a linear composition rule to approximate SHAP values by backpropagating attributions through the network layers.

SHAP VALUES EXPLAINED

Frequently Asked Questions

Clear, technically precise answers to the most common questions about SHapley Additive exPlanations for machine learning model interpretability.

SHAP (SHapley Additive exPlanations) values are a game-theoretic approach to explain the output of any machine learning model by computing the contribution of each feature to a specific prediction. The method is rooted in Shapley values from cooperative game theory, where the 'game' is the prediction task and the 'players' are the input features. SHAP works by considering all possible subsets of features and calculating the marginal contribution of a feature when it is added to a subset. The final SHAP value for a feature is the weighted average of its marginal contributions across all possible feature coalitions. This ensures a mathematically fair distribution of the prediction among the features, satisfying properties of local accuracy, missingness, and consistency. For a fraud detection model, a SHAP value tells you exactly how much a specific transaction feature—like transaction amount or time since last login—pushed the model's risk score higher or lower than the average prediction.

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.