shapiq.interaction_values.aggregate_interaction_valuesΒΆ
- shapiq.interaction_values.aggregate_interaction_values(interaction_values, aggregation='mean')[source]ΒΆ
Aggregates InteractionValues objects using a specific aggregation method.
- Parameters:
interaction_values (
Sequence[InteractionValues]) β A list of InteractionValues objects to aggregate.aggregation (
str) β The aggregation method to use. Defaults to"mean". Other options are"median","sum","max", and"min".
- Return type:
- Returns:
The aggregated InteractionValues object.
Example
>>> iv1 = InteractionValues( ... values=np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6]), ... interaction_lookup={(0,): 0, (1,): 1, (2,): 2, (0, 1): 3, (0, 2): 4, (1, 2): 5}, ... index="SII", ... max_order=2, ... n_players=3, ... min_order=1, ... baseline_value=0.0, ... ) >>> iv2 = InteractionValues( ... values=np.array([0.2, 0.3, 0.4, 0.5, 0.6]), # this iv is missing the (1, 2) value ... interaction_lookup={(0,): 0, (1,): 1, (2,): 2, (0, 1): 3, (0, 2): 4}, # no (1, 2) ... index="SII", ... max_order=2, ... n_players=3, ... min_order=1, ... baseline_value=1.0, ... ) >>> aggregate_interaction_values([iv1, iv2], "mean") InteractionValues( index=SII, max_order=2, min_order=1, estimated=True, estimation_budget=None, n_players=3, baseline_value=0.5, Top 10 interactions: (1, 2): 0.60 (0, 2): 0.35 (0, 1): 0.25 (0,): 0.15 (1,): 0.25 (2,): 0.35 )
Note
The index of the aggregated InteractionValues object is set to the index of the first InteractionValues object in the list.
- Raises:
ValueError β If the aggregation method is not supported.
- Parameters:
interaction_values (Sequence[InteractionValues])
aggregation (str)
- Return type: