Skip to content

Commit

Permalink
Merge pull request #42 from mmschlk/development
Browse files Browse the repository at this point in the history
Renamed nSII to k-SII and refactors base approximators
  • Loading branch information
mmschlk authored Feb 6, 2024
2 parents 321bfcd + d3545d6 commit 3d13d3f
Show file tree
Hide file tree
Showing 31 changed files with 693 additions and 630 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,29 @@ You can use `shapiq` in different ways. If you have a trained model you can rely
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 n-SII values
## 📈 Compute k-SII values

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

```python
# train a model
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor(n_estimators=50, random_state=42)
model.fit(x_train, y_train)

# explain with nSII interaction scores
# explain with k-SII interaction scores
from shapiq import InteractionExplainer
explainer = InteractionExplainer(
model=model.predict,
background_data=x_train,
index="nSII",
index="k-SII",
max_order=2
)
interaction_values = explainer.explain(x_explain, budget=2000)
print(interaction_values)

>>> InteractionValues(
>>> index=nSII, max_order=2, min_order=1, estimated=True, estimation_budget=2000,
>>> 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
Expand All @@ -110,8 +110,8 @@ attribution scores and interaction scores, respectively.
from shapiq.plot import network_plot

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

Expand Down
4 changes: 1 addition & 3 deletions shapiq/approximator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""This module contains the approximators to estimate the Shapley interaction values."""
from ._base import convert_nsii_into_one_dimension, transforms_sii_to_nsii # TODO add to tests
from .k_sii import convert_ksii_into_one_dimension, transforms_sii_to_ksii
from .permutation.sii import PermutationSamplingSII
from .permutation.sti import PermutationSamplingSTI
from .regression import RegressionSII, RegressionFSI, KernelSHAP
Expand All @@ -12,6 +12,4 @@
"RegressionFSI",
"RegressionSII",
"ShapIQ",
"transforms_sii_to_nsii",
"convert_nsii_into_one_dimension",
]
Loading

0 comments on commit 3d13d3f

Please sign in to comment.