dipd 0.0.1__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.
- dipd-0.0.1/.github/images/readmefig.png +0 -0
- dipd-0.0.1/.gitignore +2 -0
- dipd-0.0.1/LICENSE +19 -0
- dipd-0.0.1/PKG-INFO +86 -0
- dipd-0.0.1/README.md +64 -0
- dipd-0.0.1/pyproject.toml +40 -0
- dipd-0.0.1/src/dipd/__init__.py +5 -0
- dipd-0.0.1/src/dipd/consts.py +6 -0
- dipd-0.0.1/src/dipd/explainer.py +619 -0
- dipd-0.0.1/src/dipd/explanation.py +67 -0
- dipd-0.0.1/src/dipd/learners.py +162 -0
- dipd-0.0.1/src/dipd/plots.py +232 -0
- dipd-0.0.1/src/dipd/py.typed +0 -0
- dipd-0.0.1/src/dipd/utils.py +15 -0
- dipd-0.0.1/tests/test_paper_examples.py +414 -0
- dipd-0.0.1/tests/test_readme_example.py +44 -0
|
Binary file
|
dipd-0.0.1/.gitignore
ADDED
dipd-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
dipd-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dipd
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Disentangling Interactions and Dependencies (DIP) Decomposition.
|
|
5
|
+
Project-URL: Homepage, https://github.com/gcskoenig/dipd
|
|
6
|
+
Project-URL: Issues, https://github.com/gcskoenig/dipd/issues
|
|
7
|
+
Author-email: Gunnar König <g.koenig.edu@pm.me>
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Requires-Dist: interpret<0.8.0,>=0.7.6
|
|
14
|
+
Requires-Dist: matplotlib
|
|
15
|
+
Requires-Dist: numpy
|
|
16
|
+
Requires-Dist: pandas
|
|
17
|
+
Requires-Dist: scikit-learn
|
|
18
|
+
Requires-Dist: seaborn
|
|
19
|
+
Requires-Dist: statsmodels
|
|
20
|
+
Requires-Dist: tqdm
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# DIP Decomposition Package (`dipd`)
|
|
24
|
+
|
|
25
|
+
**The DIP Decomposition** is a loss-based global feature attribution technique, that explains how much each feature contributes to the predictive performance.
|
|
26
|
+
In contrast to standard feature attribution techniques it separates the standalone contributions of the individual features and cooperative contributions stemming from interactions and dependencies between features.
|
|
27
|
+
|
|
28
|
+
The DIP decomposition was introduced in [this paper](https://arxiv.org/pdf/2410.23772), titled "Disentangling Interactions and Dependencies in Feature Attribution".
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
`dipd` requires **Python 3.11** or newer and can be installed from PyPI:
|
|
33
|
+
```
|
|
34
|
+
pip install dipd
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For a development installation, clone the repository and install in editable mode:
|
|
38
|
+
```
|
|
39
|
+
git clone https://github.com/gcskoenig/dipd
|
|
40
|
+
cd dipd
|
|
41
|
+
pip install -e .
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
As follows we illustrate the package on a reduced version of the California housing dataset with just three features: longitude, latitude, and ocean proximity.
|
|
47
|
+
Specifically, we compute and decompose the Leave-One-Covariate-Out (LOCO) scores based on explainable boosting machines (EBM) and decompose these scores into the feature's standalone contribution, and the contributions stemming from interactions and dependencies with the remaining features.
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
## load data and preprocess data
|
|
51
|
+
import pandas as pd
|
|
52
|
+
import category_encoders as ce
|
|
53
|
+
|
|
54
|
+
varnames = ['longitude', 'latitude', 'ocean_proximity', 'median_house_value']
|
|
55
|
+
target_variable = 'median_house_value'
|
|
56
|
+
df = pd.read_csv('https://raw.githubusercontent.com/ageron/handson-ml2/master/datasets/housing/housing.csv').dropna()[varnames]
|
|
57
|
+
encoder = ce.OrdinalEncoder()
|
|
58
|
+
df = encoder.fit_transform(df)
|
|
59
|
+
|
|
60
|
+
## perform leave-one-covariate-out DIP decomposition
|
|
61
|
+
from dipd import DIP
|
|
62
|
+
from dipd.learners import EBM
|
|
63
|
+
|
|
64
|
+
explainer = DIP(df, target_variable, EBM)
|
|
65
|
+
explanation = explainer.get_all_loo()
|
|
66
|
+
print(explanation.scores)
|
|
67
|
+
|
|
68
|
+
## plot the results
|
|
69
|
+
import matplotlib.pyplot as plt
|
|
70
|
+
from dipd.plots import forceplot
|
|
71
|
+
|
|
72
|
+
ax = forceplot(explanation.scores.T, 'DIP Decomposition of LOCO scores',
|
|
73
|
+
figsize=(3, 3), explain_surplus=True)
|
|
74
|
+
ax.get_legend().remove()
|
|
75
|
+
plt.show()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The code produces the following plot.
|
|
79
|
+
|
|
80
|
+
<p align="center">
|
|
81
|
+
<img src=".github/images/readmefig.png" alt="Forceplot DIP Decomposition" width="50%">
|
|
82
|
+
</p>
|
|
83
|
+
|
|
84
|
+
The plot can be interpreted as follows: Each bar explains one LOCO score as the sum of standalone contribution (gray)
|
|
85
|
+
and the contributions of interactions (green) and dependencies (purple).
|
|
86
|
+
Each bar is visualized as a forceplot, meaning that the direction of each bar indicates the sign, where downward facing bars are negative contributions and upward facing bars positive contributions. The bars sum up to the black horizontal lines, which are the LOCO scores of the features.
|
dipd-0.0.1/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# DIP Decomposition Package (`dipd`)
|
|
2
|
+
|
|
3
|
+
**The DIP Decomposition** is a loss-based global feature attribution technique, that explains how much each feature contributes to the predictive performance.
|
|
4
|
+
In contrast to standard feature attribution techniques it separates the standalone contributions of the individual features and cooperative contributions stemming from interactions and dependencies between features.
|
|
5
|
+
|
|
6
|
+
The DIP decomposition was introduced in [this paper](https://arxiv.org/pdf/2410.23772), titled "Disentangling Interactions and Dependencies in Feature Attribution".
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
`dipd` requires **Python 3.11** or newer and can be installed from PyPI:
|
|
11
|
+
```
|
|
12
|
+
pip install dipd
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
For a development installation, clone the repository and install in editable mode:
|
|
16
|
+
```
|
|
17
|
+
git clone https://github.com/gcskoenig/dipd
|
|
18
|
+
cd dipd
|
|
19
|
+
pip install -e .
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
As follows we illustrate the package on a reduced version of the California housing dataset with just three features: longitude, latitude, and ocean proximity.
|
|
25
|
+
Specifically, we compute and decompose the Leave-One-Covariate-Out (LOCO) scores based on explainable boosting machines (EBM) and decompose these scores into the feature's standalone contribution, and the contributions stemming from interactions and dependencies with the remaining features.
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
## load data and preprocess data
|
|
29
|
+
import pandas as pd
|
|
30
|
+
import category_encoders as ce
|
|
31
|
+
|
|
32
|
+
varnames = ['longitude', 'latitude', 'ocean_proximity', 'median_house_value']
|
|
33
|
+
target_variable = 'median_house_value'
|
|
34
|
+
df = pd.read_csv('https://raw.githubusercontent.com/ageron/handson-ml2/master/datasets/housing/housing.csv').dropna()[varnames]
|
|
35
|
+
encoder = ce.OrdinalEncoder()
|
|
36
|
+
df = encoder.fit_transform(df)
|
|
37
|
+
|
|
38
|
+
## perform leave-one-covariate-out DIP decomposition
|
|
39
|
+
from dipd import DIP
|
|
40
|
+
from dipd.learners import EBM
|
|
41
|
+
|
|
42
|
+
explainer = DIP(df, target_variable, EBM)
|
|
43
|
+
explanation = explainer.get_all_loo()
|
|
44
|
+
print(explanation.scores)
|
|
45
|
+
|
|
46
|
+
## plot the results
|
|
47
|
+
import matplotlib.pyplot as plt
|
|
48
|
+
from dipd.plots import forceplot
|
|
49
|
+
|
|
50
|
+
ax = forceplot(explanation.scores.T, 'DIP Decomposition of LOCO scores',
|
|
51
|
+
figsize=(3, 3), explain_surplus=True)
|
|
52
|
+
ax.get_legend().remove()
|
|
53
|
+
plt.show()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The code produces the following plot.
|
|
57
|
+
|
|
58
|
+
<p align="center">
|
|
59
|
+
<img src=".github/images/readmefig.png" alt="Forceplot DIP Decomposition" width="50%">
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
The plot can be interpreted as follows: Each bar explains one LOCO score as the sum of standalone contribution (gray)
|
|
63
|
+
and the contributions of interactions (green) and dependencies (purple).
|
|
64
|
+
Each bar is visualized as a forceplot, meaning that the direction of each bar indicates the sign, where downward facing bars are negative contributions and upward facing bars positive contributions. The bars sum up to the black horizontal lines, which are the LOCO scores of the features.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dipd"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Gunnar König", email="g.koenig.edu@pm.me" },
|
|
10
|
+
]
|
|
11
|
+
description = "Disentangling Interactions and Dependencies (DIP) Decomposition."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.11"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"numpy",
|
|
21
|
+
"pandas",
|
|
22
|
+
"interpret>=0.7.6,<0.8.0",
|
|
23
|
+
"matplotlib",
|
|
24
|
+
"seaborn",
|
|
25
|
+
"tqdm",
|
|
26
|
+
"scikit-learn",
|
|
27
|
+
"statsmodels",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[tool.hatchling.build]
|
|
31
|
+
exclude = [
|
|
32
|
+
"**/__pycache__",
|
|
33
|
+
"**/*.pyc",
|
|
34
|
+
"**/*.pyo",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/gcskoenig/dipd"
|
|
39
|
+
Issues = "https://github.com/gcskoenig/dipd/issues"
|
|
40
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
RETURN_NAMES = ['v1', 'v2', 'vC', 'main_effect_cross_predictability', 'main_effect_cov', 'pure_interactions']
|
|
2
|
+
|
|
3
|
+
FORCEPLOT_COLOR_DICT = {'main_effect_dependencies': '#946EE6', 'main_effect_cross_predictability': '#C862CC',
|
|
4
|
+
'main_effect_cov': '#6285CC', 'pure_interactions': '#77E69E',
|
|
5
|
+
'v2': 'gray', 'v1': 'darkgrey', 'total': 'black',
|
|
6
|
+
'vC': 'lightgrey', 'loco': '#D98068', 'joint': '#A69C37'}
|