shapiq.tree.LinearTreeSHAPΒΆ
- class shapiq.tree.LinearTreeSHAP(model, *, class_index=None, base_func=<function chebpts2>)[source]ΒΆ
Bases:
objectLinear TreeSHAP explainer for first-order Shapley values on tree-based models.
Implements the Linear TreeSHAP algorithm Yu et al. [2022] for exact
order=1Shapley 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-orderTreeSHAPIQalgorithm 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(seeget_N_v2()).
- Parameters:
Initialize the
LinearTreeSHAPexplainer.- Parameters:
model (
Any) β A fitted tree model or ensemble accepted byvalidate_tree_model(). Ensembles are explained tree by tree and aggregated.class_index (
int|None) β The class index for classification models. Defaults toNone.base_func (
Callable[[int],ndarray]) β Callableint -> np.ndarrayreturning the interpolation base for the given depth. Defaults tonumpy.polynomial.chebyshev.chebpts2().
- explain(x)[source]ΒΆ
Computes the Shapley values for a single instance (alias of
explain_function).- Return type:
- 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:
- Returns:
The interaction values for the instance.