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

Metadata

Release files for unifiedig 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unifiedig 0.1.6
File Size Uploaded Provenance Actions
unifiedig-0.1.6.tar.gz 236.5 kB With provenance Details for unifiedig-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for unifiedig 0.1.6
File Interpreter ABI Platform Actions
unifiedig-0.1.6-py3-none-any.whl Python 3 none any Details for unifiedig-0.1.6-py3-none-any.whl

Total release size: 276.3 kB

Release files / unifiedig-0.1.6.tar.gz

Download URL unifiedig-0.1.6.tar.gz
Size 236.5 kB
Tags Source
SHA-256 checksum
How to use checksums
83089314d2ad06c9ca13a7ddf9550ffb55ea5ce1bddbc174849318a88a11b361
BLAKE2b-256 checksum
How to use checksums
0b84b9f455f5d7d8279fe3ccc3afbbee6e09172bc5fe6bd8381e7cb406b650d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / unifiedig-0.1.6-py3-none-any.whl

Download URL unifiedig-0.1.6-py3-none-any.whl
Size 39.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40bcfefd68ae2418d6082d03910704c70efdcbc1ab1b2ba6e51e144c0a9550c3
BLAKE2b-256 checksum
How to use checksums
87a5ce96918191b0c4bf614a9dd0f4ac9e73e1006eabe8bf16bea6d61a15a2e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Security for unifiedig 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for unifiedig-0.1.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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