shapiq.interaction_values.InteractionValuesBatchΒΆ
- class shapiq.interaction_values.InteractionValuesBatch(values, *, n_instances, n_players, index, max_order, min_order, baseline_value)[source]ΒΆ
Bases:
Sequence[InteractionValues]A batch of interaction values for multiple instances in a vectorized format.
Instead of one
InteractionValuesobject per instance, the batch stores one value array of shape(n_instances,)per interaction β a memory-efficient layout for explaining many instances at once (the output format of the Woodelf algorithms). The batch behaves like a read-only sequence ofInteractionValues: indexing and iterating materialize the per-instance objects lazily, so consumers that only need the raw arrays never pay for them.- Variables:
values β The interaction values in the vectorized format
{interaction_tuple: ndarray of shape (n_instances,)}holding the ordersmax(min_order, 1) .. max_order. Interactions that are zero for every instance may be omitted; the empty interaction()is not included.n_instances β The number of explained instances in the batch.
n_players β The number of players (features) of the explained instances.
index β The interaction index of the values (e.g.
"SV"or"k-SII").max_order β The maximum interaction order contained in the batch.
min_order β The minimum interaction order of the materialized
InteractionValues. When0, the empty interaction()is added with the baseline value on materialization.baseline_value β The baseline value (empty prediction) of the explained model.
- Parameters:
Initializes the InteractionValuesBatch.
- Parameters:
values (
dict[tuple[int,...],ndarray]) β The interaction values in the vectorized format{interaction_tuple: ndarray of shape (n_instances,)}.n_instances (
int) β The number of explained instances in the batch.n_players (
int) β The number of players (features) of the explained instances.index (
str) β The interaction index of the values (e.g."SV"or"k-SII").max_order (
int) β The maximum interaction order contained in the batch.min_order (
int) β The minimum interaction order of the materializedInteractionValues.baseline_value (
float) β The baseline value (empty prediction) of the explained model.
- classmethod from_interaction_values(instances)[source]ΒΆ
Build a batch from per-instance interaction values.
Transposes the instances into the vectorized batch storage. The metadata (index, orders, number of players, and baseline value) is taken from the first instance.
- Parameters:
instances (
Sequence[InteractionValues]) β OneInteractionValuesper explained instance. Must be non-empty.- Return type:
- Returns:
The batch holding the values of all instances.
- Raises:
ValueError β If
instancesis empty.