Skip to main content

SHAPley Interaction Quantification (SHAP-IQ) for Explainable AI

Project description

shapiq_logo

unit-tests Coverage Status Documentation Status PyPi PyPi_status
  </a>
  <!-- PePy -->
  <a href= pepy mit_license black_codestyle

SHAP-IQ: SHAP Interaction Quantification

An interaction may speak more than a thousand main effects.

:exclamation: Note: This application is still in alpha and still under active development. :exclamation:

SHAP Interaction Quantification (short SHAP-IQ) is an XAI framework extending on the well-known shap explanations by introducing interactions to the equation. Shapley interactions extend on indivdual Shapley values by quantifying the synergy effect between machine learning entities such as features, data points, or weak learners in ensemble models. Synergies between these entities (also called players in game theory jargon) allows for a more intricate evaluation of your black-box models!

🛠️ Install

shapiq is intended to work with Python 3.9 and above. Installation can be done via pip:

pip install shapiq

⭐ Quickstart

You can use shapiq in different ways. If you have a trained model you can rely on the shapiq.explainer classes. If you are interested in the underlying game theoretic algorithms, then check out the shapiq.approximator modules. You can also plot and visualize your interaction scores with shapiq.plot.

📈 Compute k-SII values

Explain your models with Shapley interaction values like the k-SII values:

# train a model
from sklearn.ensemble import RandomForestRegressor

model = RandomForestRegressor(n_estimators=50, random_state=42)
model.fit(x_train, y_train)

# explain with k-SII interaction scores
from shapiq import TabularExplainer

explainer = TabularExplainer(
    model=model.predict,
    background_data=x_train,
    index="k-SII",
    max_order=2
)
interaction_values = explainer.explain(x_explain, budget=2000)
print(interaction_values)

>> > InteractionValues(
     >> > index = k - SII, max_order = 2, min_order = 1, estimated = True, estimation_budget = 2000,
>> > values = {
              >> > (0,): -91.0403,  # main effect for feature 0
>> > (1,): 4.1264,  # main effect for feature 1
>> > (2,): -0.4724,  # main effect for feature 2
>> > ...
     >> > (0, 1): -0.8073,  # 2-way interaction for feature 0 and 1
>> > (0, 2): 2.469,  # 2-way interaction for feature 0 and 2
>> > ...
     >> > (10, 11): 0.4057  # 2-way interaction for feature 10 and 11
                    >> >}
>> > )

📊 Visualize your Interactions

One handy way of visualizing interaction scores (up to order 2) are network plots. You can see an example of such a plot below. The nodes represent attribution scores and the edges represent the interactions. The strength and size of the nodes and edges are proportional to the absolute value of the attribution scores and interaction scores, respectively.

from shapiq.plot import network_plot

network_plot(
    first_order_values=k_sii_first_order,  # first order k-SII values
    second_order_values=k_sii_second_order # second order k-SII values
)

The pseudo-code above can produce the following plot (here also an image is added):

network_plot_example

📖 Documentation

The documentation for shapiq can be found here.

💬 Citation

If you ejnoy shapiq consider starring ⭐ the repository. If you really enjoy the package or it has been useful to you, and you would like to cite it in a scientific publication, please refer to the paper accepted at NeurIPS'23:

@article{shapiq,
  author       = {Fabian Fumagalli and
                  Maximilian Muschalik and
                  Patrick Kolpaczki and
                  Eyke H{\"{u}}llermeier and
                  Barbara Hammer},
  title        = {{SHAP-IQ:} Unified Approximation of any-order Shapley Interactions},
  journal      = {CoRR},
  volume       = {abs/2303.01179},
  year         = {2023},
  doi          = {10.48550/ARXIV.2303.01179},
  eprinttype    = {arXiv}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shapiq-0.0.5.tar.gz (60.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shapiq-0.0.5-py3-none-any.whl (64.2 kB view details)

Uploaded Python 3

File details

Details for the file shapiq-0.0.5.tar.gz.

File metadata

  • Download URL: shapiq-0.0.5.tar.gz
  • Upload date:
  • Size: 60.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for shapiq-0.0.5.tar.gz
Algorithm Hash digest
SHA256 3a41a9d5b29441725afbce47976db8079cfb39ce1fbf1e243fb81ced759fd784
MD5 48a782a934af3069fd5db2f17801e64f
BLAKE2b-256 c8d68523892d54498350d526153de9d3bd7765bff7df7f8265da713c6621eaff

See more details on using hashes here.

File details

Details for the file shapiq-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: shapiq-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 64.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for shapiq-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5523abea5a6fe983570bf2ebbfbc25d95099a264c60c176c8fd5421a5436b5d9
MD5 ca4b6917e5f403d2ac55be8529f69099
BLAKE2b-256 08b798df786aef7f9d311f6c219f744649f66cc22d6dda988dc6ead58ace2af5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page