TreeIG
TreeIG computes exact Integrated Gradients for tree-based models. It attributes the change in a model's scalar output from a baseline to an observation to the input features. For one baseline $x_0$,
$$\sum_j \phi_j = F(x) - F(x_0).$$
TreeIG finds the split boundaries crossed along the straight-line path and sums their prediction jumps. For supported models, this avoids numerical integration and sampling. Weighted baseline distributions are supported as well.
Why Integrated Gradients works for trees
A tree prediction is constant between splits, so its ordinary gradient is zero almost everywhere. But the prediction jumps at split boundaries. Those jumps are the contribution that an ordinary pointwise gradient misses: in the distributional interpretation, each jump is an impulse whose integral equals the jump's height.
The top panel shows a single prediction step; the middle shows its derivative as an impulse at the split; the bottom shows the accumulated contribution. Integrating across the split recovers the prediction change. TreeIG applies this idea along the path from a baseline to an observation, assigning each crossing's jump to its split feature and summing across trees.
Installation
pip install "treeig[sklearn]"
Requires Python 3.9 or later, NumPy, and Numba. Install the model library you use;
extras include sklearn, xgboost, lightgbm, and catboost. SHAP is optional
for plotting. The first attribution call includes Numba compilation.
Quickstart
With a fitted supported model and numeric evaluation data:
from treeig import TreeIG
# A representative training row provides a simple reference.
ig = TreeIG(model, baseline=X_train[0])
result = ig.explain(X_eval)
phi = result.values
print(result.max_abs_completeness_error)
phi has one row per observation and one column per feature. Positive values
increase the explained output relative to the baseline; negative values decrease
it. Use ig.attribute(X_eval) when only the attribution array is needed.
The baseline defines the comparison. For substantive attribution,
CBaseline is the recommended way
to construct a prediction-neutral baseline distribution. TreeIG accepts its
Background directly as baseline=background, or a matrix of rows with
baseline_weights. See the baseline guide.
Model support and interpretation
Exact backends cover selected scikit-learn tree regressors and gradient boosting, XGBoost, and LightGBM. Regression explains predictions; classification explains raw margins, not probabilities. Inputs must be finite and numeric; categorical splits and missing-value routing are not supported by the exact parser.
TreeIGNumeric provides a numerical fallback for other piecewise-constant models,
including numeric-input CatBoost and probability-only classifiers. Its resolution
requires care. See supported models
and the numerical guide.
TreeIG and TreeSHAP answer different attribution questions. TreeIG can be fast on substantial attribution workloads, but relative speed depends on the model, baselines, and batch size. The comparison and benchmarks explain the distinction and report measured examples.
Documentation
The user guide covers a complete runnable example, baseline distributions, classification, plots, loss attribution, numerical conventions, and performance. The Sphinx sources also build into searchable HTML with an API reference; see building the documentation.
Optional GPU support
GPUTreeIG is an optional CUDA backend within this package. CPU TreeIG remains
the default; GPU performance depends on the workload. See
GPU documentation
for installation and limitations.
Citation and license
If you use TreeIG in your work, please cite:
@misc{hentschel2026treeig,
author = {Hentschel, Ludger},
title = {{TreeIG}: Exact Integrated Gradients for Tree-Based Models},
year = {2026},
url = {https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf},
}
Released under the BSD-3-Clause license.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file treeig-0.2.0.tar.gz.
File metadata
- Download URL: treeig-0.2.0.tar.gz
- Upload date:
- Size: 102.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2dabd19321330c355ae20cc6856174351dd922c48eabd70c247551f8dff17fc
|
|
| MD5 |
9a76fed4326d2746c6e90180a34d4abf
|
|
| BLAKE2b-256 |
19f1e2f21a9de0e283f86c9ce8e61a46183b59d393c70fb19a04015e4355a662
|
Provenance
The following attestation bundles were made for treeig-0.2.0.tar.gz:
Publisher:
release.yml on LudgerHentschel/treeig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treeig-0.2.0.tar.gz -
Subject digest:
c2dabd19321330c355ae20cc6856174351dd922c48eabd70c247551f8dff17fc - Sigstore transparency entry: 2728932111
- Sigstore integration time:
-
Permalink:
LudgerHentschel/treeig@bf0bbcc5e735053e81d996eeeb08df6c8aaf14f4 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/LudgerHentschel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bf0bbcc5e735053e81d996eeeb08df6c8aaf14f4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file treeig-0.2.0-py3-none-any.whl.
File metadata
- Download URL: treeig-0.2.0-py3-none-any.whl
- Upload date:
- Size: 49.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
253e6cfb71b4ea3dcd4804453014779ce35f917c237f354cf2554034d52ed94a
|
|
| MD5 |
6e65d4da35a263326c0d4f896a2ddb8a
|
|
| BLAKE2b-256 |
5568e6c5398027abea2b1168760bbc34c56e57c0c5265aba5c6cf57b9d436b72
|
Provenance
The following attestation bundles were made for treeig-0.2.0-py3-none-any.whl:
Publisher:
release.yml on LudgerHentschel/treeig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treeig-0.2.0-py3-none-any.whl -
Subject digest:
253e6cfb71b4ea3dcd4804453014779ce35f917c237f354cf2554034d52ed94a - Sigstore transparency entry: 2728932999
- Sigstore integration time:
-
Permalink:
LudgerHentschel/treeig@bf0bbcc5e735053e81d996eeeb08df6c8aaf14f4 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/LudgerHentschel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bf0bbcc5e735053e81d996eeeb08df6c8aaf14f4 -
Trigger Event:
push
-
Statement type: