RegressionFSII

Faithful Shapley Interaction Index via regression using RegressionFSII Fumagalli et al.[1].

from __future__ import annotations

import numpy as np

import shapiq

N_PLAYERS = 8
BUDGET = 200
feature_names = [f"x{i}" for i in range(N_PLAYERS)]

weights = np.array([0.4, 0.3, 0.2, 0.1, 0.05, -0.1, -0.2, -0.3])


def game_fun(coalitions: np.ndarray) -> np.ndarray:
    coalitions = np.atleast_2d(coalitions)
    return (coalitions @ weights) + 0.5 * coalitions[:, 0] * coalitions[:, 1]

Approximate FSII values

approximator = shapiq.RegressionFSII(n=N_PLAYERS, max_order=2, random_state=42)
iv = approximator.approximate(BUDGET, game_fun)
print(iv)
InteractionValues(
    index=FSII, max_order=2, min_order=0, estimated=True, estimation_budget=200,
    n_players=8, baseline_value=0.0,
    Top 10 interactions:
        (0, 1): 0.49999984443542284
        (0,): 0.3999999093274821
        (1,): 0.2999998720674785
        (2,): 0.20000002546472737
        (3,): 0.10000010315947862
        (4,): 0.050000070519854736
        (3, 4): -1.7520529030089438e-07
        (5,): -0.10000002944123698
        (6,): -0.20000005472499977
        (7,): -0.3000000918661308
)

Force plot

iv.plot_force(feature_names=feature_names)
plot regression fsii

Network plot

iv.plot_network(feature_names=feature_names)
plot regression fsii

References

Total running time of the script: (0 minutes 0.680 seconds)