Skip to main content

Disentangling Interactions and Dependencies (DIP) Decomposition.

Project description

DIP Decomposition Package (dipd)

The DIP Decomposition is a loss-based global feature attribution technique, that explains how much each feature contributes to the predictive performance. 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.

The DIP decomposition was introduced in this paper, titled "Disentangling Interactions and Dependencies in Feature Attribution".

Installation

dipd requires Python 3.11 or newer and can be installed from PyPI:

uv pip install dipd

For a development installation, clone the repository and install in editable mode:

git clone https://github.com/gcskoenig/dipd
cd dipd
uv pip install -e .

Usage

As follows we illustrate the package on a reduced version of the California housing dataset with just three features: longitude, latitude, and ocean proximity. 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.

## load data and preprocess data
import pandas as pd
import category_encoders as ce

varnames = ['longitude', 'latitude', 'ocean_proximity', 'median_house_value']
target_variable = 'median_house_value'
df = pd.read_csv('https://raw.githubusercontent.com/ageron/handson-ml2/master/datasets/housing/housing.csv').dropna()[varnames]
encoder = ce.OrdinalEncoder()
df = encoder.fit_transform(df)

## perform leave-one-covariate-out DIP decomposition
from dipd import DIP
from dipd.learners import EBM

# exemplary hyperparameters for the EBM learner (passed to ExplainableBoostingRegressor)
learner_kwargs = {'max_rounds': 500, 'learning_rate': 0.05}

explainer = DIP(df, target_variable, EBM, learner_kwargs=learner_kwargs)
explanation = explainer.get_all_loo()
print(explanation.scores)

## plot the results
import matplotlib.pyplot as plt
from dipd.plots import forceplot

ax = forceplot(explanation.scores.T, 'DIP Decomposition of LOCO scores',
               figsize=(3, 3), explain_surplus=True)
ax.get_legend().remove()
plt.show()

The code produces the following plot.

Forceplot DIP Decomposition

The plot can be interpreted as follows: Each bar explains one LOCO score as the sum of standalone contribution (gray) and the contributions of interactions (green) and dependencies (purple). 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.

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

dipd-0.0.3.tar.gz (76.1 kB view details)

Uploaded Source

Built Distribution

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

dipd-0.0.3-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file dipd-0.0.3.tar.gz.

File metadata

  • Download URL: dipd-0.0.3.tar.gz
  • Upload date:
  • Size: 76.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for dipd-0.0.3.tar.gz
Algorithm Hash digest
SHA256 1d8077708f39517439873a919f3c98d1a8fe7c6df6b76080b98bad8849f12c61
MD5 659e316c32a430606ff6c5fb4db0d089
BLAKE2b-256 d932aadf1f1dca5a2005d7ef5f70fc20c966ff4a79214fbe9226f0c60364e78d

See more details on using hashes here.

File details

Details for the file dipd-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: dipd-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for dipd-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0cff931ae47bf29c701a47728c5e82ac7e751378de85963269bc9a0902118b6f
MD5 caa2585d3b24fce03a0220c556eb2837
BLAKE2b-256 6263f42b07fc963df762e4055f676de9e0cfc444ef66c2dd3769b593914ff761

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