shapiq.tree.LinearTreeSHAPΒΆ

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

Bases: object

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

Implements the Linear TreeSHAP algorithm 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)

  • class_index (int | None)

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

Initialize the LinearTreeSHAP explainer.

Parameters:
  • model (Any) – A fitted tree model or ensemble accepted by validate_tree_model(). Ensembles are explained tree by tree and aggregated.

  • class_index (int | None) – The class index for classification models. Defaults to None.

  • base_func (Callable[[int], ndarray]) – Callable int -> np.ndarray returning the interpolation base for the given depth. Defaults to numpy.polynomial.chebyshev.chebpts2().

explain(x)[source]ΒΆ

Computes the Shapley values for a single instance (alias of explain_function).

Return type:

InteractionValues

Parameters:

x (ndarray)

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

property empty_prediction: floatΒΆ

The empty prediction (baseline value) of the explained tree or ensemble.