TreeSHAP explains an individual prediction by assigning each feature a Shapley value: its contribution across combinations of the other features. It is specialized for decision trees and tree ensembles, using the trees' splits, leaf predictions, and example counts instead of a separately generated surrogate dataset. section 9.4.2
Its practical workflow is:
- Start with a fitted decision tree or ensemble and the particular example whose prediction needs explanation. section 9.4.2
- Compute each feature's contribution using the model's internal paths rather than fitting a local surrogate dataset. section 9.4.2
- Add contributions from individual trees to obtain the ensemble explanation, preserving SHAP's additivity property. section 9.4.2
- Read a waterfall or force plot to see which feature values push the prediction above or below its base value. section 9.4.2
Explaining one XGBoost prediction
For test example 3104 in the Bank Marketing data set, construct a shap.TreeExplainer for the XGBoost model, explain the example, and display shap.plots.waterfall or shap.plots.force. The force plot shows contributions that move the prediction of 0.52 above the average prediction of -0.194; the contributions sum to the overall prediction.

