shapiq.explainer.TreeExplainer¶
- class shapiq.explainer.TreeExplainer(model, *, mode='pathdependent', reference_dataset=None, max_order=1, min_order=0, index='SV', class_index=None, **kwargs)[source]¶
Bases:
ExplainerThe TreeExplainer class for tree-based models.
The explainer for tree-based models using the
TreeSHAPIQalgorithm. For details, refer to Muschalik et al. (2024) [Mus24].TreeSHAP-IQ is an algorithm for computing Shapley Interaction values for tree-based models. It is based on the Linear TreeSHAP algorithm by Yu et al. (2022) [Yu22], but extended to compute Shapley Interaction values up to a given order. TreeSHAP-IQ needs to visit each node only once and makes use of polynomial arithmetic to compute the Shapley Interaction values efficiently.
The TreeExplainer can be used with a variety of tree-based models, including
scikit-learn,XGBoost,LightGBM, andCatBoost. The explainer can handle both regression and classification models.References
[Yu22]Peng Yu, Chao Xu, Albert Bifet, Jesse Read. (2022). Linear Tree Shap. In: Proceedings of 36th Conference on Neural Information Processing Systems. https://openreview.net/forum?id=OzbkiUo24g
[Mus24]Maximilian Muschalik, Fabian Fumagalli, Barbara Hammer, & Eyke Hüllermeier (2024). Beyond TreeSHAP: Efficient Computation of Any-Order Shapley Interactions for Tree Ensembles. In: Proceedings of the AAAI Conference on Artificial Intelligence, 38(13), 14388-14396. https://doi.org/10.1609/aaai.v38i13.29352
Initializes the TreeExplainer.
- Parameters:
model (
dict|TreeModel|list[TreeModel] |Any) – A tree-based model to explain.mode (In "interventional") – The mode of the explainer, either
"pathdependent"or"interventional".mode
"SV". (the explainer computes path-dependent interaction values using the TreeSHAPIQ algorithm or the Linear TreeSHAP algorithm if the index is)
mode
algorithm. (the explainer computes interventional interaction values using the Interventional TreeExplainer)
"pathdependent". (Defaults to)
max_order (
int) – The maximum order of interactions to be computed. Set to1for no interactions (i.e, for Shapley values"SV"or Banzhaf values"BV"). Any value higher than1computes interaction values up to that order. Defaults to1.min_order (
int) – The minimum interaction order to keep in the returnedInteractionValues. Must satisfy0 <= min_order <= max_order. Whenmin_order == 0the empty interaction()is included with the baseline value. Whenmin_order >= 1all interactions of order belowmin_orderare filtered out of the result; the underlying algorithm still computes them internally when required by aggregated indices such as"k-SII". Defaults to0.index (
Literal['SV','SII','k-SII']) – The type of interaction to be computed. It can be one of["k-SII", "SII", "STII", "FSII", "BII", "SV"]. All indices apart from"BII"will reduce to the"SV"(Shapley value) for order 1. Defaults to"SV".class_index (
int|None) – The class index of the model to explain. Defaults toNone, which will set the class index to1per default for classification models and is ignored for regression models.reference_dataset (
ndarray|None) – A dataset to be used for reference in the explanation when using mode=interventional. Defaults toNone.**kwargs (
Any) – Additional keyword arguments are ignored.