shapiq.explainer.tree.utils#
This module contains utility functions for dealing with trees or tree structures.
Functions
|
Compute the empty prediction of a tree model. |
|
Get the conditional sample weights for a tree at each decision node. |
- shapiq.explainer.tree.utils.compute_empty_prediction(leaf_values, leaf_sample_weights)[source]#
Compute the empty prediction of a tree model.
The empty prediction is the weighted average of the leaf node values.
- shapiq.explainer.tree.utils.get_conditional_sample_weights(sample_count, parent_array)[source]#
Get the conditional sample weights for a tree at each decision node.
The conditional sample weights are the probabilities of going left or right at each decision node. The probabilities are computed by the number of instances going through each node divided by the number of instances going through the parent node. The conditional sample weights of the root node is 1.
- Parameters:
- Return type:
- Returns:
The conditional sample weights of the nodes.
Examples
>>> parent_array = np.asarray([-1, 0, 1, 1, 0, 4, 4]) # binary tree with depth 2 >>> sample_count = np.asarray([100, 70, 50, 20, 30, 15, 15]) >>> get_conditional_sample_weights(sample_count, parent_array) >>> [1., 0.7, 0.71428571, 0.28571429, 0.3, 0.5, 0.5]