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 InteractionValues object 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 of InteractionValues: 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 orders max(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. When 0, 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 materialized InteractionValues.

  • 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]) – One InteractionValues per explained instance. Must be non-empty.

Return type:

InteractionValuesBatch

Returns:

The batch holding the values of all instances.

Raises:

ValueError – If instances is empty.

baseline_value: floatΒΆ
max_order: intΒΆ
min_order: intΒΆ
n_instances: intΒΆ
n_players: intΒΆ
values: dict[tuple[int, ...], ndarray]ΒΆ