shapiq 0.0.4__tar.gz → 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shapiq-1.2.0/CHANGELOG.md +77 -0
- shapiq-1.2.0/MANIFEST.in +3 -0
- shapiq-1.2.0/PKG-INFO +358 -0
- shapiq-1.2.0/README.md +188 -0
- shapiq-1.2.0/pyproject.toml +16 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/setup.py +45 -16
- shapiq-1.2.0/shapiq/__init__.py +136 -0
- shapiq-1.2.0/shapiq/approximator/__init__.py +82 -0
- shapiq-1.2.0/shapiq/approximator/_base.py +344 -0
- shapiq-1.2.0/shapiq/approximator/marginals/__init__.py +6 -0
- shapiq-1.2.0/shapiq/approximator/marginals/owen.py +115 -0
- shapiq-1.2.0/shapiq/approximator/marginals/stratified.py +119 -0
- shapiq-1.2.0/shapiq/approximator/montecarlo/__init__.py +7 -0
- shapiq-1.2.0/shapiq/approximator/montecarlo/_base.py +463 -0
- shapiq-1.2.0/shapiq/approximator/montecarlo/shapiq.py +131 -0
- shapiq-1.2.0/shapiq/approximator/montecarlo/svarmiq.py +90 -0
- shapiq-1.2.0/shapiq/approximator/permutation/__init__.py +7 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/shapiq/approximator/permutation/sii.py +49 -61
- shapiq-0.0.4/shapiq/approximator/permutation/sti.py → shapiq-1.2.0/shapiq/approximator/permutation/stii.py +55 -41
- shapiq-1.2.0/shapiq/approximator/permutation/sv.py +132 -0
- shapiq-1.2.0/shapiq/approximator/regression/__init__.py +8 -0
- shapiq-1.2.0/shapiq/approximator/regression/_base.py +521 -0
- shapiq-1.2.0/shapiq/approximator/regression/fsi.py +53 -0
- shapiq-1.2.0/shapiq/approximator/regression/kadd_shap.py +56 -0
- shapiq-1.2.0/shapiq/approximator/regression/kernelshap.py +68 -0
- shapiq-1.2.0/shapiq/approximator/regression/kernelshapiq.py +134 -0
- shapiq-1.2.0/shapiq/approximator/sampling.py +518 -0
- shapiq-1.2.0/shapiq/benchmark/__init__.py +31 -0
- shapiq-1.2.0/shapiq/benchmark/configuration.py +825 -0
- shapiq-1.2.0/shapiq/benchmark/load.py +191 -0
- shapiq-1.2.0/shapiq/benchmark/metrics.py +182 -0
- shapiq-1.2.0/shapiq/benchmark/plot.py +487 -0
- shapiq-1.2.0/shapiq/benchmark/precompute.py +217 -0
- shapiq-1.2.0/shapiq/benchmark/run.py +473 -0
- shapiq-1.2.0/shapiq/datasets/__init__.py +5 -0
- shapiq-1.2.0/shapiq/datasets/_all.py +205 -0
- shapiq-1.2.0/shapiq/explainer/__init__.py +8 -0
- shapiq-1.2.0/shapiq/explainer/_base.py +155 -0
- shapiq-1.2.0/shapiq/explainer/tabpfn.py +120 -0
- shapiq-1.2.0/shapiq/explainer/tabular.py +271 -0
- shapiq-1.2.0/shapiq/explainer/tree/__init__.py +7 -0
- shapiq-1.2.0/shapiq/explainer/tree/base.py +194 -0
- shapiq-1.2.0/shapiq/explainer/tree/conversion/__init__.py +0 -0
- shapiq-1.2.0/shapiq/explainer/tree/conversion/edges.py +186 -0
- shapiq-1.2.0/shapiq/explainer/tree/conversion/lightgbm.py +101 -0
- shapiq-1.2.0/shapiq/explainer/tree/conversion/sklearn.py +188 -0
- shapiq-1.2.0/shapiq/explainer/tree/conversion/xgboost.py +120 -0
- shapiq-1.2.0/shapiq/explainer/tree/explainer.py +115 -0
- shapiq-1.2.0/shapiq/explainer/tree/treeshapiq.py +655 -0
- shapiq-1.2.0/shapiq/explainer/tree/utils.py +54 -0
- shapiq-1.2.0/shapiq/explainer/tree/validation.py +105 -0
- shapiq-1.2.0/shapiq/explainer/utils.py +227 -0
- shapiq-1.2.0/shapiq/game_theory/__init__.py +30 -0
- shapiq-1.2.0/shapiq/game_theory/aggregation.py +142 -0
- shapiq-1.2.0/shapiq/game_theory/core.py +167 -0
- shapiq-1.2.0/shapiq/game_theory/exact.py +914 -0
- shapiq-1.2.0/shapiq/game_theory/indices.py +275 -0
- shapiq-1.2.0/shapiq/game_theory/moebius_converter.py +377 -0
- shapiq-1.2.0/shapiq/games/__init__.py +9 -0
- shapiq-1.2.0/shapiq/games/base.py +545 -0
- shapiq-1.2.0/shapiq/games/benchmark/__init__.py +136 -0
- shapiq-1.2.0/shapiq/games/benchmark/_setup/__init__.py +4 -0
- shapiq-1.2.0/shapiq/games/benchmark/_setup/_california_torch_setup.py +96 -0
- shapiq-1.2.0/shapiq/games/benchmark/_setup/_resnet_setup.py +191 -0
- shapiq-1.2.0/shapiq/games/benchmark/_setup/_vit_setup.py +1738 -0
- shapiq-1.2.0/shapiq/games/benchmark/data_valuation/__init__.py +8 -0
- shapiq-1.2.0/shapiq/games/benchmark/data_valuation/base.py +92 -0
- shapiq-1.2.0/shapiq/games/benchmark/data_valuation/benchmark.py +108 -0
- shapiq-1.2.0/shapiq/games/benchmark/dataset_valuation/__init__.py +8 -0
- shapiq-1.2.0/shapiq/games/benchmark/dataset_valuation/base.py +162 -0
- shapiq-1.2.0/shapiq/games/benchmark/dataset_valuation/benchmark.py +219 -0
- shapiq-1.2.0/shapiq/games/benchmark/ensemble_selection/__init__.py +24 -0
- shapiq-1.2.0/shapiq/games/benchmark/ensemble_selection/base.py +277 -0
- shapiq-1.2.0/shapiq/games/benchmark/ensemble_selection/benchmark.py +168 -0
- shapiq-1.2.0/shapiq/games/benchmark/ensemble_selection/benchmark_random_forest.py +141 -0
- shapiq-1.2.0/shapiq/games/benchmark/feature_selection/__init__.py +8 -0
- shapiq-1.2.0/shapiq/games/benchmark/feature_selection/base.py +114 -0
- shapiq-1.2.0/shapiq/games/benchmark/feature_selection/benchmark.py +123 -0
- shapiq-1.2.0/shapiq/games/benchmark/global_xai/__init__.py +13 -0
- shapiq-1.2.0/shapiq/games/benchmark/global_xai/base.py +119 -0
- shapiq-1.2.0/shapiq/games/benchmark/global_xai/benchmark_tabular.py +159 -0
- shapiq-1.2.0/shapiq/games/benchmark/local_xai/__init__.py +17 -0
- shapiq-1.2.0/shapiq/games/benchmark/local_xai/base.py +132 -0
- shapiq-1.2.0/shapiq/games/benchmark/local_xai/benchmark_image.py +136 -0
- shapiq-1.2.0/shapiq/games/benchmark/local_xai/benchmark_language.py +137 -0
- shapiq-1.2.0/shapiq/games/benchmark/local_xai/benchmark_tabular.py +173 -0
- shapiq-1.2.0/shapiq/games/benchmark/setup.py +300 -0
- shapiq-1.2.0/shapiq/games/benchmark/synthetic/__init__.py +8 -0
- shapiq-1.2.0/shapiq/games/benchmark/synthetic/dummy.py +63 -0
- shapiq-1.2.0/shapiq/games/benchmark/synthetic/soum.py +211 -0
- shapiq-1.2.0/shapiq/games/benchmark/treeshapiq_xai/__init__.py +8 -0
- shapiq-1.2.0/shapiq/games/benchmark/treeshapiq_xai/base.py +156 -0
- shapiq-1.2.0/shapiq/games/benchmark/treeshapiq_xai/benchmark.py +218 -0
- shapiq-1.2.0/shapiq/games/benchmark/uncertainty/__init__.py +7 -0
- shapiq-1.2.0/shapiq/games/benchmark/uncertainty/base.py +122 -0
- shapiq-1.2.0/shapiq/games/benchmark/uncertainty/benchmark.py +58 -0
- shapiq-1.2.0/shapiq/games/benchmark/unsupervised_cluster/__init__.py +8 -0
- shapiq-1.2.0/shapiq/games/benchmark/unsupervised_cluster/base.py +101 -0
- shapiq-1.2.0/shapiq/games/benchmark/unsupervised_cluster/benchmark.py +142 -0
- shapiq-1.2.0/shapiq/games/benchmark/unsupervised_data/__init__.py +8 -0
- shapiq-1.2.0/shapiq/games/benchmark/unsupervised_data/base.py +94 -0
- shapiq-1.2.0/shapiq/games/benchmark/unsupervised_data/benchmark.py +37 -0
- shapiq-1.2.0/shapiq/games/imputer/__init__.py +8 -0
- shapiq-1.2.0/shapiq/games/imputer/base.py +128 -0
- shapiq-1.2.0/shapiq/games/imputer/baseline_imputer.py +151 -0
- shapiq-1.2.0/shapiq/games/imputer/conditional_imputer.py +167 -0
- shapiq-1.2.0/shapiq/games/imputer/marginal_imputer.py +181 -0
- shapiq-1.2.0/shapiq/games/imputer/tabpfn_imputer.py +110 -0
- shapiq-1.2.0/shapiq/interaction_values.py +925 -0
- shapiq-1.2.0/shapiq/plot/__init__.py +24 -0
- shapiq-1.2.0/shapiq/plot/_config.py +38 -0
- shapiq-1.2.0/shapiq/plot/bar.py +244 -0
- shapiq-1.2.0/shapiq/plot/force.py +630 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/shapiq/plot/network.py +254 -146
- shapiq-1.2.0/shapiq/plot/sentence.py +193 -0
- shapiq-1.2.0/shapiq/plot/si_graph.py +527 -0
- shapiq-1.2.0/shapiq/plot/stacked_bar.py +154 -0
- shapiq-1.2.0/shapiq/plot/upset.py +146 -0
- shapiq-1.2.0/shapiq/plot/utils.py +97 -0
- shapiq-1.2.0/shapiq/plot/watefall.py +379 -0
- shapiq-1.2.0/shapiq/utils/__init__.py +34 -0
- shapiq-1.2.0/shapiq/utils/datasets.py +24 -0
- shapiq-1.2.0/shapiq/utils/modules.py +74 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/shapiq/utils/sets.py +123 -8
- shapiq-1.2.0/shapiq/utils/types.py +6 -0
- shapiq-1.2.0/shapiq.egg-info/PKG-INFO +358 -0
- shapiq-1.2.0/shapiq.egg-info/SOURCES.txt +135 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/shapiq.egg-info/requires.txt +12 -0
- shapiq-1.2.0/tests/test_abstract_classes.py +64 -0
- shapiq-1.2.0/tests/test_base_interaction_values.py +740 -0
- shapiq-1.2.0/tests/test_configuration.py +17 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/tests/test_integration_import_all.py +10 -16
- shapiq-0.0.4/MANIFEST.in +0 -1
- shapiq-0.0.4/PKG-INFO +0 -139
- shapiq-0.0.4/README.md +0 -75
- shapiq-0.0.4/pyproject.toml +0 -10
- shapiq-0.0.4/shapiq/__init__.py +0 -47
- shapiq-0.0.4/shapiq/__version__.py +0 -1
- shapiq-0.0.4/shapiq/approximator/__init__.py +0 -12
- shapiq-0.0.4/shapiq/approximator/_base.py +0 -522
- shapiq-0.0.4/shapiq/approximator/permutation/__init__.py +0 -8
- shapiq-0.0.4/shapiq/approximator/regression/__init__.py +0 -5
- shapiq-0.0.4/shapiq/approximator/regression/fsi.py +0 -166
- shapiq-0.0.4/shapiq/approximator/shapiq/__init__.py +0 -5
- shapiq-0.0.4/shapiq/approximator/shapiq/shapiq.py +0 -254
- shapiq-0.0.4/shapiq/explainer/__init__.py +0 -7
- shapiq-0.0.4/shapiq/explainer/_base.py +0 -17
- shapiq-0.0.4/shapiq/games/__init__.py +0 -6
- shapiq-0.0.4/shapiq/games/dummy.py +0 -82
- shapiq-0.0.4/shapiq/plot/__init__.py +0 -7
- shapiq-0.0.4/shapiq/plot/_config.py +0 -23
- shapiq-0.0.4/shapiq/utils/__init__.py +0 -14
- shapiq-0.0.4/shapiq/utils/tree.py +0 -56
- shapiq-0.0.4/shapiq.egg-info/PKG-INFO +0 -139
- shapiq-0.0.4/shapiq.egg-info/SOURCES.txt +0 -40
- shapiq-0.0.4/tests/test_approximator_base_interaction_values.py +0 -87
- shapiq-0.0.4/tests/test_approximator_permutation_sii.py +0 -65
- shapiq-0.0.4/tests/test_approximator_permutation_sti.py +0 -61
- shapiq-0.0.4/tests/test_approximator_regression_fsi.py +0 -60
- shapiq-0.0.4/tests/test_approximator_shapiq.py +0 -109
- shapiq-0.0.4/tests/test_games_dummy.py +0 -70
- shapiq-0.0.4/tests/test_utils_sets.py +0 -75
- {shapiq-0.0.4 → shapiq-1.2.0}/LICENSE +0 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/setup.cfg +0 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/shapiq.egg-info/dependency_links.txt +0 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/shapiq.egg-info/top_level.txt +0 -0
- {shapiq-0.0.4 → shapiq-1.2.0}/shapiq.egg-info/zip-safe +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
## Changelog
|
|
2
|
+
|
|
3
|
+
### Development
|
|
4
|
+
...
|
|
5
|
+
|
|
6
|
+
### v1.2.0 (2025-01-15)
|
|
7
|
+
- adds ``shapiq.TabPFNExplainer`` as a specialized version of the ``shapiq.TabularExplainer`` which offers a streamlined variant of the explainer for the TabPFN model [#301](https://github.com/mmschlk/shapiq/issues/301)
|
|
8
|
+
- handles ``explainer.explain()`` now through a common interface for all explainer classes which now need to implement a ``explain_function()`` method
|
|
9
|
+
- adds the baseline_value into the InteractionValues object's value storage for the ``()`` interaction if ``min_order=0`` (default usually) for all indices that are not ``SII```(SII has another baseline value) such that the values are efficient (sum up to the model prediction) without the awkward handling of the baseline_value attribute
|
|
10
|
+
- renames ``game_fun`` parameter in ``shapiq.ExactComputer`` to ``game`` [#297](https://github.com/mmschlk/shapiq/issues/297)
|
|
11
|
+
- adds a TabPFN example notebook to the documentation
|
|
12
|
+
- removes warning when class_index is not provided in explainers [#298](https://github.com/mmschlk/shapiq/issues/298)
|
|
13
|
+
- adds the `sentence_plot` function to the `plot` module to visualize the contributions of words to a language model prediction in a sentence-like format
|
|
14
|
+
- makes abbreviations in the `plot` module optional [#281](https://github.com/mmschlk/shapiq/issues/281)
|
|
15
|
+
- adds the `upset_plot` function to the `plot` module to visualize the interactions of higher-order [#290](https://github.com/mmschlk/shapiq/issues/290)
|
|
16
|
+
- adds support for IsoForest models to explainer and tree explainer [#278](https://github.com/mmschlk/shapiq/issues/278)
|
|
17
|
+
- adds support for sub-selection of players in the interaction values data class [#276](https://github.com/mmschlk/shapiq/issues/276) which allows retrieving interaction values for a subset of players
|
|
18
|
+
- refactors game theory computations like `ExactComputer`, `MoebiusConverter`, `core`, among others to be more modular and flexible into the `game_theory` module [#258](https://github.com/mmschlk/shapiq/issues/258)
|
|
19
|
+
- improves quality of the tests by adding many more semantic tests to the different interaction indices and computations [#285](https://github.com/mmschlk/shapiq/pull/285)
|
|
20
|
+
|
|
21
|
+
### v1.1.1 (2024-11-13)
|
|
22
|
+
|
|
23
|
+
#### Improvements and Ease of Use
|
|
24
|
+
- adds a `class_index` parameter to `TabularExplainer` and `Explainer` to specify the class index to be explained for classification models [#271](https://github.com/mmschlk/shapiq/issues/271) (renames `class_label` parameter in TreeExplainer to `class_index`)
|
|
25
|
+
- adds support for `PyTorch` models to `Explainer` [#272](https://github.com/mmschlk/shapiq/issues/272)
|
|
26
|
+
- adds new tests comparing `shapiq` outputs for SVs with alues computed with `shap`
|
|
27
|
+
- adds new tests for checking `shapiq` explainers with different types of models
|
|
28
|
+
|
|
29
|
+
#### Bug Fixes
|
|
30
|
+
- fixes a bug that `RandomForestClassifier` models were not working with the `TreeExplainer` [#273](https://github.com/mmschlk/shapiq/issues/273)
|
|
31
|
+
|
|
32
|
+
### v1.1.0 (2024-11-07)
|
|
33
|
+
|
|
34
|
+
#### New Features and Improvements
|
|
35
|
+
- adds computation of the Egalitarian Core (`EC`) and Egalitarian Least-Core (`ELC`) to the `ExactComputer` [#182](https://github.com/mmschlk/shapiq/issues/182)
|
|
36
|
+
- adds `waterfall_plot` [#34](https://github.com/mmschlk/shapiq/issues/34) that visualizes the contributions of features to the model prediction
|
|
37
|
+
- adds `BaselineImputer` [#107](https://github.com/mmschlk/shapiq/issues/107) which is now responsible for handling the `sample_replacements` parameter. Added a DeprecationWarning for the parameter in `MarginalImputer`, which will be removed in the next release.
|
|
38
|
+
- adds `joint_marginal_distribution` parameter to `MarginalImputer` with default value `True` [#261](https://github.com/mmschlk/shapiq/issues/261)
|
|
39
|
+
- renames explanation graph to `si_graph`
|
|
40
|
+
- `get_n_order` now has optional lower/upper limits for the order
|
|
41
|
+
- computing metrics for benchmarking now tries to resolve not-matching interaction indices and will throw a warning instead of a ValueError [#179](https://github.com/mmschlk/shapiq/issues/179)
|
|
42
|
+
- add a legend to benchmark plots [#170](https://github.com/mmschlk/shapiq/issues/170)
|
|
43
|
+
- refactored the `shapiq.games.benchmark` module into a separate `shapiq.benchmark` module by moving all but the benchmark games into the new module. This closes [#169](https://github.com/mmschlk/shapiq/issues/169) and makes benchmarking more flexible and convenient.
|
|
44
|
+
- a `shapiq.Game` can now be called more intuitively with coalitions data types (tuples of int or str) and also allows to add `player_names` to the game at initialization [#183](https://github.com/mmschlk/shapiq/issues/183)
|
|
45
|
+
- improve tests across the package
|
|
46
|
+
|
|
47
|
+
#### Documentation
|
|
48
|
+
- adds a notebook showing how to use custom tree models with the `TreeExplainer` [#66](https://github.com/mmschlk/shapiq/issues/66)
|
|
49
|
+
- adds a notebook show how to use the `shapiq.Game` API to create custom games [#184](https://github.com/mmschlk/shapiq/issues/184)
|
|
50
|
+
- adds a notebook showing hot to visualize interactions [#252](https://github.com/mmschlk/shapiq/issues/252)
|
|
51
|
+
- adds a notebook showing how to compute Shapley values with `shapiq` [#193](https://github.com/mmschlk/shapiq/issues/197)
|
|
52
|
+
- adds a notebook for conducting data valuation [#190](https://github.com/mmschlk/shapiq/issues/190)
|
|
53
|
+
- adds a notebook showcasing introducing the Core and how to compute it with `shapiq` [#191](https://github.com/mmschlk/shapiq/issues/191)
|
|
54
|
+
|
|
55
|
+
#### Bug Fixes
|
|
56
|
+
- fixes a bug with SIs not adding up to the model prediction because of wrong values in the empty set [#264](https://github.com/mmschlk/shapiq/issues/264)
|
|
57
|
+
- fixes a bug that `TreeExplainer` did not have the correct baseline_value when using XGBoost models [#250](https://github.com/mmschlk/shapiq/issues/250)
|
|
58
|
+
- fixes the force plot not showing and its baseline value
|
|
59
|
+
|
|
60
|
+
### v1.0.1 (2024-06-05)
|
|
61
|
+
|
|
62
|
+
- add `max_order=1` to `TabularExplainer` and `TreeExplainer`
|
|
63
|
+
- fix `TreeExplainer.explain_X(..., n_jobs=2, random_state=0)`
|
|
64
|
+
|
|
65
|
+
### v1.0.0 (2024-06-04)
|
|
66
|
+
|
|
67
|
+
Major release of the `shapiq` Python package including (among others):
|
|
68
|
+
|
|
69
|
+
- `approximator` module implements over 10 approximators of Shapley values and interaction indices.
|
|
70
|
+
- `exact` module implements a computer for over 10 game theoretic concepts like interaction indices or generalized values.
|
|
71
|
+
- `games` module implements over 10 application benchmarks for the approximators.
|
|
72
|
+
- `explainer` module includes a `TabularExplainer` and `TreeExplainer` for any-order feature interactions of machine learning model predictions.
|
|
73
|
+
- `interaction_values` module implements a data class to store and analyze interaction values.
|
|
74
|
+
- `plot` module allows visualizing interaction values.
|
|
75
|
+
- `datasets` module loads datasets for testing and examples.
|
|
76
|
+
|
|
77
|
+
Documentation of `shapiq` with tutorials and API reference is available at https://shapiq.readthedocs.io
|
shapiq-1.2.0/MANIFEST.in
ADDED
shapiq-1.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: shapiq
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Shapley Interactions for Machine Learning
|
|
5
|
+
Home-page: https://github.com/mmschlk/shapiq
|
|
6
|
+
Author: Maximilian Muschalik et al.
|
|
7
|
+
Author-email: maximilian.muschalik@ifi.lmu.de
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Tracker, https://github.com/mmschlk/shapiq/issues
|
|
10
|
+
Project-URL: Source, https://github.com/mmschlk/shapiq
|
|
11
|
+
Project-URL: Documentation, https://shapiq.readthedocs.io
|
|
12
|
+
Keywords: python,machine learning,interpretable machine learning,shap,xai,explainable ai,interaction,shapley interactions,shapley values,feature interaction
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Programming Language :: Python
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Requires-Python: >=3.9.0
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: numpy
|
|
28
|
+
Requires-Dist: scipy
|
|
29
|
+
Requires-Dist: pandas
|
|
30
|
+
Requires-Dist: scikit-learn
|
|
31
|
+
Requires-Dist: tqdm
|
|
32
|
+
Requires-Dist: requests
|
|
33
|
+
Requires-Dist: matplotlib
|
|
34
|
+
Requires-Dist: colour
|
|
35
|
+
Requires-Dist: networkx
|
|
36
|
+
Provides-Extra: docs
|
|
37
|
+
Requires-Dist: numpy; extra == "docs"
|
|
38
|
+
Requires-Dist: scipy; extra == "docs"
|
|
39
|
+
Requires-Dist: pandas; extra == "docs"
|
|
40
|
+
Requires-Dist: scikit-learn; extra == "docs"
|
|
41
|
+
Requires-Dist: tqdm; extra == "docs"
|
|
42
|
+
Requires-Dist: requests; extra == "docs"
|
|
43
|
+
Requires-Dist: matplotlib; extra == "docs"
|
|
44
|
+
Requires-Dist: colour; extra == "docs"
|
|
45
|
+
Requires-Dist: networkx; extra == "docs"
|
|
46
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
47
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
|
|
48
|
+
Requires-Dist: sphinx_rtd_theme; extra == "docs"
|
|
49
|
+
Requires-Dist: sphinx_toolbox; extra == "docs"
|
|
50
|
+
Requires-Dist: nbsphinx; extra == "docs"
|
|
51
|
+
Requires-Dist: pandoc; extra == "docs"
|
|
52
|
+
Requires-Dist: furo; extra == "docs"
|
|
53
|
+
Requires-Dist: sphinx-copybutton; extra == "docs"
|
|
54
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
55
|
+
Provides-Extra: dev
|
|
56
|
+
Requires-Dist: numpy; extra == "dev"
|
|
57
|
+
Requires-Dist: scipy; extra == "dev"
|
|
58
|
+
Requires-Dist: pandas; extra == "dev"
|
|
59
|
+
Requires-Dist: scikit-learn; extra == "dev"
|
|
60
|
+
Requires-Dist: tqdm; extra == "dev"
|
|
61
|
+
Requires-Dist: requests; extra == "dev"
|
|
62
|
+
Requires-Dist: matplotlib; extra == "dev"
|
|
63
|
+
Requires-Dist: colour; extra == "dev"
|
|
64
|
+
Requires-Dist: networkx; extra == "dev"
|
|
65
|
+
Requires-Dist: sphinx; extra == "dev"
|
|
66
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == "dev"
|
|
67
|
+
Requires-Dist: sphinx_rtd_theme; extra == "dev"
|
|
68
|
+
Requires-Dist: sphinx_toolbox; extra == "dev"
|
|
69
|
+
Requires-Dist: nbsphinx; extra == "dev"
|
|
70
|
+
Requires-Dist: pandoc; extra == "dev"
|
|
71
|
+
Requires-Dist: furo; extra == "dev"
|
|
72
|
+
Requires-Dist: sphinx-copybutton; extra == "dev"
|
|
73
|
+
Requires-Dist: myst-parser; extra == "dev"
|
|
74
|
+
Requires-Dist: build; extra == "dev"
|
|
75
|
+
Requires-Dist: black; extra == "dev"
|
|
76
|
+
Requires-Dist: pytest; extra == "dev"
|
|
77
|
+
Requires-Dist: coverage; extra == "dev"
|
|
78
|
+
Dynamic: author
|
|
79
|
+
Dynamic: author-email
|
|
80
|
+
Dynamic: classifier
|
|
81
|
+
Dynamic: description
|
|
82
|
+
Dynamic: description-content-type
|
|
83
|
+
Dynamic: home-page
|
|
84
|
+
Dynamic: keywords
|
|
85
|
+
Dynamic: license
|
|
86
|
+
Dynamic: project-url
|
|
87
|
+
Dynamic: provides-extra
|
|
88
|
+
Dynamic: requires-dist
|
|
89
|
+
Dynamic: requires-python
|
|
90
|
+
Dynamic: summary
|
|
91
|
+
|
|
92
|
+
# shapiq: Shapley Interactions for Machine Learning <img src="https://raw.githubusercontent.com/mmschlk/shapiq/main/docs/source/_static/logo/logo_shapiq_light.svg" alt="shapiq_logo" align="right" height="250px"/>
|
|
93
|
+
|
|
94
|
+
[](https://opensource.org/licenses/MIT)
|
|
95
|
+
[](https://coveralls.io/github/mmschlk/shapiq?branch=main)
|
|
96
|
+
[](https://github.com/mmschlk/shapiq/actions/workflows/unit-tests.yml)
|
|
97
|
+
[](https://shapiq.readthedocs.io/en/latest/?badge=latest)
|
|
98
|
+
|
|
99
|
+
[](https://pypi.org/project/shapiq)
|
|
100
|
+
[](https://pypi.org/project/shapiq)
|
|
101
|
+
[](https://pepy.tech/project/shapiq)
|
|
102
|
+
|
|
103
|
+
[](https://github.com/psf/black)
|
|
104
|
+
|
|
105
|
+
> An interaction may speak more than a thousand main effects.
|
|
106
|
+
|
|
107
|
+
Shapley Interaction Quantification (`shapiq`) is a Python package for (1) approximating any-order Shapley interactions, (2) benchmarking game-theoretical algorithms for machine learning, (3) explaining feature interactions of model predictions. `shapiq` extends the well-known [shap](https://github.com/shap/shap) package for both researchers working on game theory in machine learning, as well as the end-users explaining models. SHAP-IQ extends individual Shapley values by quantifying the **synergy** effect between entities (aka **players** in the jargon of game theory) like explanatory features, data points, or weak learners in ensemble models. Synergies between players give a more comprehensive view of machine learning models.
|
|
108
|
+
|
|
109
|
+
## 🛠️ Install
|
|
110
|
+
`shapiq` is intended to work with **Python 3.9 and above**. Installation can be done via `pip`:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
pip install shapiq
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## ⭐ Quickstart
|
|
117
|
+
|
|
118
|
+
You can explain your model with `shapiq.explainer` and visualize Shapley interactions with `shapiq.plot`.
|
|
119
|
+
If you are interested in the underlying game theoretic algorithms, then check out the `shapiq.approximator` and `shapiq.games` modules.
|
|
120
|
+
|
|
121
|
+
### Compute any-order feature interactions
|
|
122
|
+
|
|
123
|
+
Explain your models with Shapley interactions:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
import shapiq
|
|
127
|
+
# load data
|
|
128
|
+
X, y = shapiq.load_california_housing(to_numpy=True)
|
|
129
|
+
# train a model
|
|
130
|
+
from sklearn.ensemble import RandomForestRegressor
|
|
131
|
+
model = RandomForestRegressor()
|
|
132
|
+
model.fit(X, y)
|
|
133
|
+
# set up an explainer with k-SII interaction values up to order 4
|
|
134
|
+
explainer = shapiq.TabularExplainer(
|
|
135
|
+
model=model,
|
|
136
|
+
data=X,
|
|
137
|
+
index="k-SII",
|
|
138
|
+
max_order=4
|
|
139
|
+
)
|
|
140
|
+
# explain the model's prediction for the first sample
|
|
141
|
+
interaction_values = explainer.explain(X[0], budget=256)
|
|
142
|
+
# analyse interaction values
|
|
143
|
+
print(interaction_values)
|
|
144
|
+
|
|
145
|
+
>> InteractionValues(
|
|
146
|
+
>> index=k-SII, max_order=4, min_order=0, estimated=False,
|
|
147
|
+
>> estimation_budget=256, n_players=8, baseline_value=2.07282292,
|
|
148
|
+
>> Top 10 interactions:
|
|
149
|
+
>> (0,): 1.696969079 # attribution of feature 0
|
|
150
|
+
>> (0, 5): 0.4847876
|
|
151
|
+
>> (0, 1): 0.4494288 # interaction between features 0 & 1
|
|
152
|
+
>> (0, 6): 0.4477677
|
|
153
|
+
>> (1, 5): 0.3750034
|
|
154
|
+
>> (4, 5): 0.3468325
|
|
155
|
+
>> (0, 3, 6): -0.320 # interaction between features 0 & 3 & 6
|
|
156
|
+
>> (2, 3, 6): -0.329
|
|
157
|
+
>> (0, 1, 5): -0.363
|
|
158
|
+
>> (6,): -0.56358890
|
|
159
|
+
>> )
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Compute Shapley values like you are used to with SHAP
|
|
163
|
+
|
|
164
|
+
If you are used to working with SHAP, you can also compute Shapley values with `shapiq` the same way:
|
|
165
|
+
You can load your data and model, and then use the `shapiq.Explainer` to compute Shapley values.
|
|
166
|
+
If you set the index to ``'SV'``, you will get the Shapley values as you know them from SHAP.
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
import shapiq
|
|
170
|
+
|
|
171
|
+
data, model = ... # get your data and model
|
|
172
|
+
explainer = shapiq.Explainer(
|
|
173
|
+
model=model,
|
|
174
|
+
data=data,
|
|
175
|
+
index="SV", # Shapley values
|
|
176
|
+
)
|
|
177
|
+
shapley_values = explainer.explain(data[0])
|
|
178
|
+
shapley_values.plot_force(feature_names=...)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Once you have the Shapley values, you can easily compute Interaction values as well:
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
explainer = shapiq.Explainer(
|
|
185
|
+
model=model,
|
|
186
|
+
data=data,
|
|
187
|
+
index="k-SII", # k-SII interaction values
|
|
188
|
+
max_order=2 # specify any order you want
|
|
189
|
+
)
|
|
190
|
+
interaction_values = explainer.explain(data[0])
|
|
191
|
+
interaction_values.plot_force(feature_names=...)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
<p align="center">
|
|
195
|
+
<img width="800px" src="https://raw.githubusercontent.com/mmschlk/shapiq/main/docs/source/_static/images/motivation_sv_and_si.png" alt="An example Force Plot for the California Housing Dataset with Shapley Interactions">
|
|
196
|
+
</p>
|
|
197
|
+
|
|
198
|
+
### Visualize feature interactions
|
|
199
|
+
|
|
200
|
+
A handy way of visualizing interaction scores up to order 2 are network plots.
|
|
201
|
+
You can see an example of such a plot below.
|
|
202
|
+
The nodes represent feature **attributions** and the edges represent the **interactions** between features.
|
|
203
|
+
The strength and size of the nodes and edges are proportional to the absolute value of attributions and interactions, respectively.
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
shapiq.network_plot(
|
|
207
|
+
first_order_values=interaction_values.get_n_order_values(1),
|
|
208
|
+
second_order_values=interaction_values.get_n_order_values(2)
|
|
209
|
+
)
|
|
210
|
+
# or use
|
|
211
|
+
interaction_values.plot_network()
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
The pseudo-code above can produce the following plot (here also an image is added):
|
|
215
|
+
|
|
216
|
+
<p align="center">
|
|
217
|
+
<img width="500px" src="https://raw.githubusercontent.com/mmschlk/shapiq/main/docs/source/_static/network_example2.png" alt="network_plot_example">
|
|
218
|
+
</p>
|
|
219
|
+
|
|
220
|
+
### Explain TabPFN
|
|
221
|
+
|
|
222
|
+
With ``shapiq`` you can also [``TabPFN``](https://github.com/PriorLabs/TabPFN) by making use of the _remove-and-recontextualize_ explanation paradigm implemented in ``shapiq.TabPFNExplainer``.
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
import tabpfn, shapiq
|
|
226
|
+
data, labels = ... # load your data
|
|
227
|
+
model = tabpfn.TabPFNClassifier() # get TabPFN
|
|
228
|
+
model.fit(data, labels) # "fit" TabPFN (optional)
|
|
229
|
+
explainer = shapiq.TabPFNExplainer( # setup the explainer
|
|
230
|
+
model=model,
|
|
231
|
+
data=data,
|
|
232
|
+
labels=labels,
|
|
233
|
+
index="FSII"
|
|
234
|
+
)
|
|
235
|
+
fsii_values = explainer.explain(X[0]) # explain with Faithful Shapley values
|
|
236
|
+
fsii_values.plot_force() # plot the force plot
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
<p align="center">
|
|
240
|
+
<img width="800px" src="https://raw.githubusercontent.com/mmschlk/shapiq/main/docs/source/_static/images/fsii_tabpfn_force_plot_example.png" alt="Force Plot of FSII values as derived from the example tabpfn notebook">
|
|
241
|
+
</p>
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
## 📖 Documentation with tutorials
|
|
245
|
+
The documentation of ``shapiq`` can be found at https://shapiq.readthedocs.io.
|
|
246
|
+
If you are new to Shapley values or Shapley interactions, we recommend starting with the [introduction](https://shapiq.readthedocs.io/en/latest/introduction/) and the [basic tutorials](https://shapiq.readthedocs.io/en/latest/notebooks/basics.html).
|
|
247
|
+
There is a lot of great resources available to get you started with Shapley values and interactions.
|
|
248
|
+
|
|
249
|
+
## 💬 Citation
|
|
250
|
+
|
|
251
|
+
If you use ``shapiq`` and enjoy it, please consider citing our [NeurIPS paper](https://arxiv.org/abs/2410.01649) or consider starring this repository.
|
|
252
|
+
|
|
253
|
+
```bibtex
|
|
254
|
+
@inproceedings{muschalik2024shapiq,
|
|
255
|
+
title = {shapiq: Shapley Interactions for Machine Learning},
|
|
256
|
+
author = {Maximilian Muschalik and Hubert Baniecki and Fabian Fumagalli and
|
|
257
|
+
Patrick Kolpaczki and Barbara Hammer and Eyke H\"{u}llermeier},
|
|
258
|
+
booktitle = {The Thirty-eight Conference on Neural Information Processing Systems Datasets and Benchmarks Track},
|
|
259
|
+
year = {2024},
|
|
260
|
+
url = {https://openreview.net/forum?id=knxGmi6SJi}
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## 📦 Contributing
|
|
265
|
+
We welcome any kind of contributions to `shapiq`!
|
|
266
|
+
If you are interested in contributing, please check out our [contributing guidelines](https://github.com/mmschlk/shapiq/blob/main/.github/CONTRIBUTING.md).
|
|
267
|
+
If you have any questions, feel free to reach out to us.
|
|
268
|
+
We are tracking our progress via a [project board](https://github.com/users/mmschlk/projects/4) and the [issues](https://github.com/mmschlk/shapiq/issues) section.
|
|
269
|
+
If you find a bug or have a feature request, please open an issue or help us fixing it by opening a pull request.
|
|
270
|
+
|
|
271
|
+
## 📜 License
|
|
272
|
+
This project is licensed under the [MIT License](https://github.com/mmschlk/shapiq/blob/main/LICENSE).
|
|
273
|
+
|
|
274
|
+
## 💰 Funding
|
|
275
|
+
This work is openly available under the MIT license.
|
|
276
|
+
Some authors acknowledge the financial support by the German Research Foundation (DFG) under grant number TRR 318/1 2021 – 438445824.
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
Built with ❤️ by the shapiq team.
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
## Changelog
|
|
283
|
+
|
|
284
|
+
### Development
|
|
285
|
+
...
|
|
286
|
+
|
|
287
|
+
### v1.2.0 (2025-01-15)
|
|
288
|
+
- adds ``shapiq.TabPFNExplainer`` as a specialized version of the ``shapiq.TabularExplainer`` which offers a streamlined variant of the explainer for the TabPFN model [#301](https://github.com/mmschlk/shapiq/issues/301)
|
|
289
|
+
- handles ``explainer.explain()`` now through a common interface for all explainer classes which now need to implement a ``explain_function()`` method
|
|
290
|
+
- adds the baseline_value into the InteractionValues object's value storage for the ``()`` interaction if ``min_order=0`` (default usually) for all indices that are not ``SII```(SII has another baseline value) such that the values are efficient (sum up to the model prediction) without the awkward handling of the baseline_value attribute
|
|
291
|
+
- renames ``game_fun`` parameter in ``shapiq.ExactComputer`` to ``game`` [#297](https://github.com/mmschlk/shapiq/issues/297)
|
|
292
|
+
- adds a TabPFN example notebook to the documentation
|
|
293
|
+
- removes warning when class_index is not provided in explainers [#298](https://github.com/mmschlk/shapiq/issues/298)
|
|
294
|
+
- adds the `sentence_plot` function to the `plot` module to visualize the contributions of words to a language model prediction in a sentence-like format
|
|
295
|
+
- makes abbreviations in the `plot` module optional [#281](https://github.com/mmschlk/shapiq/issues/281)
|
|
296
|
+
- adds the `upset_plot` function to the `plot` module to visualize the interactions of higher-order [#290](https://github.com/mmschlk/shapiq/issues/290)
|
|
297
|
+
- adds support for IsoForest models to explainer and tree explainer [#278](https://github.com/mmschlk/shapiq/issues/278)
|
|
298
|
+
- adds support for sub-selection of players in the interaction values data class [#276](https://github.com/mmschlk/shapiq/issues/276) which allows retrieving interaction values for a subset of players
|
|
299
|
+
- refactors game theory computations like `ExactComputer`, `MoebiusConverter`, `core`, among others to be more modular and flexible into the `game_theory` module [#258](https://github.com/mmschlk/shapiq/issues/258)
|
|
300
|
+
- improves quality of the tests by adding many more semantic tests to the different interaction indices and computations [#285](https://github.com/mmschlk/shapiq/pull/285)
|
|
301
|
+
|
|
302
|
+
### v1.1.1 (2024-11-13)
|
|
303
|
+
|
|
304
|
+
#### Improvements and Ease of Use
|
|
305
|
+
- adds a `class_index` parameter to `TabularExplainer` and `Explainer` to specify the class index to be explained for classification models [#271](https://github.com/mmschlk/shapiq/issues/271) (renames `class_label` parameter in TreeExplainer to `class_index`)
|
|
306
|
+
- adds support for `PyTorch` models to `Explainer` [#272](https://github.com/mmschlk/shapiq/issues/272)
|
|
307
|
+
- adds new tests comparing `shapiq` outputs for SVs with alues computed with `shap`
|
|
308
|
+
- adds new tests for checking `shapiq` explainers with different types of models
|
|
309
|
+
|
|
310
|
+
#### Bug Fixes
|
|
311
|
+
- fixes a bug that `RandomForestClassifier` models were not working with the `TreeExplainer` [#273](https://github.com/mmschlk/shapiq/issues/273)
|
|
312
|
+
|
|
313
|
+
### v1.1.0 (2024-11-07)
|
|
314
|
+
|
|
315
|
+
#### New Features and Improvements
|
|
316
|
+
- adds computation of the Egalitarian Core (`EC`) and Egalitarian Least-Core (`ELC`) to the `ExactComputer` [#182](https://github.com/mmschlk/shapiq/issues/182)
|
|
317
|
+
- adds `waterfall_plot` [#34](https://github.com/mmschlk/shapiq/issues/34) that visualizes the contributions of features to the model prediction
|
|
318
|
+
- adds `BaselineImputer` [#107](https://github.com/mmschlk/shapiq/issues/107) which is now responsible for handling the `sample_replacements` parameter. Added a DeprecationWarning for the parameter in `MarginalImputer`, which will be removed in the next release.
|
|
319
|
+
- adds `joint_marginal_distribution` parameter to `MarginalImputer` with default value `True` [#261](https://github.com/mmschlk/shapiq/issues/261)
|
|
320
|
+
- renames explanation graph to `si_graph`
|
|
321
|
+
- `get_n_order` now has optional lower/upper limits for the order
|
|
322
|
+
- computing metrics for benchmarking now tries to resolve not-matching interaction indices and will throw a warning instead of a ValueError [#179](https://github.com/mmschlk/shapiq/issues/179)
|
|
323
|
+
- add a legend to benchmark plots [#170](https://github.com/mmschlk/shapiq/issues/170)
|
|
324
|
+
- refactored the `shapiq.games.benchmark` module into a separate `shapiq.benchmark` module by moving all but the benchmark games into the new module. This closes [#169](https://github.com/mmschlk/shapiq/issues/169) and makes benchmarking more flexible and convenient.
|
|
325
|
+
- a `shapiq.Game` can now be called more intuitively with coalitions data types (tuples of int or str) and also allows to add `player_names` to the game at initialization [#183](https://github.com/mmschlk/shapiq/issues/183)
|
|
326
|
+
- improve tests across the package
|
|
327
|
+
|
|
328
|
+
#### Documentation
|
|
329
|
+
- adds a notebook showing how to use custom tree models with the `TreeExplainer` [#66](https://github.com/mmschlk/shapiq/issues/66)
|
|
330
|
+
- adds a notebook show how to use the `shapiq.Game` API to create custom games [#184](https://github.com/mmschlk/shapiq/issues/184)
|
|
331
|
+
- adds a notebook showing hot to visualize interactions [#252](https://github.com/mmschlk/shapiq/issues/252)
|
|
332
|
+
- adds a notebook showing how to compute Shapley values with `shapiq` [#193](https://github.com/mmschlk/shapiq/issues/197)
|
|
333
|
+
- adds a notebook for conducting data valuation [#190](https://github.com/mmschlk/shapiq/issues/190)
|
|
334
|
+
- adds a notebook showcasing introducing the Core and how to compute it with `shapiq` [#191](https://github.com/mmschlk/shapiq/issues/191)
|
|
335
|
+
|
|
336
|
+
#### Bug Fixes
|
|
337
|
+
- fixes a bug with SIs not adding up to the model prediction because of wrong values in the empty set [#264](https://github.com/mmschlk/shapiq/issues/264)
|
|
338
|
+
- fixes a bug that `TreeExplainer` did not have the correct baseline_value when using XGBoost models [#250](https://github.com/mmschlk/shapiq/issues/250)
|
|
339
|
+
- fixes the force plot not showing and its baseline value
|
|
340
|
+
|
|
341
|
+
### v1.0.1 (2024-06-05)
|
|
342
|
+
|
|
343
|
+
- add `max_order=1` to `TabularExplainer` and `TreeExplainer`
|
|
344
|
+
- fix `TreeExplainer.explain_X(..., n_jobs=2, random_state=0)`
|
|
345
|
+
|
|
346
|
+
### v1.0.0 (2024-06-04)
|
|
347
|
+
|
|
348
|
+
Major release of the `shapiq` Python package including (among others):
|
|
349
|
+
|
|
350
|
+
- `approximator` module implements over 10 approximators of Shapley values and interaction indices.
|
|
351
|
+
- `exact` module implements a computer for over 10 game theoretic concepts like interaction indices or generalized values.
|
|
352
|
+
- `games` module implements over 10 application benchmarks for the approximators.
|
|
353
|
+
- `explainer` module includes a `TabularExplainer` and `TreeExplainer` for any-order feature interactions of machine learning model predictions.
|
|
354
|
+
- `interaction_values` module implements a data class to store and analyze interaction values.
|
|
355
|
+
- `plot` module allows visualizing interaction values.
|
|
356
|
+
- `datasets` module loads datasets for testing and examples.
|
|
357
|
+
|
|
358
|
+
Documentation of `shapiq` with tutorials and API reference is available at https://shapiq.readthedocs.io
|
shapiq-1.2.0/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# shapiq: Shapley Interactions for Machine Learning <img src="https://raw.githubusercontent.com/mmschlk/shapiq/main/docs/source/_static/logo/logo_shapiq_light.svg" alt="shapiq_logo" align="right" height="250px"/>
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://coveralls.io/github/mmschlk/shapiq?branch=main)
|
|
5
|
+
[](https://github.com/mmschlk/shapiq/actions/workflows/unit-tests.yml)
|
|
6
|
+
[](https://shapiq.readthedocs.io/en/latest/?badge=latest)
|
|
7
|
+
|
|
8
|
+
[](https://pypi.org/project/shapiq)
|
|
9
|
+
[](https://pypi.org/project/shapiq)
|
|
10
|
+
[](https://pepy.tech/project/shapiq)
|
|
11
|
+
|
|
12
|
+
[](https://github.com/psf/black)
|
|
13
|
+
|
|
14
|
+
> An interaction may speak more than a thousand main effects.
|
|
15
|
+
|
|
16
|
+
Shapley Interaction Quantification (`shapiq`) is a Python package for (1) approximating any-order Shapley interactions, (2) benchmarking game-theoretical algorithms for machine learning, (3) explaining feature interactions of model predictions. `shapiq` extends the well-known [shap](https://github.com/shap/shap) package for both researchers working on game theory in machine learning, as well as the end-users explaining models. SHAP-IQ extends individual Shapley values by quantifying the **synergy** effect between entities (aka **players** in the jargon of game theory) like explanatory features, data points, or weak learners in ensemble models. Synergies between players give a more comprehensive view of machine learning models.
|
|
17
|
+
|
|
18
|
+
## 🛠️ Install
|
|
19
|
+
`shapiq` is intended to work with **Python 3.9 and above**. Installation can be done via `pip`:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install shapiq
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## ⭐ Quickstart
|
|
26
|
+
|
|
27
|
+
You can explain your model with `shapiq.explainer` and visualize Shapley interactions with `shapiq.plot`.
|
|
28
|
+
If you are interested in the underlying game theoretic algorithms, then check out the `shapiq.approximator` and `shapiq.games` modules.
|
|
29
|
+
|
|
30
|
+
### Compute any-order feature interactions
|
|
31
|
+
|
|
32
|
+
Explain your models with Shapley interactions:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import shapiq
|
|
36
|
+
# load data
|
|
37
|
+
X, y = shapiq.load_california_housing(to_numpy=True)
|
|
38
|
+
# train a model
|
|
39
|
+
from sklearn.ensemble import RandomForestRegressor
|
|
40
|
+
model = RandomForestRegressor()
|
|
41
|
+
model.fit(X, y)
|
|
42
|
+
# set up an explainer with k-SII interaction values up to order 4
|
|
43
|
+
explainer = shapiq.TabularExplainer(
|
|
44
|
+
model=model,
|
|
45
|
+
data=X,
|
|
46
|
+
index="k-SII",
|
|
47
|
+
max_order=4
|
|
48
|
+
)
|
|
49
|
+
# explain the model's prediction for the first sample
|
|
50
|
+
interaction_values = explainer.explain(X[0], budget=256)
|
|
51
|
+
# analyse interaction values
|
|
52
|
+
print(interaction_values)
|
|
53
|
+
|
|
54
|
+
>> InteractionValues(
|
|
55
|
+
>> index=k-SII, max_order=4, min_order=0, estimated=False,
|
|
56
|
+
>> estimation_budget=256, n_players=8, baseline_value=2.07282292,
|
|
57
|
+
>> Top 10 interactions:
|
|
58
|
+
>> (0,): 1.696969079 # attribution of feature 0
|
|
59
|
+
>> (0, 5): 0.4847876
|
|
60
|
+
>> (0, 1): 0.4494288 # interaction between features 0 & 1
|
|
61
|
+
>> (0, 6): 0.4477677
|
|
62
|
+
>> (1, 5): 0.3750034
|
|
63
|
+
>> (4, 5): 0.3468325
|
|
64
|
+
>> (0, 3, 6): -0.320 # interaction between features 0 & 3 & 6
|
|
65
|
+
>> (2, 3, 6): -0.329
|
|
66
|
+
>> (0, 1, 5): -0.363
|
|
67
|
+
>> (6,): -0.56358890
|
|
68
|
+
>> )
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Compute Shapley values like you are used to with SHAP
|
|
72
|
+
|
|
73
|
+
If you are used to working with SHAP, you can also compute Shapley values with `shapiq` the same way:
|
|
74
|
+
You can load your data and model, and then use the `shapiq.Explainer` to compute Shapley values.
|
|
75
|
+
If you set the index to ``'SV'``, you will get the Shapley values as you know them from SHAP.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import shapiq
|
|
79
|
+
|
|
80
|
+
data, model = ... # get your data and model
|
|
81
|
+
explainer = shapiq.Explainer(
|
|
82
|
+
model=model,
|
|
83
|
+
data=data,
|
|
84
|
+
index="SV", # Shapley values
|
|
85
|
+
)
|
|
86
|
+
shapley_values = explainer.explain(data[0])
|
|
87
|
+
shapley_values.plot_force(feature_names=...)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Once you have the Shapley values, you can easily compute Interaction values as well:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
explainer = shapiq.Explainer(
|
|
94
|
+
model=model,
|
|
95
|
+
data=data,
|
|
96
|
+
index="k-SII", # k-SII interaction values
|
|
97
|
+
max_order=2 # specify any order you want
|
|
98
|
+
)
|
|
99
|
+
interaction_values = explainer.explain(data[0])
|
|
100
|
+
interaction_values.plot_force(feature_names=...)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
<p align="center">
|
|
104
|
+
<img width="800px" src="https://raw.githubusercontent.com/mmschlk/shapiq/main/docs/source/_static/images/motivation_sv_and_si.png" alt="An example Force Plot for the California Housing Dataset with Shapley Interactions">
|
|
105
|
+
</p>
|
|
106
|
+
|
|
107
|
+
### Visualize feature interactions
|
|
108
|
+
|
|
109
|
+
A handy way of visualizing interaction scores up to order 2 are network plots.
|
|
110
|
+
You can see an example of such a plot below.
|
|
111
|
+
The nodes represent feature **attributions** and the edges represent the **interactions** between features.
|
|
112
|
+
The strength and size of the nodes and edges are proportional to the absolute value of attributions and interactions, respectively.
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
shapiq.network_plot(
|
|
116
|
+
first_order_values=interaction_values.get_n_order_values(1),
|
|
117
|
+
second_order_values=interaction_values.get_n_order_values(2)
|
|
118
|
+
)
|
|
119
|
+
# or use
|
|
120
|
+
interaction_values.plot_network()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The pseudo-code above can produce the following plot (here also an image is added):
|
|
124
|
+
|
|
125
|
+
<p align="center">
|
|
126
|
+
<img width="500px" src="https://raw.githubusercontent.com/mmschlk/shapiq/main/docs/source/_static/network_example2.png" alt="network_plot_example">
|
|
127
|
+
</p>
|
|
128
|
+
|
|
129
|
+
### Explain TabPFN
|
|
130
|
+
|
|
131
|
+
With ``shapiq`` you can also [``TabPFN``](https://github.com/PriorLabs/TabPFN) by making use of the _remove-and-recontextualize_ explanation paradigm implemented in ``shapiq.TabPFNExplainer``.
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
import tabpfn, shapiq
|
|
135
|
+
data, labels = ... # load your data
|
|
136
|
+
model = tabpfn.TabPFNClassifier() # get TabPFN
|
|
137
|
+
model.fit(data, labels) # "fit" TabPFN (optional)
|
|
138
|
+
explainer = shapiq.TabPFNExplainer( # setup the explainer
|
|
139
|
+
model=model,
|
|
140
|
+
data=data,
|
|
141
|
+
labels=labels,
|
|
142
|
+
index="FSII"
|
|
143
|
+
)
|
|
144
|
+
fsii_values = explainer.explain(X[0]) # explain with Faithful Shapley values
|
|
145
|
+
fsii_values.plot_force() # plot the force plot
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
<p align="center">
|
|
149
|
+
<img width="800px" src="https://raw.githubusercontent.com/mmschlk/shapiq/main/docs/source/_static/images/fsii_tabpfn_force_plot_example.png" alt="Force Plot of FSII values as derived from the example tabpfn notebook">
|
|
150
|
+
</p>
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
## 📖 Documentation with tutorials
|
|
154
|
+
The documentation of ``shapiq`` can be found at https://shapiq.readthedocs.io.
|
|
155
|
+
If you are new to Shapley values or Shapley interactions, we recommend starting with the [introduction](https://shapiq.readthedocs.io/en/latest/introduction/) and the [basic tutorials](https://shapiq.readthedocs.io/en/latest/notebooks/basics.html).
|
|
156
|
+
There is a lot of great resources available to get you started with Shapley values and interactions.
|
|
157
|
+
|
|
158
|
+
## 💬 Citation
|
|
159
|
+
|
|
160
|
+
If you use ``shapiq`` and enjoy it, please consider citing our [NeurIPS paper](https://arxiv.org/abs/2410.01649) or consider starring this repository.
|
|
161
|
+
|
|
162
|
+
```bibtex
|
|
163
|
+
@inproceedings{muschalik2024shapiq,
|
|
164
|
+
title = {shapiq: Shapley Interactions for Machine Learning},
|
|
165
|
+
author = {Maximilian Muschalik and Hubert Baniecki and Fabian Fumagalli and
|
|
166
|
+
Patrick Kolpaczki and Barbara Hammer and Eyke H\"{u}llermeier},
|
|
167
|
+
booktitle = {The Thirty-eight Conference on Neural Information Processing Systems Datasets and Benchmarks Track},
|
|
168
|
+
year = {2024},
|
|
169
|
+
url = {https://openreview.net/forum?id=knxGmi6SJi}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 📦 Contributing
|
|
174
|
+
We welcome any kind of contributions to `shapiq`!
|
|
175
|
+
If you are interested in contributing, please check out our [contributing guidelines](https://github.com/mmschlk/shapiq/blob/main/.github/CONTRIBUTING.md).
|
|
176
|
+
If you have any questions, feel free to reach out to us.
|
|
177
|
+
We are tracking our progress via a [project board](https://github.com/users/mmschlk/projects/4) and the [issues](https://github.com/mmschlk/shapiq/issues) section.
|
|
178
|
+
If you find a bug or have a feature request, please open an issue or help us fixing it by opening a pull request.
|
|
179
|
+
|
|
180
|
+
## 📜 License
|
|
181
|
+
This project is licensed under the [MIT License](https://github.com/mmschlk/shapiq/blob/main/LICENSE).
|
|
182
|
+
|
|
183
|
+
## 💰 Funding
|
|
184
|
+
This work is openly available under the MIT license.
|
|
185
|
+
Some authors acknowledge the financial support by the German Research Foundation (DFG) under grant number TRR 318/1 2021 – 438445824.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
Built with ❤️ by the shapiq team.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[tool.pytest.ini_options]
|
|
6
|
+
testpaths = "tests"
|
|
7
|
+
|
|
8
|
+
[tool.black]
|
|
9
|
+
line-length = 100
|
|
10
|
+
target-version = ['py39', 'py310', 'py311']
|
|
11
|
+
|
|
12
|
+
[tool.ruff]
|
|
13
|
+
lint.select = ["E", "F", "I", "UP"] # https://beta.ruff.rs/docs/rules/
|
|
14
|
+
lint.ignore = ["E501"]
|
|
15
|
+
line-length = 100
|
|
16
|
+
target-version = "py39"
|