Skip to main content

Unified IG

Documentation

Tests PyPI version Python versions License: BSD-3-Clause

Fast Integrated Gradients feature attribution for the most common Python machine learning models, including tree models, with a familiar API and a convenient path to SHAP plotting tools.

UnifiedIG brings three capabilities together:

  1. One familiar API, including trees. Explain supported linear models, pipelines, neural networks, and tree ensembles through the same interface. TreeIG brings tree models into the IG framework by accounting for prediction jumps at split boundaries.
  2. Fast attribution from model structure. Native autograd, skgrad's analytic derivatives, and TreeIG's exact split-crossing calculations use the information each model makes available. Exact shortcuts avoid unnecessary integration; specialized gradients avoid expensive numerical differentiation.
  3. Coherent reference distributions. CBaseline constructs distributions of observed inputs localized around a chosen reference prediction and calibrates their weighted output to that reference. Explain against a meaningful reference population, with every path contributing to the same prediction contrast.
import unifiedig as uig

explanation = uig.Explainer(model, background)(X)

Read the UnifiedIG documentation for the user guide, worked examples, and API reference.

Installation

pip install unifiedig

Requires Python 3.10 or newer. CBaseline, skgrad, and TreeIG are installed alongside UnifiedIG; no separate attribution-backend setup is needed. Install your model's framework separately when using PyTorch, JAX, TensorFlow, CatBoost, XGBoost, or LightGBM.

Quick start

import numpy as np
from sklearn.linear_model import Ridge

from cbaseline import background
import unifiedig as uig

rng = np.random.default_rng(0)
X_train = rng.normal(size=(200, 4))
y_train = 2.0 * X_train[:, 0] - X_train[:, 1] + 0.5 * X_train[:, 2]
model = Ridge(alpha=0.5).fit(X_train, y_train)

# Choose a reference prediction and construct observed baseline inputs whose
# weighted mean model prediction equals that reference.
f_train = model.predict(X_train)
f0 = float(f_train.mean())
bg = background(
    predictions=f_train,
    f0=f0,
    features=X_train,
    weighting="calibrated",
)
X_eval = X_train[100:105]

explanation = uig.Explainer(model, bg)(X_eval)

np.testing.assert_allclose(
    explanation.base_values + explanation.values.sum(axis=1),
    model.predict(X_eval),
)

For a pandas DataFrame, Unified IG carries column labels into explanation.feature_names.

If one particular input is the intended starting point, pass it directly instead: uig.Explainer(model, x0).

Plot with SHAP

Install the optional plotting dependencies:

pip install "unifiedig[shap]"

Convert the result and use familiar SHAP plotting tools:

import shap

plot_values = explanation.to_shap()
shap.plots.waterfall(plot_values[0])
shap.plots.beeswarm(plot_values)
shap.plots.bar(plot_values)

Conversion does not rerun the model: the plotted values remain Integrated Gradients contributions. See the plotting guide and gallery for multiclass contrasts, scatter plots, labeling, and saving figures.

Model coverage and interpretation

The same interface covers supported sklearn linear models, MLPs and pipelines; selected sklearn, XGBoost and LightGBM trees; and native PyTorch, JAX, and TensorFlow/Keras models. Explicit numerical fallbacks extend coverage to other smooth estimators and recognized tree families, including numeric CatBoost. The model/backend matrix distinguishes exact routes, numerical routes, and their restrictions.

Classification attributions explain scores, not probabilities. Binary outputs use margins or logits; multiclass outputs use centered scores and support pairwise contrasts. We recommend against probability attribution for explaining classification decisions because probability links compress and couple score changes. Read the classification guide for the rationale and conventions.

For scalar tabular predictions, explanation.values has shape (samples, features). Adding its feature sum to explanation.base_values reconstructs the prediction. Inspect explanation.max_abs_completeness_error and follow the accuracy guide when using numerical routes.

Explore the documentation

Topic Guide
Choose a coherent reference population Baselines and CBaseline
Understand the returned values and shapes Reading an explanation
Explain original or transformed pipeline features Feature spaces
Connect framework models Framework adapters
Follow complete runnable examples Worked examples
Understand tree paths, gradients, and integration How UnifiedIG works
Look up parameters and public objects API reference

UnifiedIG also offers loss attribution when observed targets are available. LossExplainer explains which features raise or lower loss relative to the reference, using much of the same path machinery. It is an additional capability beyond prediction attribution.

Project information

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unifiedig-0.1.6.tar.gz (236.5 kB view details)

Uploaded Source

Built Distribution

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

unifiedig-0.1.6-py3-none-any.whl (39.9 kB view details)

Uploaded Python 3

File details

Details for the file unifiedig-0.1.6.tar.gz.

File metadata

  • Download URL: unifiedig-0.1.6.tar.gz
  • Upload date:
  • Size: 236.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for unifiedig-0.1.6.tar.gz
Algorithm Hash digest
SHA256 83089314d2ad06c9ca13a7ddf9550ffb55ea5ce1bddbc174849318a88a11b361
MD5 2f762721b0b742392dc47d2ad2919cfe
BLAKE2b-256 0b84b9f455f5d7d8279fe3ccc3afbbee6e09172bc5fe6bd8381e7cb406b650d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for unifiedig-0.1.6.tar.gz:

Publisher: release.yml on LudgerHentschel/unifiedig

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unifiedig-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: unifiedig-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 39.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for unifiedig-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 40bcfefd68ae2418d6082d03910704c70efdcbc1ab1b2ba6e51e144c0a9550c3
MD5 86b8357895cee73570a6025144e41f65
BLAKE2b-256 87a5ce96918191b0c4bf614a9dd0f4ac9e73e1006eabe8bf16bea6d61a15a2e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for unifiedig-0.1.6-py3-none-any.whl:

Publisher: release.yml on LudgerHentschel/unifiedig

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page