Ray's Knowledge Base
Unlock

SHAP TreeExplainer breaks additivity on HistGradientBoosting with missing values

PitfallVerified 1 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

shap.TreeExplainer(model, background).shap_values(X) stops with:

shap.utils._exceptions.ExplainerError: Additivity check failed in TreeExplainer! ... the sum of the SHAP values was -0.817884, while the model output was -0.989883.

The model is a scikit-learn HistGradientBoostingRegressor and the features have many NaN values. The same code passed on a small test with few NaN values.

Cause#

Not isolated. The failure came only after features with many NaN values were added. HistGradientBoosting sends a NaN down a branch it learned during the fit, and the likely cause is that the tree explainer does not follow that routing for every row. Treat this as a likely reason, not a proven one.

Fix#

Do not set check_additivity=False: it keeps values that do not add up. Use the permutation explainer. It calls only predict, so its values sum to the prediction by construction:

masker = shap.maskers.Independent(X_background, max_samples=len(X_background))
explainer = shap.PermutationExplainer(model.predict, masker, seed=0)
values = explainer(X_rows, max_evals=max(500, 2 * X_rows.shape[1] + 1), silent=True).values

max_evals must be at least 2 * n_features + 1.

Evidence#

Seen in the dpucrumbs black-box study (shap 0.52.0, scikit-learn 1.9.1, Python 3.13). The tree explainer passed a synthetic test, then failed once workloads with many NaN columns were pooled. The permutation explainer ran on the same data, and its values summed to the prediction.

Also found by searching

  • Additivity check failed in TreeExplainer!
  • SHAP values do not sum to the model output for HistGradientBoosting
  • how do I explain a HistGradientBoostingRegressor that has missing values
  • shap tree explainer wrong values with NaN features