TreeExplainer attributes predictions from tree-based models to their input features, helping explain why an individual prediction or a broader model pattern occurs. section 7.3
Choose the calculation approach according to the explanation goal:
- Use tree-path-dependent perturbation when reconstructing the model's original predictions is important. section 7.3
- Use interventional perturbation when correlated features make more causally informed contribution estimates valuable, accepting longer computation and weaker prediction reconstruction. section 7.3
- Inspect global importance with bar plots or feature effects with violin plots, then package individual explanations as JSON containing values and SHAP contributions. section 7.3
Explain an XGBoost prediction
Transform the input data, construct a TreeExplainer for the XGBoost model, request raw interventional SHAP values, and compare their interpretation with the model's prediction. section 7.3
from shap import TreeExplainer explainer = TreeExplainer(model_pipeline['xgb'], data=Xt, model_output='raw', feature_perturbation='interventional') interventional_shap_values = explainer.shap_values(Xt)
Open the runnable interventional TreeExplainer setup. section 7.3
