shapiq.tree.TreeSHAPIQΒΆ

class shapiq.tree.TreeSHAPIQ(model, *, max_order=2, min_order=1, index='k-SII', verbose=False)[source]ΒΆ

Bases: object

The TreeSHAP-IQ computation class.

This class implements the TreeSHAP-IQ algorithm for computing Shapley Interaction values for tree-based models. It is used internally by the TreeExplainer. The TreeSHAP-IQ algorithm is presented in 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.

Note

This class is not intended to be used directly. Instead, use the TreeExplainer class to explain tree-based models which internally uses then the TreeSHAP-IQ algorithm.

Initializes the TreeSHAP-IQ explainer.

Parameters:
  • model (dict | TreeModel | Any) – A single tree model to explain. Note that unlike the TreeExplainer class, TreeSHAP-IQ only supports a single tree. It can be a dictionary representation of the tree, a TreeModel object, or any other single tree model supported by the validate_tree_model() function.

  • max_order (int) – The maximum interaction order to be computed. An interaction order of 1 corresponds to the Shapley value. Any value higher than 1 computes the Shapley interaction values up to that order. Defaults to 2.

  • min_order (int) – The minimum interaction order to be computed. Must be >= 1. Defaults to 1.

  • index (Literal['SV', 'SII', 'k-SII']) – The type of interaction to be computed.

  • verbose (bool) – Whether to print information about the tree during initialization. Defaults to False.

explain(x)[source]ΒΆ

Computes the Shapley Interaction values for a given instance x and interaction order.

Note

This function is the main explanation function of this class.

Parameters:

x (ndarray) – Instance to be explained.

Returns:

The computed Shapley Interaction values.

Return type:

InteractionValues