shapiq.tree.LinearTreeSHAPΒΆ

class shapiq.tree.LinearTreeSHAP(model, *, base_func=<function chebpts2>)[source]ΒΆ

Bases: object

Linear TreeSHAP explainer for first-order Shapley values on tree-based models.

Implements the Linear TreeSHAP algorithm of Yu et al. (2022) for exact order=1 Shapley value computation on a single decision tree. The heavy lifting is delegated to a C++ kernel (linear_tree_shap_iterative), which is faster than the any-order TreeSHAPIQ algorithm when only Shapley values are needed.

Variables:
  • clf – The original tree-based model passed by the user.

  • edge_tree – Edge-based representation of the tree (EdgeTree) used by the C++ kernel for efficient traversal.

  • N – The \(N'\) matrix used by Linear TreeSHAP (see get_N_prime()).

  • Base – The Chebyshev (or user-supplied) interpolation base of length max_depth.

  • Offset – The Vandermonde-style power cache of Base + 1.

  • N_v2 – The interpolation N matrix evaluated at Base (see get_N_v2()).

Parameters:
  • model (Model)

  • base_func (Callable[[int], np.ndarray])

Initialize the LinearTreeSHAP explainer.

Parameters:
explain_function(x)[source]ΒΆ

Computes the Shapley values for a single instance.

Parameters:

x (ndarray) – The instance to explain as a 1-dimensional array.

Return type:

InteractionValues

Returns:

The interaction values for the instance.

shap_values_cpp_iterative(X)[source]ΒΆ

Shapley Value computation using an Iterative C++ Implementation of LinearTreeShap.

Parameters:

X (ndarray) – Datapoints

Returns:

The computed shapley values

Return type:

ndarray