ProxySHAP¶

Proxy model-based interaction approximation using ProxySHAP.

from __future__ import annotations

import numpy as np

from shapiq.approximator import ProxySHAP

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 interaction values¶

approximator = ProxySHAP(n=N_PLAYERS, max_order=2, random_state=42)
iv = approximator.approximate(BUDGET, game_fun)
print(iv)
InteractionValues(
    index=k-SII, max_order=2, min_order=0, estimated=True, estimation_budget=200,
    n_players=8, baseline_value=0.0,
    Top 10 interactions:
        (0, 1): 0.5007201650054331
        (0,): 0.3982790335494763
        (1,): 0.30095687249149183
        (2,): 0.19733526918284908
        (3,): 0.09663668618735159
        (4,): 0.047598009004696004
        (4, 5): 0.002189095430586955
        (5,): -0.0949201886507579
        (6,): -0.19703468830913784
        (7,): -0.2957913661525175
)

Force plot¶

iv.plot_force(feature_names=feature_names)
plot proxyshap

Network plot¶

iv.plot_network(feature_names=feature_names)
plot proxyshap

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