A Shapley value fairly assigns each participant’s contribution across every possible coalition. For machine learning, SHAP values adapt this idea to assign each feature credit for a specific prediction. section 7.3
The practical interpretation follows three ideas:
- Each feature’s contribution reflects its influence across different feature combinations. section 7.3
- SHAP uses resampling to approximate the otherwise expensive calculation over all combinations. section 7.3
- The resulting explanations support model debugging, feature engineering, bias analysis, and interpretability. section 7.3
Explaining an XGBoost prediction
An XGBoost model can produce SHAP values for each transformed feature, compare them with predictions, and present global importance through bar or violin plots. A JSON explanation can pair each feature’s original value with its SHAP contribution for narrative interpretation. section 7.3
Listing 7.19 SHAP values as an XGBoost output
from XGBoost import DMatrix
booster = model_pipeline['xgb'].get_booster() #1
Xt = model_pipeline['processing'].transform(X) #2
feature_names = (
model_pipeline['processing']
.get_feature_names_out()
) #3
Xd = DMatrix(Xt) #4
shap_values = booster.predict(Xd, pred_contribs=True) #5
preds = booster.predict(Xd) #6
Inspect the runnable XGBoost procedure for obtaining transformed features, feature names, predictions, and SHAP contributions. section 7.3

