This package implements algorithms for computing interventional SHAP values and interaction values of piecewise linear trees and their ensembles.
This includes piecewise linear tree ensembles from LightGBM (LGBMRegressor(linear_tree=True)
, LGBMClassifier(linear_tree=True)
).
The implemented algorithms are described in the paper [1].
The package can directly be installed from GitHub using pip:
pip install https://github.com/schufa-innovationlab/pltreeshap/archive/main.zip
For this, an installed C++ compiler is required (e.g. Microsoft Visual C++ 14.0 for Windows).
The package provides the explainer class PLTreeExplainer
implementing the methods shap_values
and shap_interaction_values
.
from pltreeshap import PLTreeExplainer
# get and train model
model = ...
# set up explainer with background data (e.g. training data)
explainer = PLTreeExplainer(model, data=data)
# compute SHAP values of some sample points (e.g. validation data)
phi = explainer.shap_values(x)
# compute SHAP interaction values
phi2 = explainer.shap_interaction_values(x)
Both SHAP algorithms from the paper [1] are implemented. The first one iterates over the background dataset. This algorithm is used with the following code.
explainer = PLTreeExplainer(model)
phi = explainer.shap_values(x, data=data) # iteration over points in `data`
The second variant precomputes split statistics of the background dataset and uses this statistics for SHAP computation. The statistics are precomputed when passing the data to the explainer class, i.e. PLTreeExplainer(model, data=data)
, or by the following code.
explainer = PLTreeExplainer(model)
explainer.aggregate(data) # precomputes split statistics
phi = explainer.shap_values(x)
[1] Zern, A. and Broelemann, K. and Kasneci, G.; Interventional SHAP Values and Interaction Values for Piecewise Linear Regression Trees; Proceedings of the AAAI Conference on Artificial Intelligence, 2023;
Bibtex
@inproceedings{Zern2023Interventional,
author = {Artjom Zern and Klaus Broelemann and Gjergji Kasneci},
title = {Interventional SHAP Values and Interaction Values for Piecewise Linear Regression Trees},
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
year = {2023}
}