shap/explainer-background-from-test
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| shap | warning | none, edit by hand | All versions |
Using holdout or test rows as the background dataset for shap.TreeExplainer, shap.Explainer, shap.KernelExplainer, shap.LinearExplainer, or shap.PermutationExplainer sets the SHAP baseline (expected_value) and interventional reference distribution from held-out data.
explainer = shap.TreeExplainer(model, X_test)explainer = shap.TreeExplainer(model, shap.sample(X_train, 100))What the rule reports
Section titled “What the rule reports”SHAP explainer constructors whose data/masker (second positional or keyword) argument is a test or holdout variable.
How to fix it
Section titled “How to fix it”Pass a background sample drawn from the training or development partition (for example shap.sample(X_train, 100)), then explain validation or test observations with explainer(X_val).
Diagnostic message
Section titled “Diagnostic message”Passing holdout or test rows as the SHAP background dataset leaks test distribution statistics into expected_value. Pass training or development background rows (such as shap.sample(X_train, 100)) instead.See all rules in the shap pack.