liveBook · Manning

TreeSHAP

As explained in Ensemble Methods for Machine Learning

TreeSHAP is an efficient SHAP algorithm that exploits the structure of decision trees to compute feature Shapley values.

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.

How Ensemble Methods for Machine Learning covers it

How deep it goes
Defines efficient computation and ensemble additivity, then demonstrates interpretation through plots without detailing the underlying path algorithm.
Examples
Uses an XGBoost Bank Marketing prediction, TreeExplainer code, and waterfall and force plots showing feature contributions.
What it assumes
Assumes familiarity with decision trees, ensembles, predictions, feature importance, and Shapley values; does not derive Shapley values from first principles.
What you can do after
Diagnose/debug with it by attributing a tree-model prediction to feature contributions and inspecting the result visually.
How it connects
Connects Shapley values, SHAP, LIME, tree ensembles, XGBoost, feature importance, and feature interactions.

Also explained in

Compare how 2 books explain TreeSHAP →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Ensemble Methods for Machine Learning. The section links point to the parts of the book it draws on.