← All Posts
MLOps · Production ML Case Studies

Explainable Scoring at Scale: From SHAP Values to Useful Evidence

Before you start: Shapley values and distributed scoring contracts.

An explanation should answer a concrete question: why did this model give this row this score relative to its baseline? It should also let a reviewer inspect the underlying evidence. SHAP contributions support the first question; feature values, provenance, and reference statistics support the second. A production explanation needs both.

Feature A receives ½[(0.40−0.10)+(0.80−0.20)]=0.45; B receives 0.25. Baseline 0.10 + 0.45 + 0.25 = 0.80.
Known featuresValue v(S)
None0.10
A0.40
B0.20
A and B0.80
Select a feature to inspect its two possible marginal contributions in a two-feature game. The complete coalition table remains visible.

Start with the output being explained

For an additive explanation, $f(x)=\phi_0+\sum_j\phi_j$. The baseline $\phi_0$ and all contributions must be in the same output space as f. If f is a binary classifier’s raw logit, adding contributions reconstructs the logit. Apply sigmoid after summing to recover the probability; do not call each logit contribution a probability-point change.

For example, baseline logit −2 and contributions +1.2,+0.8 reconstruct logit 0, hence probability 0.5. The baseline probability is sigmoid(−2)≈0.119. The probability change is about 0.381, not 2.0. A probability-output explainer is a different decomposition and must be supported by the model/explainer configuration.

The baseline encodes a comparison population

An interventional explanation integrates missing features against a background dataset under its defined intervention convention. A tree-path-dependent explanation uses tree path statistics to account for missing features. These approaches make different assumptions about feature dependence. Correlated features can therefore receive different allocations without a bug in the summation.

Choose a background appropriate to the question: a representative training population, a peer group, or a fixed reference cohort. Changing it changes the question. Version the background and keep it stable for comparisons. If different tenants receive different backgrounds, explain why the resulting contributions are not directly interchangeable.

Tree structure makes exact calculations practical

TreeSHAP uses the tree’s branch structure and path bookkeeping to account for feature coalitions efficiently. It is not just “subtract the prediction before and after each visited split.” A missing feature may route expectation through multiple branches, and repeated features on a path need careful treatment. The SHAP foundations chapter explains how tree structure changes the computation.

For ensembles, add contributions across trees in the model output space, including the appropriate base offset. Validate the explainer against a brute-force coalition calculation on tiny models where feasible. This catches assumptions that are obscured by a large production ensemble.

Explain the rows and features the product needs

Scoring every row and computing full explanations for every row are different workloads. If only a small queue needs detailed inspection, score the full population first, then explain selected rows plus an audit sample. This reduces compute while preserving visibility into non-alert cases. If every score requires an explanation, batch it and measure the cost separately.

01Score all eligible rowsStore keys and model outputs
02Select explanation workloadQueue plus audit sample, or full coverage
03Explain in batchesModel and background loaded per worker
04Validate and publishReconstruction, provenance, and version checks
The selection rule for explanations should be recorded. A dashboard of only high-risk cases does not describe global feature behavior.

A validation contract for explanations

Keep full contributions in the artifact even when the UI displays only a few. Otherwise the visible sum can silently fail to reconstruct the score.
InvariantRequired evidence
AdditivityBaseline + all contributions matches the declared output within tolerance
Feature alignmentContribution index matches the feature schema and raw value
Background identityVersion and sampling rule are recorded
CompletenessOmitted displayed features are aggregated into an “other” contribution
ProvenanceRaw evidence links resolve to the scored snapshot
StabilityFrozen rows do not change unexpectedly after a dependency update

An attribution is not a causal claim. “Permission count raised the model score” does not prove that reducing permissions would reduce actual risk. Counterfactual interventions require a model of which feature combinations are feasible and what outcomes would follow. Keep explanatory wording tied to the model computation.

Check your understanding: Can you sigmoid each SHAP logit contribution and add the results?

No. Sigmoid is nonlinear. Sum the baseline and contributions in logit space first, then transform the total, or use a supported probability-space explanation with its own assumptions.

Sources and further reading