Skip to main content

Unified IG

Unified IG provides one small, SHAP-like API for Integrated Gradients across linear models, neural networks, and tree ensembles.

import unifiedig as uig

explainer = uig.Explainer(model, baseline)
explanation = explainer(X)

For numerical backends, the quadrature resolution is configurable:

explainer = uig.Explainer(model, baseline, n_steps=128)

Explanation is lightweight and has SHAP-compatible fields. SHAP remains an optional dependency; call explanation.to_shap() to use its plotting tools.

Installation

Install the core sklearn support from PyPI:

pip install unifiedig

Install every optional backend and the SHAP adapter with:

pip install "unifiedig[all]"

During development, install the project and its test dependencies with:

python -m pip install -e ".[test]"

Output semantics

For regression, attributions sum to the difference between the prediction and the baseline prediction. Binary classifiers are explained on their decision-score (logit) scale; probability attributions are not part of V1. See docs/semantics.md for the complete array-shape and output contract.

A baseline matrix is an equally weighted distribution shared by every input:

background = X_train[:100]
explanation = uig.Explainer(model, background)(X_test)

Unified IG averages the attribution paths and model output over all background rows. It does not pair background row i with input row i.

Numerical explanations expose their observed completeness residual:

explanation.completeness_error
explanation.max_abs_completeness_error

Unified IG warns when this error exceeds the configured tolerance. Increasing n_steps usually improves it. See the examples/ directory for complete linear, logistic, MLP regression, and MLP classification programs.

Supported models

  • sklearn.linear_model.LinearRegression (closed form)
  • Binary sklearn.linear_model.LogisticRegression (closed form)
  • sklearn.neural_network.MLPRegressor (analytic gradients and quadrature)
  • Binary sklearn.neural_network.MLPClassifier (analytic logit gradients and quadrature)
  • PyTorch modules with one raw scalar output per sample (Captum, optional)
  • TreeIG-supported sklearn, XGBoost, and LightGBM trees (exact, optional)

Install PyTorch support separately so the core package remains lightweight:

pip install "unifiedig[torch]"

Install exact tree-model support separately:

pip install "unifiedig[trees]"

Tree attributions are computed by TreeIG; Unified IG normalizes the input and baseline and adapts TreeIG's exact result to Explanation.

PyTorch models may accept tabular or structured single-tensor inputs. Unified IG preserves the model's device and floating-point dtype, temporarily evaluates the model in inference mode, and restores every module's prior training state. V1 expects one raw scalar output per sample. For binary classification that output must be the logit, not a sigmoid probability.

Development

Run the tests and validate distribution artifacts with:

pytest
python -m build
python -m twine check dist/*

See CONTRIBUTING.md for the development workflow.

V1 public API

The stable V1 surface is deliberately small: Explainer, Explanation, and Explanation.to_shap(). Unified IG has no plotting API and SHAP is not a core dependency.

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.0.tar.gz (21.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.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unifiedig-0.1.0.tar.gz
  • Upload date:
  • Size: 21.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.0.tar.gz
Algorithm Hash digest
SHA256 3a196d0cfe8a05030e9def4ad8d12234b94d8e39b0b310a3d0f59c07bd346fd0
MD5 dc5426770fd2efff1e33fad9e8d3bb41
BLAKE2b-256 33fb676e9e164afd695cf5705328ef83dfefa21bd332e66f8037c085d3998be1

See more details on using hashes here.

Provenance

The following attestation bundles were made for unifiedig-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: unifiedig-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57d6b287495fbf27c7234f2eda188696d6c78ab67f1430d963665af9a59f14f6
MD5 ffc060e3988811cae25206432afd5e9d
BLAKE2b-256 f6a5adcc5c524770856d12ff7436c6c590ae54300d2b1d6b0b4803d115bd1c1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for unifiedig-0.1.0-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

0.1.6

2 files

This release

0.1.0 This release

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