treeig 0.2.1__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.
Files changed (63) hide show
  1. treeig-0.2.2/CHANGELOG.md +33 -0
  2. {treeig-0.2.1 → treeig-0.2.2}/PKG-INFO +61 -24
  3. {treeig-0.2.1 → treeig-0.2.2}/README.md +61 -25
  4. {treeig-0.2.1 → treeig-0.2.2}/docs/api.md +6 -0
  5. {treeig-0.2.1 → treeig-0.2.2}/docs/baselines.md +15 -6
  6. {treeig-0.2.1 → treeig-0.2.2}/docs/building.md +17 -0
  7. {treeig-0.2.1 → treeig-0.2.2}/docs/concepts.md +6 -0
  8. {treeig-0.2.1 → treeig-0.2.2}/docs/conf.py +7 -1
  9. {treeig-0.2.1 → treeig-0.2.2}/docs/examples.md +6 -0
  10. {treeig-0.2.1 → treeig-0.2.2}/docs/explanations.md +10 -2
  11. {treeig-0.2.1 → treeig-0.2.2}/docs/getting-started.md +6 -0
  12. {treeig-0.2.1 → treeig-0.2.2}/docs/ig-stack.md +7 -1
  13. treeig-0.2.2/docs/index.md +106 -0
  14. {treeig-0.2.1 → treeig-0.2.2}/docs/models.md +6 -0
  15. {treeig-0.2.1 → treeig-0.2.2}/docs/numeric.md +22 -5
  16. treeig-0.2.2/docs/publishing.md +28 -0
  17. {treeig-0.2.1 → treeig-0.2.2}/docs/requirements.txt +1 -0
  18. {treeig-0.2.1 → treeig-0.2.2}/pyproject.toml +2 -1
  19. treeig-0.2.2/tests/test_release_version.py +23 -0
  20. {treeig-0.2.1 → treeig-0.2.2}/tests/test_treeig_numeric.py +62 -5
  21. {treeig-0.2.1 → treeig-0.2.2}/treeig/numeric.py +18 -12
  22. {treeig-0.2.1 → treeig-0.2.2}/treeig.egg-info/PKG-INFO +61 -24
  23. {treeig-0.2.1 → treeig-0.2.2}/treeig.egg-info/SOURCES.txt +2 -0
  24. {treeig-0.2.1 → treeig-0.2.2}/treeig.egg-info/requires.txt +1 -0
  25. treeig-0.2.1/CHANGELOG.md +0 -16
  26. treeig-0.2.1/docs/index.md +0 -64
  27. {treeig-0.2.1 → treeig-0.2.2}/CITATION.cff +0 -0
  28. {treeig-0.2.1 → treeig-0.2.2}/LICENSE +0 -0
  29. {treeig-0.2.1 → treeig-0.2.2}/MANIFEST.in +0 -0
  30. {treeig-0.2.1 → treeig-0.2.2}/benchmarks/README.md +0 -0
  31. {treeig-0.2.1 → treeig-0.2.2}/benchmarks/catboost_adaptive.py +0 -0
  32. {treeig-0.2.1 → treeig-0.2.2}/benchmarks/cuda_prediction.py +0 -0
  33. {treeig-0.2.1 → treeig-0.2.2}/benchmarks/probability_forests.py +0 -0
  34. {treeig-0.2.1 → treeig-0.2.2}/benchmarks/treeig_vs_treeshap.py +0 -0
  35. {treeig-0.2.1 → treeig-0.2.2}/benchmarks/weighted_baselines_cpu.py +0 -0
  36. {treeig-0.2.1 → treeig-0.2.2}/docs/Figure_BoundaryCrossings.svg +0 -0
  37. {treeig-0.2.1 → treeig-0.2.2}/docs/Figure_TreeGradient.svg +0 -0
  38. {treeig-0.2.1 → treeig-0.2.2}/docs/_templates/documentation-nav.html +0 -0
  39. {treeig-0.2.1 → treeig-0.2.2}/docs/comparison.md +0 -0
  40. {treeig-0.2.1 → treeig-0.2.2}/docs/gpu-benchmarks.md +0 -0
  41. {treeig-0.2.1 → treeig-0.2.2}/docs/gpu.md +0 -0
  42. {treeig-0.2.1 → treeig-0.2.2}/docs/loss.md +0 -0
  43. {treeig-0.2.1 → treeig-0.2.2}/docs/performance.md +0 -0
  44. {treeig-0.2.1 → treeig-0.2.2}/docs/references.md +0 -0
  45. {treeig-0.2.1 → treeig-0.2.2}/setup.cfg +0 -0
  46. {treeig-0.2.1 → treeig-0.2.2}/tests/test_binsearch.py +0 -0
  47. {treeig-0.2.1 → treeig-0.2.2}/tests/test_cuda_backend.py +0 -0
  48. {treeig-0.2.1 → treeig-0.2.2}/tests/test_explanation.py +0 -0
  49. {treeig-0.2.1 → treeig-0.2.2}/tests/test_optional_cuda.py +0 -0
  50. {treeig-0.2.1 → treeig-0.2.2}/tests/test_treeig.py +0 -0
  51. {treeig-0.2.1 → treeig-0.2.2}/treeig/__init__.py +0 -0
  52. {treeig-0.2.1 → treeig-0.2.2}/treeig/api.py +0 -0
  53. {treeig-0.2.1 → treeig-0.2.2}/treeig/core.py +0 -0
  54. {treeig-0.2.1 → treeig-0.2.2}/treeig/cuda_backend.py +0 -0
  55. {treeig-0.2.1 → treeig-0.2.2}/treeig/dispatch.py +0 -0
  56. {treeig-0.2.1 → treeig-0.2.2}/treeig/explanation.py +0 -0
  57. {treeig-0.2.1 → treeig-0.2.2}/treeig/gpu.py +0 -0
  58. {treeig-0.2.1 → treeig-0.2.2}/treeig/lightgbm_backend.py +0 -0
  59. {treeig-0.2.1 → treeig-0.2.2}/treeig/sklearn_backend.py +0 -0
  60. {treeig-0.2.1 → treeig-0.2.2}/treeig/utils.py +0 -0
  61. {treeig-0.2.1 → treeig-0.2.2}/treeig/xgboost_backend.py +0 -0
  62. {treeig-0.2.1 → treeig-0.2.2}/treeig.egg-info/dependency_links.txt +0 -0
  63. {treeig-0.2.1 → 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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: treeig
3
- Version: 0.2.1
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
@@ -26,6 +26,7 @@ Requires-Dist: numpy>=1.24
26
26
  Requires-Dist: numba>=0.58
27
27
  Provides-Extra: docs
28
28
  Requires-Dist: sphinx<9,>=7; extra == "docs"
29
+ Requires-Dist: sphinx-sitemap<3,>=2.6; extra == "docs"
29
30
  Requires-Dist: myst-parser<5,>=3; extra == "docs"
30
31
  Requires-Dist: pydata-sphinx-theme<0.17,>=0.16; extra == "docs"
31
32
  Provides-Extra: cuda
@@ -62,36 +63,49 @@ Dynamic: license-file
62
63
  [![PyPI version](https://img.shields.io/pypi/v/treeig.svg)](https://pypi.org/project/treeig/)
63
64
  [![Documentation](https://img.shields.io/badge/docs-user%20guide-blue)](https://ludgerhentschel.github.io/treeig/)
64
65
 
65
- TreeIG computes exact Integrated Gradients for tree-based models. It attributes
66
- the change in a model's scalar output from a baseline to an observation to the
67
- input features. For one baseline $x_0$,
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.
68
70
 
69
- $$\sum_j \phi_j = F(x) - F(x_0).$$
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.**
70
73
 
71
- TreeIG finds the split boundaries crossed along the straight-line path and sums
72
- their prediction jumps. For supported models, this avoids numerical integration
73
- and sampling. Weighted baseline distributions are supported as well.
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.
74
80
 
75
- The method is developed in Ludger Hentschel's
76
- [**TreeIG: Exact Integrated Gradients for Tree-Based Models**](https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf).
77
- It builds on Integrated Gradients introduced by Sundararajan, Taly, and Yan in
78
- [**Axiomatic Attribution for Deep Networks** (ICML 2017)](https://proceedings.mlr.press/v70/sundararajan17a.html).
79
-
80
- ## Why Integrated Gradients works for trees
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.
81
85
 
82
- A tree prediction is constant between splits, so its ordinary gradient is zero
83
- almost everywhere. But the prediction jumps at split boundaries. Those jumps
84
- are the contribution that an ordinary pointwise gradient misses: in the
85
- distributional interpretation, each jump is an impulse whose integral equals
86
- 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.
87
89
 
88
90
  ![A prediction step, its derivative impulse, and its integrated contribution](https://raw.githubusercontent.com/LudgerHentschel/treeig/main/docs/Figure_TreeGradient.svg)
89
91
 
90
92
  The top panel shows a single prediction step; the middle shows its derivative
91
93
  as an impulse at the split; the bottom shows the accumulated contribution.
92
- Integrating across the split recovers the prediction change. TreeIG applies
93
- this idea along the path from a baseline to an observation, assigning each
94
- crossing's jump to its split feature and summing across trees.
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).
95
109
 
96
110
  ## Installation
97
111
 
@@ -105,7 +119,9 @@ for plotting. The first attribution call includes Numba compilation.
105
119
 
106
120
  ## Quickstart
107
121
 
108
- With a fitted supported model and numeric evaluation data:
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).
109
125
 
110
126
  ```python
111
127
  from treeig import TreeIG
@@ -136,7 +152,11 @@ splits and missing-value routing are not supported by the exact parser.
136
152
 
137
153
  `TreeIGNumeric` provides a numerical fallback for other piecewise-constant models,
138
154
  including numeric-input CatBoost and probability-only classifiers. Its resolution
139
- requires care. See [supported models](https://ludgerhentschel.github.io/treeig/models.html)
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)
140
160
  and [the numerical guide](https://ludgerhentschel.github.io/treeig/numeric.html).
141
161
 
142
162
  TreeIG and TreeSHAP answer different attribution questions. TreeIG can be fast
@@ -146,6 +166,9 @@ explain the distinction and report measured examples.
146
166
 
147
167
  ## Documentation
148
168
 
169
+ For automated readers, [llms.txt](https://ludgerhentschel.github.io/treeig/llms.txt)
170
+ maps the guides, complete examples, and rendered API reference.
171
+
149
172
  The [user guide](https://ludgerhentschel.github.io/treeig/)
150
173
  covers a complete runnable example, baseline distributions, classification,
151
174
  plots, loss attribution, numerical conventions, and performance. The Sphinx
@@ -161,6 +184,18 @@ the reported workloads. Performance depends on the problem. See
161
184
  [GPU documentation](https://ludgerhentschel.github.io/treeig/gpu.html)
162
185
  for installation and limitations.
163
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
+
164
199
  ## Citation and license
165
200
 
166
201
  If you use TreeIG in your work, please cite the
@@ -176,3 +211,5 @@ If you use TreeIG in your work, please cite the
176
211
  ```
177
212
 
178
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).
@@ -3,37 +3,50 @@
3
3
  [![PyPI version](https://img.shields.io/pypi/v/treeig.svg)](https://pypi.org/project/treeig/)
4
4
  [![Documentation](https://img.shields.io/badge/docs-user%20guide-blue)](https://ludgerhentschel.github.io/treeig/)
5
5
 
6
- TreeIG computes exact Integrated Gradients for tree-based models. It attributes
7
- the change in a model's scalar output from a baseline to an observation to the
8
- input features. For one baseline $x_0$,
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.
9
29
 
10
- $$\sum_j \phi_j = F(x) - F(x_0).$$
30
+ ![A prediction step, its derivative impulse, and its integrated contribution](https://raw.githubusercontent.com/LudgerHentschel/treeig/main/docs/Figure_TreeGradient.svg)
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
11
39
 
12
- TreeIG finds the split boundaries crossed along the straight-line path and sums
13
- their prediction jumps. For supported models, this avoids numerical integration
14
- and sampling. Weighted baseline distributions are supported as well.
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.
15
44
 
16
45
  The method is developed in Ludger Hentschel's
17
46
  [**TreeIG: Exact Integrated Gradients for Tree-Based Models**](https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf).
18
47
  It builds on Integrated Gradients introduced by Sundararajan, Taly, and Yan in
19
48
  [**Axiomatic Attribution for Deep Networks** (ICML 2017)](https://proceedings.mlr.press/v70/sundararajan17a.html).
20
49
 
21
- ## Why Integrated Gradients works for trees
22
-
23
- A tree prediction is constant between splits, so its ordinary gradient is zero
24
- almost everywhere. But the prediction jumps at split boundaries. Those jumps
25
- are the contribution that an ordinary pointwise gradient misses: in the
26
- distributional interpretation, each jump is an impulse whose integral equals
27
- the jump's height.
28
-
29
- ![A prediction step, its derivative impulse, and its integrated contribution](https://raw.githubusercontent.com/LudgerHentschel/treeig/main/docs/Figure_TreeGradient.svg)
30
-
31
- The top panel shows a single prediction step; the middle shows its derivative
32
- as an impulse at the split; the bottom shows the accumulated contribution.
33
- Integrating across the split recovers the prediction change. TreeIG applies
34
- this idea along the path from a baseline to an observation, assigning each
35
- crossing's jump to its split feature and summing across trees.
36
-
37
50
  ## Installation
38
51
 
39
52
  ```bash
@@ -46,7 +59,9 @@ for plotting. The first attribution call includes Numba compilation.
46
59
 
47
60
  ## Quickstart
48
61
 
49
- With a fitted supported model and numeric evaluation data:
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).
50
65
 
51
66
  ```python
52
67
  from treeig import TreeIG
@@ -77,7 +92,11 @@ splits and missing-value routing are not supported by the exact parser.
77
92
 
78
93
  `TreeIGNumeric` provides a numerical fallback for other piecewise-constant models,
79
94
  including numeric-input CatBoost and probability-only classifiers. Its resolution
80
- requires care. See [supported models](https://ludgerhentschel.github.io/treeig/models.html)
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)
81
100
  and [the numerical guide](https://ludgerhentschel.github.io/treeig/numeric.html).
82
101
 
83
102
  TreeIG and TreeSHAP answer different attribution questions. TreeIG can be fast
@@ -87,6 +106,9 @@ explain the distinction and report measured examples.
87
106
 
88
107
  ## Documentation
89
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
+
90
112
  The [user guide](https://ludgerhentschel.github.io/treeig/)
91
113
  covers a complete runnable example, baseline distributions, classification,
92
114
  plots, loss attribution, numerical conventions, and performance. The Sphinx
@@ -102,6 +124,18 @@ the reported workloads. Performance depends on the problem. See
102
124
  [GPU documentation](https://ludgerhentschel.github.io/treeig/gpu.html)
103
125
  for installation and limitations.
104
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
+
105
139
  ## Citation and license
106
140
 
107
141
  If you use TreeIG in your work, please cite the
@@ -117,3 +151,5 @@ If you use TreeIG in your work, please cite the
117
151
  ```
118
152
 
119
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).
@@ -1,3 +1,9 @@
1
+ ---
2
+ myst:
3
+ html_meta:
4
+ description: "Look up TreeIG, TreeIGNumeric, Explanation, and public functions in the rendered API reference."
5
+ ---
6
+
1
7
  # API reference
2
8
 
3
9
  The primary interfaces are `TreeIG` for exact structural attribution,
@@ -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.** CBaseline produces empirical,
18
- prediction-neutral baseline *distributions* whose weighted mean model output is
19
- the chosen reference prediction. TreeIG then explains the model prediction
20
- relative to that reference level rather than relative to an arbitrary feature
21
- vector such as the feature-wise mean.
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
@@ -9,6 +9,7 @@ From the repository root, using Python 3.11 or later:
9
9
  ```bash
10
10
  python -m pip install -e ".[docs]"
11
11
  python -m sphinx -W --keep-going -b html docs docs/_build/html
12
+ python scripts/check_docs_discovery.py
12
13
  ```
13
14
 
14
15
  Open `docs/_build/html/index.html` in a browser. Documentation dependencies are
@@ -26,3 +27,19 @@ 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,
27
28
  a first example, and links into the guide. Version information comes from
28
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,3 +1,9 @@
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?
@@ -8,7 +8,7 @@ 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"]
@@ -21,3 +21,9 @@ napoleon_google_docstring = False
21
21
 
22
22
  templates_path = ["_templates"]
23
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: "Run complete TreeIG examples for XGBoost regression and LightGBM multiclass margins."
5
+ ---
6
+
1
7
  # Worked examples
2
8
 
3
9
  These examples use synthetic data so they can run without downloading datasets.
@@ -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. TreeIGNumeric can use the explicit
82
- probability-derived score convention above when no native margin exists.
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
 
@@ -1,3 +1,9 @@
1
+ ---
2
+ myst:
3
+ html_meta:
4
+ description: "Install TreeIG and run a complete regression example with fitted tree models, baseline inputs, and completeness checks."
5
+ ---
6
+
1
7
  # Getting started
2
8
 
3
9
  ## Installation
@@ -1,3 +1,9 @@
1
+ ---
2
+ myst:
3
+ html_meta:
4
+ description: "Choose between TreeIG, UnifiedIG, CBaseline, and skgrad for tree paths, attribution, reference distributions, and input derivatives."
5
+ ---
6
+
1
7
  # The Integrated Gradients Stack
2
8
 
3
9
  | Package | Responsibility |
@@ -29,5 +35,5 @@ combine a score gradient with a probability-valued baseline prediction.
29
35
  evaluate analytic gradients, including supported preprocessing pipelines.
30
36
  - [TreeIG documentation](https://ludgerhentschel.github.io/treeig/):
31
37
  compute Integrated Gradients for supported tree models.
32
- - [UnifiedIG guide](https://github.com/LudgerHentschel/unifiedig/blob/main/docs/how-it-works.md):
38
+ - [UnifiedIG guide](https://ludgerhentschel.github.io/unifiedig/how-it-works.html):
33
39
  select the attribution backend through a common interface.
@@ -0,0 +1,106 @@
1
+ ---
2
+ myst:
3
+ html_meta:
4
+ description: "TreeIG computes exact Integrated Gradients for supported numeric tree models, with weighted baselines and a separate numerical fallback."
5
+ ---
6
+
7
+ # TreeIG documentation
8
+
9
+ TreeIG is a Python package for Integrated Gradients feature attribution on
10
+ supported numeric tree models. Install and import it as `treeig`. Given a fitted
11
+ model, a baseline point or weighted background, and evaluation rows, `TreeIG`
12
+ returns feature contributions and completeness diagnostics.
13
+
14
+ **TreeIG computes exact Integrated Gradients for supported numeric tree models.
15
+ A tree's gradient is zero almost everywhere; its integrated gradient is not.**
16
+
17
+ Check [supported models](models.md) before choosing an interface.
18
+ `TreeIG` uses exact structural split crossings; [TreeIGNumeric](numeric.md)
19
+ is a separately selected numerical fallback. Exact classification explains raw
20
+ margins or logits. Exact parsing requires finite numeric inputs and does not
21
+ support categorical splits or missing-value routing. Installing the CatBoost
22
+ extra does not add an exact CatBoost backend.
23
+
24
+ Tree ensembles are piecewise constant, so $\nabla F = 0$ except on a
25
+ measure-zero set of split boundaries. Numerical Integrated Gradients therefore
26
+ recovers approximately nothing, which is why IG has largely been confined to
27
+ differentiable models.
28
+
29
+ The pointwise gradient is not the full derivative. In the distributional sense,
30
+ $F'$ carries an impulse at each split boundary whose integral equals the
31
+ prediction jump there.
32
+
33
+ ![A prediction step, its derivative impulse, and its integrated contribution](Figure_TreeGradient.svg)
34
+
35
+ The top panel shows a single prediction step; the middle shows its derivative
36
+ as an impulse at the split; the bottom shows the accumulated contribution.
37
+ Integrating across the split recovers the prediction change.
38
+
39
+ TreeIG enumerates the boundaries crossed by the straight-line path from baseline
40
+ to observation, assigns each jump to its split feature, and sums across trees.
41
+ No quadrature and no sampling are involved, and completeness
42
+
43
+ $$\sum_j \phi_j = F(x) - F(x_0)$$
44
+
45
+ holds to the floating-point precision of the fitted model's own arithmetic.
46
+ Weighted baseline distributions are supported directly.
47
+
48
+ The CPU `TreeIG` class is the main interface. Start with a runnable example,
49
+ then choose the baseline distribution and output scale that express the
50
+ comparison you want to explain.
51
+
52
+ The method is developed in Ludger Hentschel's
53
+ [**TreeIG: Exact Integrated Gradients for Tree-Based Models**](https://www.ludgerhentschel.com/PDFs/Hentschel%20'26g.pdf).
54
+ It builds on Integrated Gradients introduced by Sundararajan, Taly, and Yan in
55
+ [**Axiomatic Attribution for Deep Networks** (ICML 2017)](https://proceedings.mlr.press/v70/sundararajan17a.html).
56
+
57
+ ## Explore the guide
58
+
59
+ For automated readers, [llms.txt](https://ludgerhentschel.github.io/treeig/llms.txt)
60
+ maps the guides, complete examples, and rendered API reference.
61
+
62
+ Read [getting started](getting-started.md), [baselines](baselines.md),
63
+ [supported models](models.md), and [worked examples](examples.md) first.
64
+ For more detail, see [results and plotting](explanations.md),
65
+ [loss attribution](loss.md), [numerical conventions](concepts.md),
66
+ [TreeIGNumeric](numeric.md), and [performance](performance.md).
67
+
68
+ ## Related projects
69
+
70
+ | Package | When to use it |
71
+ |---|---|
72
+ | [UnifiedIG](https://ludgerhentschel.github.io/unifiedig/) (`unifiedig`) | A common Integrated Gradients interface across supported tree and smooth model families. |
73
+ | [CBaseline](https://ludgerhentschel.github.io/cbaseline/) (`cbaseline`) | Construct empirical reference distributions; TreeIG accepts its backgrounds with their weights directly. |
74
+ | [skgrad](https://ludgerhentschel.github.io/skgrad/) (`skgrad`) | Obtain analytic input gradients and Jacobians for supported smooth scikit-learn models. |
75
+
76
+ Use TreeIG directly when you need its tree-specific attribution interface.
77
+ See [the Integrated Gradients stack](https://ludgerhentschel.github.io/treeig/ig-stack.html)
78
+ for how the packages compose and why output scales must agree.
79
+
80
+ ```{toctree}
81
+ :maxdepth: 2
82
+ :caption: User guide
83
+
84
+ getting-started
85
+ examples
86
+ baselines
87
+ models
88
+ explanations
89
+ loss
90
+ concepts
91
+ numeric
92
+ performance
93
+ comparison
94
+ gpu
95
+ ig-stack
96
+ ```
97
+
98
+ ```{toctree}
99
+ :maxdepth: 1
100
+ :caption: Reference
101
+
102
+ api
103
+ references
104
+ building
105
+ publishing
106
+ ```
@@ -1,3 +1,9 @@
1
+ ---
2
+ myst:
3
+ html_meta:
4
+ description: "Check exact TreeIG model support, classification margins, parser restrictions, and models requiring TreeIGNumeric."
5
+ ---
6
+
1
7
  # Supported models
2
8
 
3
9
  TreeIG currently supports tree models with finite numeric feature inputs.
@@ -1,3 +1,9 @@
1
+ ---
2
+ myst:
3
+ html_meta:
4
+ description: "Use TreeIGNumeric for explicit numerical jump detection and understand probability outputs, score conversion, and resolution limits."
5
+ ---
6
+
1
7
  # TreeIGNumeric
2
8
 
3
9
  TreeIGNumeric is a model-agnostic fallback that recovers the crossing-sum
@@ -36,10 +42,10 @@ Two caveats on coverage:
36
42
  feature along the straight-line path is not meaningful, which is a property of
37
43
  Integrated Gradients itself, not of the implementation. TreeIGNumeric works on
38
44
  CatBoost (and similar) models with numeric or one-hot-encoded inputs.
39
- - **Probability-averaging classifiers.** By default, TreeIGNumeric retains its
40
- original behavior and explains one class probability. With
41
- `probability_to_score=True`, it instead explains binary log odds or a
42
- centered multiclass log score. Zero probabilities require an explicit
45
+ - **Probability-averaging classifiers.** By default, TreeIGNumeric explains
46
+ binary log odds or a centered multiclass log score derived from the complete
47
+ probability vector (`probability_to_score=True`). Class-probability
48
+ attribution requires explicit `probability_to_score=False`. Zero probabilities require an explicit
43
49
  `probability_floor`; TreeIGNumeric never clips them silently.
44
50
 
45
51
  ```python
@@ -60,7 +66,7 @@ ig = tig.TreeIGNumeric(
60
66
  model,
61
67
  baseline=x0,
62
68
  target=2, # omit for binary positive-class log odds
63
- probability_to_score=True,
69
+ # Score conversion is the default when no native margin exists.
64
70
  probability_floor=1e-6, # explicit because tree probabilities may be 0
65
71
  )
66
72
  phi = ig.attribute(X_eval)
@@ -102,3 +108,14 @@ Bundling may change the feature allocation, and offsetting jumps inside a cell
102
108
  can remain invisible even with a zero residual. These are allocation limitations,
103
109
  not reasons to require exhaustive refinement or replace event detection with
104
110
  generic numerical Integrated Gradients.
111
+
112
+ ## Compatibility with earlier releases
113
+
114
+ Previously, probability-only classifiers defaulted to class-probability
115
+ attribution. The default now explains scores. Existing callers that require the
116
+ previous probability-valued result must pass `probability_to_score=False`
117
+ explicitly. This option affects only classifiers without a native margin;
118
+ models exposing native scores continue to explain those scores. Zero class
119
+ probabilities now raise by default during score evaluation unless an explicit
120
+ `probability_floor` defines finite scores. Reconstruct background reference
121
+ outputs on the same scale as the explainer before comparing attributions.