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.2.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.2-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dipd-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 b0c2703342fe036111cb3fe63ab1a0312fc75ed5ba93746ae4777b9073e482a3
MD5 6c20e0132e57088aac10c00366dd53d8
BLAKE2b-256 4d3347f16a42ad10857d9df6879cd5d3c029ab155f652e4bb19a5a388523eeb1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dipd-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bc8b277dad89c7ba5e9cfa4efa458d5199ca95737026e3c3a899eff675ff5b07
MD5 74e6fc084ff65513102a41e5c1d1aa8c
BLAKE2b-256 3cc9743f158f9e1e424d679305fd94206ae7bb3455dae9461227cc46b0da01ef

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