treeig 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- treeig-0.2.2/CHANGELOG.md +33 -0
- {treeig-0.2.0 → treeig-0.2.2}/CITATION.cff +1 -1
- {treeig-0.2.0 → treeig-0.2.2}/MANIFEST.in +1 -1
- {treeig-0.2.0 → treeig-0.2.2}/PKG-INFO +75 -28
- treeig-0.2.2/README.md +155 -0
- treeig-0.2.2/docs/_templates/documentation-nav.html +8 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/api.md +6 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/baselines.md +15 -6
- treeig-0.2.2/docs/building.md +45 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/concepts.md +18 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/conf.py +11 -2
- {treeig-0.2.0 → treeig-0.2.2}/docs/examples.md +6 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/explanations.md +10 -2
- {treeig-0.2.0 → treeig-0.2.2}/docs/getting-started.md +6 -0
- treeig-0.2.2/docs/gpu-benchmarks.md +10 -0
- treeig-0.2.2/docs/gpu.md +112 -0
- treeig-0.2.2/docs/ig-stack.md +39 -0
- treeig-0.2.2/docs/index.md +106 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/models.md +6 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/numeric.md +50 -6
- {treeig-0.2.0 → treeig-0.2.2}/docs/performance.md +8 -0
- treeig-0.2.2/docs/publishing.md +28 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/references.md +21 -3
- {treeig-0.2.0 → treeig-0.2.2}/docs/requirements.txt +1 -0
- {treeig-0.2.0 → treeig-0.2.2}/pyproject.toml +3 -1
- treeig-0.2.2/tests/test_release_version.py +23 -0
- {treeig-0.2.0 → treeig-0.2.2}/tests/test_treeig_numeric.py +125 -9
- {treeig-0.2.0 → treeig-0.2.2}/treeig/numeric.py +68 -27
- {treeig-0.2.0 → treeig-0.2.2}/treeig.egg-info/PKG-INFO +75 -28
- {treeig-0.2.0 → treeig-0.2.2}/treeig.egg-info/SOURCES.txt +5 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig.egg-info/requires.txt +1 -0
- treeig-0.2.0/CHANGELOG.md +0 -10
- treeig-0.2.0/README.md +0 -110
- treeig-0.2.0/docs/building.md +0 -21
- treeig-0.2.0/docs/gpu.md +0 -52
- treeig-0.2.0/docs/index.md +0 -58
- {treeig-0.2.0 → treeig-0.2.2}/LICENSE +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/benchmarks/README.md +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/benchmarks/catboost_adaptive.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/benchmarks/cuda_prediction.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/benchmarks/probability_forests.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/benchmarks/treeig_vs_treeshap.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/benchmarks/weighted_baselines_cpu.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/Figure_BoundaryCrossings.svg +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/Figure_TreeGradient.svg +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/comparison.md +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/docs/loss.md +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/setup.cfg +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/tests/test_binsearch.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/tests/test_cuda_backend.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/tests/test_explanation.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/tests/test_optional_cuda.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/tests/test_treeig.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/__init__.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/api.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/core.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/cuda_backend.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/dispatch.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/explanation.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/gpu.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/lightgbm_backend.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/sklearn_backend.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/utils.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig/xgboost_backend.py +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig.egg-info/dependency_links.txt +0 -0
- {treeig-0.2.0 → treeig-0.2.2}/treeig.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
- Change `TreeIGNumeric` and `make_scalar_fn` to derive classification scores
|
|
6
|
+
by default when no native margin exists: binary log odds or centered
|
|
7
|
+
multiclass log probabilities. `compute_numeric` inherits this default.
|
|
8
|
+
Callers requiring the former class-probability output must explicitly set
|
|
9
|
+
`probability_to_score=False`. Zero probabilities require an explicit
|
|
10
|
+
`probability_floor` for finite scores; no floor is chosen silently.
|
|
11
|
+
|
|
12
|
+
- Add an agent documentation index, sitemap, canonical URLs, page descriptions,
|
|
13
|
+
and build checks for documentation discovery. Clarify exact versus numerical
|
|
14
|
+
model support, baseline guarantees, and related-project links.
|
|
15
|
+
- Lead the README and documentation landing page with the piecewise-constant
|
|
16
|
+
gradient argument, and move the derivative-impulse figure above the fold.
|
|
17
|
+
- State completeness precision relative to the fitted model's own arithmetic
|
|
18
|
+
rather than unqualified floating-point precision.
|
|
19
|
+
|
|
20
|
+
## 0.2.1
|
|
21
|
+
|
|
22
|
+
- Separate numerical jump-detection tolerance from absolute and relative completeness-warning tolerances; retain raw residual diagnostics.
|
|
23
|
+
- Clarify jump-based fallback behavior, bundled-event completeness, and XGBoost prediction precision.
|
|
24
|
+
- Check numeric regression tests with unexpected runtime warnings treated as errors in CI.
|
|
25
|
+
|
|
26
|
+
## 0.2.0
|
|
27
|
+
|
|
28
|
+
- Add optional `treeig.GPUTreeIG` prediction attribution with persistent CUDA model and weighted-baseline state and reusable observation buffers.
|
|
29
|
+
- Keep CPU `TreeIG` as the default; load CUDA only when constructing `GPUTreeIG`.
|
|
30
|
+
- Add the `cuda` installation extra, simulator equivalence tests, and GPU usage and benchmark documentation.
|
|
31
|
+
- Correct GitHub project links and restrict release publishing to version tags.
|
|
32
|
+
|
|
33
|
+
GPUTreeIG is part of `treeig`, not a separate distribution. GPU performance depends on the workload; existing T4 measurements are examples rather than guarantees.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: treeig
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Exact Integrated Gradients for tree ensembles.
|
|
5
5
|
Author: Ludger Hentschel
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
7
|
+
Project-URL: Documentation, https://ludgerhentschel.github.io/treeig/
|
|
7
8
|
Project-URL: Homepage, https://github.com/LudgerHentschel/treeig
|
|
8
9
|
Project-URL: Repository, https://github.com/LudgerHentschel/treeig
|
|
9
10
|
Project-URL: Issues, https://github.com/LudgerHentschel/treeig/issues
|
|
@@ -25,6 +26,7 @@ Requires-Dist: numpy>=1.24
|
|
|
25
26
|
Requires-Dist: numba>=0.58
|
|
26
27
|
Provides-Extra: docs
|
|
27
28
|
Requires-Dist: sphinx<9,>=7; extra == "docs"
|
|
29
|
+
Requires-Dist: sphinx-sitemap<3,>=2.6; extra == "docs"
|
|
28
30
|
Requires-Dist: myst-parser<5,>=3; extra == "docs"
|
|
29
31
|
Requires-Dist: pydata-sphinx-theme<0.17,>=0.16; extra == "docs"
|
|
30
32
|
Provides-Extra: cuda
|
|
@@ -59,32 +61,51 @@ Dynamic: license-file
|
|
|
59
61
|
# TreeIG
|
|
60
62
|
|
|
61
63
|
[](https://pypi.org/project/treeig/)
|
|
64
|
+
[](https://ludgerhentschel.github.io/treeig/)
|
|
62
65
|
|
|
63
|
-
TreeIG
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
TreeIG is a Python package for Integrated Gradients feature attribution on
|
|
67
|
+
supported numeric tree models. Install and import it as `treeig`. Given a fitted
|
|
68
|
+
model, a baseline point or weighted background, and evaluation rows, `TreeIG`
|
|
69
|
+
returns feature contributions and completeness diagnostics.
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
**TreeIG computes exact Integrated Gradients for supported numeric tree models.
|
|
72
|
+
A tree's gradient is zero almost everywhere; its integrated gradient is not.**
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
Check [supported models](https://ludgerhentschel.github.io/treeig/models.html) before choosing an interface.
|
|
75
|
+
`TreeIG` uses exact structural split crossings; [TreeIGNumeric](https://ludgerhentschel.github.io/treeig/numeric.html)
|
|
76
|
+
is a separately selected numerical fallback. Exact classification explains raw
|
|
77
|
+
margins or logits. Exact parsing requires finite numeric inputs and does not
|
|
78
|
+
support categorical splits or missing-value routing. Installing the CatBoost
|
|
79
|
+
extra does not add an exact CatBoost backend.
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
Tree ensembles are piecewise constant, so $\nabla F = 0$ except on a
|
|
82
|
+
measure-zero set of split boundaries. Numerical Integrated Gradients therefore
|
|
83
|
+
recovers approximately nothing, which is why IG has largely been confined to
|
|
84
|
+
differentiable models.
|
|
74
85
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
distributional interpretation, each jump is an impulse whose integral equals
|
|
79
|
-
the jump's height.
|
|
86
|
+
The pointwise gradient is not the full derivative. In the distributional sense,
|
|
87
|
+
$F'$ carries an impulse at each split boundary whose integral equals the
|
|
88
|
+
prediction jump there.
|
|
80
89
|
|
|
81
90
|

|
|
82
91
|
|
|
83
92
|
The top panel shows a single prediction step; the middle shows its derivative
|
|
84
93
|
as an impulse at the split; the bottom shows the accumulated contribution.
|
|
85
|
-
Integrating across the split recovers the prediction change.
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
Integrating across the split recovers the prediction change.
|
|
95
|
+
|
|
96
|
+
TreeIG enumerates the boundaries crossed by the straight-line path from baseline
|
|
97
|
+
to observation, assigns each jump to its split feature, and sums across trees.
|
|
98
|
+
No quadrature and no sampling are involved, and completeness
|
|
99
|
+
|
|
100
|
+
$$\sum_j \phi_j = F(x) - F(x_0)$$
|
|
101
|
+
|
|
102
|
+
holds to the floating-point precision of the fitted model's own arithmetic.
|
|
103
|
+
Weighted baseline distributions are supported directly.
|
|
104
|
+
|
|
105
|
+
The method is developed in Ludger Hentschel's
|
|
106
|
+
[**TreeIG: Exact Integrated Gradients for Tree-Based Models**](https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf).
|
|
107
|
+
It builds on Integrated Gradients introduced by Sundararajan, Taly, and Yan in
|
|
108
|
+
[**Axiomatic Attribution for Deep Networks** (ICML 2017)](https://proceedings.mlr.press/v70/sundararajan17a.html).
|
|
88
109
|
|
|
89
110
|
## Installation
|
|
90
111
|
|
|
@@ -98,7 +119,9 @@ for plotting. The first attribution call includes Numba compilation.
|
|
|
98
119
|
|
|
99
120
|
## Quickstart
|
|
100
121
|
|
|
101
|
-
|
|
122
|
+
This snippet assumes a fitted supported model and numeric evaluation data.
|
|
123
|
+
For a standalone example that creates data, fits a model, and checks prediction
|
|
124
|
+
reconstruction, start with [the complete quickstart](https://ludgerhentschel.github.io/treeig/getting-started.html).
|
|
102
125
|
|
|
103
126
|
```python
|
|
104
127
|
from treeig import TreeIG
|
|
@@ -118,7 +141,7 @@ The baseline defines the comparison. For substantive attribution,
|
|
|
118
141
|
[CBaseline](https://github.com/LudgerHentschel/cbaseline) is the recommended way
|
|
119
142
|
to construct a prediction-neutral baseline distribution. TreeIG accepts its
|
|
120
143
|
`Background` directly as `baseline=background`, or a matrix of rows with
|
|
121
|
-
`baseline_weights`. See the [baseline guide](https://github.
|
|
144
|
+
`baseline_weights`. See the [baseline guide](https://ludgerhentschel.github.io/treeig/baselines.html).
|
|
122
145
|
|
|
123
146
|
## Model support and interpretation
|
|
124
147
|
|
|
@@ -129,32 +152,54 @@ splits and missing-value routing are not supported by the exact parser.
|
|
|
129
152
|
|
|
130
153
|
`TreeIGNumeric` provides a numerical fallback for other piecewise-constant models,
|
|
131
154
|
including numeric-input CatBoost and probability-only classifiers. Its resolution
|
|
132
|
-
requires care.
|
|
133
|
-
|
|
155
|
+
requires care. For probability-only classifiers, it defaults to binary log odds
|
|
156
|
+
or centered multiclass log scores; class probabilities require explicit
|
|
157
|
+
`probability_to_score=False`. Zero probabilities require an explicit
|
|
158
|
+
`probability_floor` for score conversion. A small completeness
|
|
159
|
+
residual alone does not establish accurate individual feature allocations. See [supported models](https://ludgerhentschel.github.io/treeig/models.html)
|
|
160
|
+
and [the numerical guide](https://ludgerhentschel.github.io/treeig/numeric.html).
|
|
134
161
|
|
|
135
162
|
TreeIG and TreeSHAP answer different attribution questions. TreeIG can be fast
|
|
136
163
|
on substantial attribution workloads, but relative speed depends on the model,
|
|
137
|
-
baselines, and batch size. The [comparison and benchmarks](https://github.
|
|
164
|
+
baselines, and batch size. The [comparison and benchmarks](https://ludgerhentschel.github.io/treeig/comparison.html)
|
|
138
165
|
explain the distinction and report measured examples.
|
|
139
166
|
|
|
140
167
|
## Documentation
|
|
141
168
|
|
|
142
|
-
|
|
169
|
+
For automated readers, [llms.txt](https://ludgerhentschel.github.io/treeig/llms.txt)
|
|
170
|
+
maps the guides, complete examples, and rendered API reference.
|
|
171
|
+
|
|
172
|
+
The [user guide](https://ludgerhentschel.github.io/treeig/)
|
|
143
173
|
covers a complete runnable example, baseline distributions, classification,
|
|
144
174
|
plots, loss attribution, numerical conventions, and performance. The Sphinx
|
|
145
175
|
sources also build into searchable HTML with an API reference; see
|
|
146
|
-
[building the documentation](https://github.
|
|
176
|
+
[building the documentation](https://ludgerhentschel.github.io/treeig/building.html).
|
|
147
177
|
|
|
148
178
|
## Optional GPU support
|
|
149
179
|
|
|
150
|
-
`
|
|
151
|
-
|
|
152
|
-
|
|
180
|
+
`TreeIG` is already fast enough for most applications and remains the default.
|
|
181
|
+
When attribution speed matters and an NVIDIA GPU is available, `GPUTreeIG` can
|
|
182
|
+
be materially faster; recorded T4 comparisons show roughly 9–20× speedups on
|
|
183
|
+
the reported workloads. Performance depends on the problem. See
|
|
184
|
+
[GPU documentation](https://ludgerhentschel.github.io/treeig/gpu.html)
|
|
153
185
|
for installation and limitations.
|
|
154
186
|
|
|
187
|
+
## Related projects
|
|
188
|
+
|
|
189
|
+
| Package | When to use it |
|
|
190
|
+
|---|---|
|
|
191
|
+
| [UnifiedIG](https://ludgerhentschel.github.io/unifiedig/) (`unifiedig`) | A common Integrated Gradients interface across supported tree and smooth model families. |
|
|
192
|
+
| [CBaseline](https://ludgerhentschel.github.io/cbaseline/) (`cbaseline`) | Construct empirical reference distributions; TreeIG accepts its backgrounds with their weights directly. |
|
|
193
|
+
| [skgrad](https://ludgerhentschel.github.io/skgrad/) (`skgrad`) | Obtain analytic input gradients and Jacobians for supported smooth scikit-learn models. |
|
|
194
|
+
|
|
195
|
+
Use TreeIG directly when you need its tree-specific attribution interface.
|
|
196
|
+
See [the Integrated Gradients stack](https://ludgerhentschel.github.io/treeig/ig-stack.html)
|
|
197
|
+
for how the packages compose and why output scales must agree.
|
|
198
|
+
|
|
155
199
|
## Citation and license
|
|
156
200
|
|
|
157
|
-
If you use TreeIG in your work, please cite
|
|
201
|
+
If you use TreeIG in your work, please cite the
|
|
202
|
+
[TreeIG paper](https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf):
|
|
158
203
|
|
|
159
204
|
```bibtex
|
|
160
205
|
@misc{hentschel2026treeig,
|
|
@@ -166,3 +211,5 @@ If you use TreeIG in your work, please cite:
|
|
|
166
211
|
```
|
|
167
212
|
|
|
168
213
|
Released under the [BSD-3-Clause license](https://github.com/LudgerHentschel/treeig/blob/main/LICENSE).
|
|
214
|
+
|
|
215
|
+
Release maintainers: see [Publishing releases](docs/publishing.md).
|
treeig-0.2.2/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# TreeIG
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/treeig/)
|
|
4
|
+
[](https://ludgerhentschel.github.io/treeig/)
|
|
5
|
+
|
|
6
|
+
TreeIG is a Python package for Integrated Gradients feature attribution on
|
|
7
|
+
supported numeric tree models. Install and import it as `treeig`. Given a fitted
|
|
8
|
+
model, a baseline point or weighted background, and evaluation rows, `TreeIG`
|
|
9
|
+
returns feature contributions and completeness diagnostics.
|
|
10
|
+
|
|
11
|
+
**TreeIG computes exact Integrated Gradients for supported numeric tree models.
|
|
12
|
+
A tree's gradient is zero almost everywhere; its integrated gradient is not.**
|
|
13
|
+
|
|
14
|
+
Check [supported models](https://ludgerhentschel.github.io/treeig/models.html) before choosing an interface.
|
|
15
|
+
`TreeIG` uses exact structural split crossings; [TreeIGNumeric](https://ludgerhentschel.github.io/treeig/numeric.html)
|
|
16
|
+
is a separately selected numerical fallback. Exact classification explains raw
|
|
17
|
+
margins or logits. Exact parsing requires finite numeric inputs and does not
|
|
18
|
+
support categorical splits or missing-value routing. Installing the CatBoost
|
|
19
|
+
extra does not add an exact CatBoost backend.
|
|
20
|
+
|
|
21
|
+
Tree ensembles are piecewise constant, so $\nabla F = 0$ except on a
|
|
22
|
+
measure-zero set of split boundaries. Numerical Integrated Gradients therefore
|
|
23
|
+
recovers approximately nothing, which is why IG has largely been confined to
|
|
24
|
+
differentiable models.
|
|
25
|
+
|
|
26
|
+
The pointwise gradient is not the full derivative. In the distributional sense,
|
|
27
|
+
$F'$ carries an impulse at each split boundary whose integral equals the
|
|
28
|
+
prediction jump there.
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
The top panel shows a single prediction step; the middle shows its derivative
|
|
33
|
+
as an impulse at the split; the bottom shows the accumulated contribution.
|
|
34
|
+
Integrating across the split recovers the prediction change.
|
|
35
|
+
|
|
36
|
+
TreeIG enumerates the boundaries crossed by the straight-line path from baseline
|
|
37
|
+
to observation, assigns each jump to its split feature, and sums across trees.
|
|
38
|
+
No quadrature and no sampling are involved, and completeness
|
|
39
|
+
|
|
40
|
+
$$\sum_j \phi_j = F(x) - F(x_0)$$
|
|
41
|
+
|
|
42
|
+
holds to the floating-point precision of the fitted model's own arithmetic.
|
|
43
|
+
Weighted baseline distributions are supported directly.
|
|
44
|
+
|
|
45
|
+
The method is developed in Ludger Hentschel's
|
|
46
|
+
[**TreeIG: Exact Integrated Gradients for Tree-Based Models**](https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf).
|
|
47
|
+
It builds on Integrated Gradients introduced by Sundararajan, Taly, and Yan in
|
|
48
|
+
[**Axiomatic Attribution for Deep Networks** (ICML 2017)](https://proceedings.mlr.press/v70/sundararajan17a.html).
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install "treeig[sklearn]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Requires Python 3.9 or later, NumPy, and Numba. Install the model library you use;
|
|
57
|
+
extras include `sklearn`, `xgboost`, `lightgbm`, and `catboost`. SHAP is optional
|
|
58
|
+
for plotting. The first attribution call includes Numba compilation.
|
|
59
|
+
|
|
60
|
+
## Quickstart
|
|
61
|
+
|
|
62
|
+
This snippet assumes a fitted supported model and numeric evaluation data.
|
|
63
|
+
For a standalone example that creates data, fits a model, and checks prediction
|
|
64
|
+
reconstruction, start with [the complete quickstart](https://ludgerhentschel.github.io/treeig/getting-started.html).
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from treeig import TreeIG
|
|
68
|
+
|
|
69
|
+
# A representative training row provides a simple reference.
|
|
70
|
+
ig = TreeIG(model, baseline=X_train[0])
|
|
71
|
+
result = ig.explain(X_eval)
|
|
72
|
+
phi = result.values
|
|
73
|
+
print(result.max_abs_completeness_error)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`phi` has one row per observation and one column per feature. Positive values
|
|
77
|
+
increase the explained output relative to the baseline; negative values decrease
|
|
78
|
+
it. Use `ig.attribute(X_eval)` when only the attribution array is needed.
|
|
79
|
+
|
|
80
|
+
The baseline defines the comparison. For substantive attribution,
|
|
81
|
+
[CBaseline](https://github.com/LudgerHentschel/cbaseline) is the recommended way
|
|
82
|
+
to construct a prediction-neutral baseline distribution. TreeIG accepts its
|
|
83
|
+
`Background` directly as `baseline=background`, or a matrix of rows with
|
|
84
|
+
`baseline_weights`. See the [baseline guide](https://ludgerhentschel.github.io/treeig/baselines.html).
|
|
85
|
+
|
|
86
|
+
## Model support and interpretation
|
|
87
|
+
|
|
88
|
+
Exact backends cover selected scikit-learn tree regressors and gradient boosting,
|
|
89
|
+
XGBoost, and LightGBM. Regression explains predictions; classification explains
|
|
90
|
+
raw margins, not probabilities. Inputs must be finite and numeric; categorical
|
|
91
|
+
splits and missing-value routing are not supported by the exact parser.
|
|
92
|
+
|
|
93
|
+
`TreeIGNumeric` provides a numerical fallback for other piecewise-constant models,
|
|
94
|
+
including numeric-input CatBoost and probability-only classifiers. Its resolution
|
|
95
|
+
requires care. For probability-only classifiers, it defaults to binary log odds
|
|
96
|
+
or centered multiclass log scores; class probabilities require explicit
|
|
97
|
+
`probability_to_score=False`. Zero probabilities require an explicit
|
|
98
|
+
`probability_floor` for score conversion. A small completeness
|
|
99
|
+
residual alone does not establish accurate individual feature allocations. See [supported models](https://ludgerhentschel.github.io/treeig/models.html)
|
|
100
|
+
and [the numerical guide](https://ludgerhentschel.github.io/treeig/numeric.html).
|
|
101
|
+
|
|
102
|
+
TreeIG and TreeSHAP answer different attribution questions. TreeIG can be fast
|
|
103
|
+
on substantial attribution workloads, but relative speed depends on the model,
|
|
104
|
+
baselines, and batch size. The [comparison and benchmarks](https://ludgerhentschel.github.io/treeig/comparison.html)
|
|
105
|
+
explain the distinction and report measured examples.
|
|
106
|
+
|
|
107
|
+
## Documentation
|
|
108
|
+
|
|
109
|
+
For automated readers, [llms.txt](https://ludgerhentschel.github.io/treeig/llms.txt)
|
|
110
|
+
maps the guides, complete examples, and rendered API reference.
|
|
111
|
+
|
|
112
|
+
The [user guide](https://ludgerhentschel.github.io/treeig/)
|
|
113
|
+
covers a complete runnable example, baseline distributions, classification,
|
|
114
|
+
plots, loss attribution, numerical conventions, and performance. The Sphinx
|
|
115
|
+
sources also build into searchable HTML with an API reference; see
|
|
116
|
+
[building the documentation](https://ludgerhentschel.github.io/treeig/building.html).
|
|
117
|
+
|
|
118
|
+
## Optional GPU support
|
|
119
|
+
|
|
120
|
+
`TreeIG` is already fast enough for most applications and remains the default.
|
|
121
|
+
When attribution speed matters and an NVIDIA GPU is available, `GPUTreeIG` can
|
|
122
|
+
be materially faster; recorded T4 comparisons show roughly 9–20× speedups on
|
|
123
|
+
the reported workloads. Performance depends on the problem. See
|
|
124
|
+
[GPU documentation](https://ludgerhentschel.github.io/treeig/gpu.html)
|
|
125
|
+
for installation and limitations.
|
|
126
|
+
|
|
127
|
+
## Related projects
|
|
128
|
+
|
|
129
|
+
| Package | When to use it |
|
|
130
|
+
|---|---|
|
|
131
|
+
| [UnifiedIG](https://ludgerhentschel.github.io/unifiedig/) (`unifiedig`) | A common Integrated Gradients interface across supported tree and smooth model families. |
|
|
132
|
+
| [CBaseline](https://ludgerhentschel.github.io/cbaseline/) (`cbaseline`) | Construct empirical reference distributions; TreeIG accepts its backgrounds with their weights directly. |
|
|
133
|
+
| [skgrad](https://ludgerhentschel.github.io/skgrad/) (`skgrad`) | Obtain analytic input gradients and Jacobians for supported smooth scikit-learn models. |
|
|
134
|
+
|
|
135
|
+
Use TreeIG directly when you need its tree-specific attribution interface.
|
|
136
|
+
See [the Integrated Gradients stack](https://ludgerhentschel.github.io/treeig/ig-stack.html)
|
|
137
|
+
for how the packages compose and why output scales must agree.
|
|
138
|
+
|
|
139
|
+
## Citation and license
|
|
140
|
+
|
|
141
|
+
If you use TreeIG in your work, please cite the
|
|
142
|
+
[TreeIG paper](https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf):
|
|
143
|
+
|
|
144
|
+
```bibtex
|
|
145
|
+
@misc{hentschel2026treeig,
|
|
146
|
+
author = {Hentschel, Ludger},
|
|
147
|
+
title = {{TreeIG}: Exact Integrated Gradients for Tree-Based Models},
|
|
148
|
+
year = {2026},
|
|
149
|
+
url = {https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf},
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Released under the [BSD-3-Clause license](https://github.com/LudgerHentschel/treeig/blob/main/LICENSE).
|
|
154
|
+
|
|
155
|
+
Release maintainers: see [Publishing releases](docs/publishing.md).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{# Show the complete guide rather than only children of the active page. #}
|
|
2
|
+
<nav class="bd-docs-nav bd-links" aria-label="Documentation navigation">
|
|
3
|
+
<p class="bd-links__title" role="heading" aria-level="1">Documentation</p>
|
|
4
|
+
<div class="bd-toc-item navbar-nav">
|
|
5
|
+
{{ generate_toctree_html("sidebar", startdepth=0, show_nav_level=1,
|
|
6
|
+
maxdepth=1, collapse=False, includehidden=True, titles_only=True) }}
|
|
7
|
+
</div>
|
|
8
|
+
</nav>
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
myst:
|
|
3
|
+
html_meta:
|
|
4
|
+
description: "Choose TreeIG baseline points or weighted reference distributions, including CBaseline backgrounds."
|
|
5
|
+
---
|
|
6
|
+
|
|
1
7
|
# Choosing baselines and batching
|
|
2
8
|
|
|
3
9
|
The baseline determines the question an attribution answers. With one baseline,
|
|
@@ -14,15 +20,18 @@ model need not satisfy $F(\sum_k w_k b_k)=\sum_k w_k F(b_k)$.
|
|
|
14
20
|
|
|
15
21
|
For Integrated Gradients, the baseline determines the prediction contrast
|
|
16
22
|
being explained. **[CBaseline](https://github.com/LudgerHentschel/cbaseline) is the
|
|
17
|
-
preferred way to construct TreeIG baselines.**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
preferred way to construct TreeIG baselines.** Its calibrated mode produces
|
|
24
|
+
empirical baseline *distributions* whose weighted mean model output meets the
|
|
25
|
+
chosen reference prediction within numerical tolerances, or raises on failure.
|
|
26
|
+
Equal-weight selections approximate neutrality and report their residual.
|
|
27
|
+
TreeIG explains the model prediction relative to the **achieved weighted mean**,
|
|
28
|
+
so preserve both the rows and weights when passing a background.
|
|
22
29
|
|
|
23
30
|
TreeIG accepts a CBaseline `Background` directly and evaluates its weighted
|
|
24
31
|
baseline paths efficiently. See CBaseline for construction choices and the
|
|
25
|
-
interpretation of the reference prediction `f0
|
|
32
|
+
interpretation of the reference prediction `f0`: start with
|
|
33
|
+
[background modes](https://ludgerhentschel.github.io/cbaseline/backgrounds.html)
|
|
34
|
+
and [diagnostics](https://ludgerhentschel.github.io/cbaseline/diagnostics.html).
|
|
26
35
|
|
|
27
36
|
A single representative observation, domain-specific neutral input, or fixed
|
|
28
37
|
benchmark case is also supported. A sample mean is convenient for a first
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Building the documentation
|
|
2
|
+
|
|
3
|
+
The documentation uses Sphinx, MyST Markdown, and the PyData Sphinx Theme.
|
|
4
|
+
NumPy-style API docstrings are rendered with Sphinx's Napoleon extension.
|
|
5
|
+
No custom theme or frontend build is needed.
|
|
6
|
+
|
|
7
|
+
From the repository root, using Python 3.11 or later:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
python -m pip install -e ".[docs]"
|
|
11
|
+
python -m sphinx -W --keep-going -b html docs docs/_build/html
|
|
12
|
+
python scripts/check_docs_discovery.py
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Open `docs/_build/html/index.html` in a browser. Documentation dependencies are
|
|
16
|
+
optional and do not change TreeIG's runtime requirements. The documentation CI
|
|
17
|
+
builds HTML with warnings treated as errors and saves it as a downloadable
|
|
18
|
+
artifact. On pushes to `main` (or a manual run on `main`), it also publishes
|
|
19
|
+
the HTML to [GitHub Pages](https://ludgerhentschel.github.io/treeig/).
|
|
20
|
+
Pull requests build the documentation without deploying it.
|
|
21
|
+
|
|
22
|
+
For initial setup, open the repository's **Settings → Pages** and select
|
|
23
|
+
**GitHub Actions** as the build and deployment source. Then push the workflow
|
|
24
|
+
or run **Documentation** manually from the Actions tab. A successful `deploy`
|
|
25
|
+
job publishes the site. No package version change or release tag is required.
|
|
26
|
+
|
|
27
|
+
Edit the topic pages under `docs/`; keep the README focused on installation,
|
|
28
|
+
a first example, and links into the guide. Version information comes from
|
|
29
|
+
`pyproject.toml`. Generated HTML should not be committed.
|
|
30
|
+
|
|
31
|
+
## Discovery files
|
|
32
|
+
|
|
33
|
+
Maintain the repository-root `llms.txt` as an annotated map to the published
|
|
34
|
+
site. Sphinx copies this single source through `html_extra_path`. Link to
|
|
35
|
+
rendered API pages so readers receive expanded signatures and docstrings,
|
|
36
|
+
rather than the autodoc instructions in raw Sphinx sources.
|
|
37
|
+
|
|
38
|
+
`sphinx-sitemap` generates `sitemap.xml` using `html_baseurl`, which also supplies
|
|
39
|
+
canonical page URLs. Important pages define descriptions in `myst.html_meta`
|
|
40
|
+
YAML front matter. Keep `docs/requirements.txt` and the `docs` extra synchronized.
|
|
41
|
+
|
|
42
|
+
The discovery check runs after the HTML build in CI. It checks the index copy,
|
|
43
|
+
local targets, sitemap URLs, canonical links, descriptions, and expanded API and
|
|
44
|
+
example content. After deployment, check the public `/treeig/llms.txt` and
|
|
45
|
+
`/treeig/sitemap.xml` endpoints and external links in the index.
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
myst:
|
|
3
|
+
html_meta:
|
|
4
|
+
description: "Understand TreeIG numerical conventions, path crossings, and completeness."
|
|
5
|
+
---
|
|
6
|
+
|
|
1
7
|
# Attribution and interpretation
|
|
2
8
|
|
|
3
9
|
## Why TreeIG?
|
|
4
10
|
|
|
11
|
+
The method is developed in Ludger Hentschel's
|
|
12
|
+
[**TreeIG: Exact Integrated Gradients for Tree-Based Models**](https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf).
|
|
13
|
+
It builds on Integrated Gradients introduced by Sundararajan, Taly, and Yan in
|
|
14
|
+
[**Axiomatic Attribution for Deep Networks** (ICML 2017)](https://proceedings.mlr.press/v70/sundararajan17a.html).
|
|
15
|
+
|
|
16
|
+
|
|
5
17
|
Standard Integrated Gradients defines feature contributions by integrating
|
|
6
18
|
model gradients along a straight-line path from a baseline input to the
|
|
7
19
|
observation. Tree models are piecewise constant, so ordinary gradients are
|
|
@@ -71,6 +83,12 @@ TreeIG follows each backend's split-routing convention as closely as possible.
|
|
|
71
83
|
- XGBoost numeric splits route left when `x[j] < threshold`
|
|
72
84
|
using float32-style comparisons.
|
|
73
85
|
|
|
86
|
+
XGBoost completeness comparisons against native raw predictions can show small
|
|
87
|
+
residuals (around `1e-7` in tested models), consistent with differences in floating-point
|
|
88
|
+
precision and accumulation between the native predictor and the attribution
|
|
89
|
+
calculation. This is not a universal error bound or a numerical integration
|
|
90
|
+
resolution; compare residuals relative to the scale of the explained output.
|
|
91
|
+
|
|
74
92
|
Inputs must be finite numeric arrays. Missing-value routing is not currently
|
|
75
93
|
implemented, so `NaN` and `Inf` values raise errors.
|
|
76
94
|
|
|
@@ -8,13 +8,22 @@ project = "TreeIG"
|
|
|
8
8
|
author = "Ludger Hentschel"
|
|
9
9
|
copyright = "2026, Ludger Hentschel"
|
|
10
10
|
release = tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]["version"]
|
|
11
|
-
extensions = ["myst_parser", "sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx.ext.mathjax"]
|
|
11
|
+
extensions = ["myst_parser", "sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx.ext.mathjax", "sphinx_sitemap"]
|
|
12
12
|
myst_enable_extensions = ["dollarmath"]
|
|
13
13
|
myst_heading_anchors = 3
|
|
14
14
|
exclude_patterns = ["_build"]
|
|
15
15
|
html_theme = "pydata_sphinx_theme"
|
|
16
16
|
html_title = f"TreeIG {release}"
|
|
17
|
-
html_theme_options = {"github_url": "https://github.com/LudgerHentschel/treeig", "show_prev_next": True}
|
|
17
|
+
html_theme_options = {"github_url": "https://github.com/LudgerHentschel/treeig", "show_prev_next": True, "navbar_center": []}
|
|
18
18
|
html_static_path = []
|
|
19
19
|
napoleon_numpy_docstring = True
|
|
20
20
|
napoleon_google_docstring = False
|
|
21
|
+
|
|
22
|
+
templates_path = ["_templates"]
|
|
23
|
+
html_sidebars = {"**": ["documentation-nav.html"]}
|
|
24
|
+
|
|
25
|
+
html_baseurl = "https://ludgerhentschel.github.io/treeig/"
|
|
26
|
+
# Publish the single maintained repository index with the documentation.
|
|
27
|
+
html_extra_path = ["../llms.txt"]
|
|
28
|
+
sitemap_url_scheme = "{link}"
|
|
29
|
+
sitemap_excludes = ["search.html", "genindex.html", "py-modindex.html"]
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
myst:
|
|
3
|
+
html_meta:
|
|
4
|
+
description: "Interpret TreeIG feature contributions, classification targets, result shapes, and completeness diagnostics."
|
|
5
|
+
---
|
|
6
|
+
|
|
1
7
|
# Reading and plotting results
|
|
2
8
|
|
|
3
9
|
## Explanation objects and SHAP plots
|
|
@@ -78,8 +84,10 @@ ig = tig.TreeIG(model, baseline=x0, target=2)
|
|
|
78
84
|
phi_class_2 = ig.attribute(X_eval)
|
|
79
85
|
```
|
|
80
86
|
|
|
81
|
-
Exact TreeIG attributes raw class margins.
|
|
82
|
-
|
|
87
|
+
Exact TreeIG attributes raw class margins. When no native margin exists,
|
|
88
|
+
TreeIGNumeric defaults to binary log odds or centered multiclass log scores
|
|
89
|
+
derived from probabilities. See [numerical classification conventions](numeric.md)
|
|
90
|
+
for explicit floors at zero and the opt-in class-probability mode.
|
|
83
91
|
|
|
84
92
|
## Functional interface
|
|
85
93
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# CUDA benchmark notes
|
|
2
|
+
|
|
3
|
+
These are the recorded experiments maintained in the repository's benchmark
|
|
4
|
+
notes. See [GPUTreeIG](gpu.md) for installation and the summary comparisons.
|
|
5
|
+
|
|
6
|
+
## Recorded experiments
|
|
7
|
+
|
|
8
|
+
```{include} ../benchmarks/README.md
|
|
9
|
+
:start-after: "## CUDA prediction attribution"
|
|
10
|
+
```
|