gpe-framework 1.2.0__tar.gz → 1.3.0__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.
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/PKG-INFO +46 -6
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/README.md +45 -5
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe/__init__.py +14 -1
- gpe_framework-1.3.0/gpe/certified.py +508 -0
- gpe_framework-1.3.0/gpe/compiled.py +206 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe/core.py +6 -1
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe/explanation.py +96 -12
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe/novel_methods.py +30 -60
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe/tree_utils.py +99 -3
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe/variants.py +4 -4
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe_framework.egg-info/PKG-INFO +46 -6
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe_framework.egg-info/SOURCES.txt +4 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/setup.py +1 -1
- gpe_framework-1.3.0/tests/test_certified.py +670 -0
- gpe_framework-1.3.0/tests/test_facts.py +185 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/LICENSE +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/baselines/__init__.py +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/baselines/anchors_wrapper.py +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/baselines/lime_wrapper.py +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/baselines/shap_wrapper.py +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe/metrics.py +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe/visualization.py +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe_framework.egg-info/dependency_links.txt +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe_framework.egg-info/requires.txt +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/gpe_framework.egg-info/top_level.txt +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/setup.cfg +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/tests/test_core.py +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/tests/test_metrics.py +0 -0
- {gpe_framework-1.2.0 → gpe_framework-1.3.0}/tests/test_variants.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gpe-framework
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Greedy-Prune-Explain: Minimal local explanations for decision tree predictions
|
|
5
5
|
Home-page: https://github.com/vladdehtiarov/gpe-framework
|
|
6
6
|
Author: Vladyslav Dehtiarov
|
|
@@ -146,6 +146,7 @@ This explanation covers 33.3% of similar cases with 100.0% accuracy.
|
|
|
146
146
|
```python
|
|
147
147
|
from gpe import (
|
|
148
148
|
GPEExplainer, # Standard (fast, greedy)
|
|
149
|
+
CertifiedGPE, # Finite-sample precision guarantee
|
|
149
150
|
GPEInformationTheoretic, # Uses mutual information for pruning
|
|
150
151
|
GPECounterfactual, # Adds counterfactual explanations
|
|
151
152
|
GPEOptimal, # Exhaustive search for minimal rule
|
|
@@ -231,12 +232,49 @@ coverage = coverage_score(explanation, X)
|
|
|
231
232
|
complexity = complexity_score(explanation)
|
|
232
233
|
```
|
|
233
234
|
|
|
234
|
-
##
|
|
235
|
+
## 🔒 Certified-GPE
|
|
235
236
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
`GPEExplainer` checks precision on the background data, so the rule it picks can fall below the threshold on new data. `CertifiedGPE` gives a finite-sample guarantee instead: with probability at least `1 - delta` over the calibration set, the rule's population precision is at least `min_precision`.
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from gpe import CertifiedGPE
|
|
241
|
+
|
|
242
|
+
# X_cal must not have been used to fit or tune the tree
|
|
243
|
+
explainer = CertifiedGPE(model, X_cal, min_precision=0.95, delta=0.05)
|
|
244
|
+
explanation = explainer.explain(x)
|
|
245
|
+
|
|
246
|
+
cert = explanation.certificate
|
|
247
|
+
print(explanation.rule, cert.lower_bound, cert.K, cert.n, cert.trivial)
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
The rule comes from the subsets of the decision path. The levels of a Clopper-Pearson bound are split over all `2^k - 2` subsets (Berk et al., 2013; Angelopoulos et al., 2025), so the guarantee covers any search. Up to 20 literals `search='auto'` enumerates all subsets and returns a shortest certified rule; above that it is greedy.
|
|
251
|
+
|
|
252
|
+
What it does not cover:
|
|
253
|
+
|
|
254
|
+
- It concerns fidelity to the model under the calibration distribution, not the correctness of the prediction. It does not survive distribution shift or a refit.
|
|
255
|
+
- It holds for one explanation at a time. For the whole tree at once use `compile_explanations(explainer, simultaneous=True)`.
|
|
256
|
+
- It is conservative and needs data. A rule with no errors needs `min_coverage(k)` calibration rows: 194 at `k=10`, `tau=0.95`, `delta=0.05`. When nothing can be certified, the full path is returned with `cert.trivial=True`; its precision is exactly 1 because its region lies inside one leaf.
|
|
257
|
+
- `interval='wilson'` has no finite-sample coverage, and its certificates carry `guarantee=False`.
|
|
258
|
+
- With imbalanced classes, high precision can just mean the base rate. Use `min_lift` to require the rule to beat it.
|
|
259
|
+
|
|
260
|
+
## 📦 Compiled Explanations
|
|
261
|
+
|
|
262
|
+
For `GPEExplainer`, `GPEInformationTheoretic` and `CertifiedGPE`, the explanation of an instance depends only on its leaf. All rules can be computed once and looked up without background data:
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
from gpe import compile_explanations
|
|
266
|
+
|
|
267
|
+
table = compile_explanations(explainer)
|
|
268
|
+
explanation = table.explain(x)
|
|
269
|
+
arrays = table.to_arrays() # leaf_ids, bit masks over the path, K, n
|
|
270
|
+
print(table.storage_bytes()) # size on top of the tree itself
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## 🔬 Method Properties
|
|
274
|
+
|
|
275
|
+
1. **GPE-Core** — rules from subsets of the decision path, evaluated on real data rather than perturbations
|
|
276
|
+
2. **GPE-IT** — literal order from conditional mutual information; a heuristic with no guarantee
|
|
277
|
+
3. **Certified-GPE** — finite-sample lower bound on population precision
|
|
240
278
|
|
|
241
279
|
## 📁 Project Structure
|
|
242
280
|
|
|
@@ -245,6 +283,8 @@ gpe-framework/
|
|
|
245
283
|
├── gpe/
|
|
246
284
|
│ ├── __init__.py # Public API
|
|
247
285
|
│ ├── core.py # GPEExplainer
|
|
286
|
+
│ ├── certified.py # CertifiedGPE, confidence bounds
|
|
287
|
+
│ ├── compiled.py # compile_explanations: leaf-to-rule table
|
|
248
288
|
│ ├── novel_methods.py # GPE-IT, GPE-CF (scientific contribution)
|
|
249
289
|
│ ├── variants.py # GPEOptimal, GPEWeighted, GPEMonotonic, GPEEnsemble
|
|
250
290
|
│ ├── explanation.py # Data structures
|
|
@@ -95,6 +95,7 @@ This explanation covers 33.3% of similar cases with 100.0% accuracy.
|
|
|
95
95
|
```python
|
|
96
96
|
from gpe import (
|
|
97
97
|
GPEExplainer, # Standard (fast, greedy)
|
|
98
|
+
CertifiedGPE, # Finite-sample precision guarantee
|
|
98
99
|
GPEInformationTheoretic, # Uses mutual information for pruning
|
|
99
100
|
GPECounterfactual, # Adds counterfactual explanations
|
|
100
101
|
GPEOptimal, # Exhaustive search for minimal rule
|
|
@@ -180,12 +181,49 @@ coverage = coverage_score(explanation, X)
|
|
|
180
181
|
complexity = complexity_score(explanation)
|
|
181
182
|
```
|
|
182
183
|
|
|
183
|
-
##
|
|
184
|
+
## 🔒 Certified-GPE
|
|
184
185
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
`GPEExplainer` checks precision on the background data, so the rule it picks can fall below the threshold on new data. `CertifiedGPE` gives a finite-sample guarantee instead: with probability at least `1 - delta` over the calibration set, the rule's population precision is at least `min_precision`.
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from gpe import CertifiedGPE
|
|
190
|
+
|
|
191
|
+
# X_cal must not have been used to fit or tune the tree
|
|
192
|
+
explainer = CertifiedGPE(model, X_cal, min_precision=0.95, delta=0.05)
|
|
193
|
+
explanation = explainer.explain(x)
|
|
194
|
+
|
|
195
|
+
cert = explanation.certificate
|
|
196
|
+
print(explanation.rule, cert.lower_bound, cert.K, cert.n, cert.trivial)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The rule comes from the subsets of the decision path. The levels of a Clopper-Pearson bound are split over all `2^k - 2` subsets (Berk et al., 2013; Angelopoulos et al., 2025), so the guarantee covers any search. Up to 20 literals `search='auto'` enumerates all subsets and returns a shortest certified rule; above that it is greedy.
|
|
200
|
+
|
|
201
|
+
What it does not cover:
|
|
202
|
+
|
|
203
|
+
- It concerns fidelity to the model under the calibration distribution, not the correctness of the prediction. It does not survive distribution shift or a refit.
|
|
204
|
+
- It holds for one explanation at a time. For the whole tree at once use `compile_explanations(explainer, simultaneous=True)`.
|
|
205
|
+
- It is conservative and needs data. A rule with no errors needs `min_coverage(k)` calibration rows: 194 at `k=10`, `tau=0.95`, `delta=0.05`. When nothing can be certified, the full path is returned with `cert.trivial=True`; its precision is exactly 1 because its region lies inside one leaf.
|
|
206
|
+
- `interval='wilson'` has no finite-sample coverage, and its certificates carry `guarantee=False`.
|
|
207
|
+
- With imbalanced classes, high precision can just mean the base rate. Use `min_lift` to require the rule to beat it.
|
|
208
|
+
|
|
209
|
+
## 📦 Compiled Explanations
|
|
210
|
+
|
|
211
|
+
For `GPEExplainer`, `GPEInformationTheoretic` and `CertifiedGPE`, the explanation of an instance depends only on its leaf. All rules can be computed once and looked up without background data:
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
from gpe import compile_explanations
|
|
215
|
+
|
|
216
|
+
table = compile_explanations(explainer)
|
|
217
|
+
explanation = table.explain(x)
|
|
218
|
+
arrays = table.to_arrays() # leaf_ids, bit masks over the path, K, n
|
|
219
|
+
print(table.storage_bytes()) # size on top of the tree itself
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## 🔬 Method Properties
|
|
223
|
+
|
|
224
|
+
1. **GPE-Core** — rules from subsets of the decision path, evaluated on real data rather than perturbations
|
|
225
|
+
2. **GPE-IT** — literal order from conditional mutual information; a heuristic with no guarantee
|
|
226
|
+
3. **Certified-GPE** — finite-sample lower bound on population precision
|
|
189
227
|
|
|
190
228
|
## 📁 Project Structure
|
|
191
229
|
|
|
@@ -194,6 +232,8 @@ gpe-framework/
|
|
|
194
232
|
├── gpe/
|
|
195
233
|
│ ├── __init__.py # Public API
|
|
196
234
|
│ ├── core.py # GPEExplainer
|
|
235
|
+
│ ├── certified.py # CertifiedGPE, confidence bounds
|
|
236
|
+
│ ├── compiled.py # compile_explanations: leaf-to-rule table
|
|
197
237
|
│ ├── novel_methods.py # GPE-IT, GPE-CF (scientific contribution)
|
|
198
238
|
│ ├── variants.py # GPEOptimal, GPEWeighted, GPEMonotonic, GPEEnsemble
|
|
199
239
|
│ ├── explanation.py # Data structures
|
|
@@ -45,7 +45,7 @@ Email: vvdehtiarov@gmail.com
|
|
|
45
45
|
License: MIT
|
|
46
46
|
"""
|
|
47
47
|
|
|
48
|
-
__version__ = "1.
|
|
48
|
+
__version__ = "1.3.0"
|
|
49
49
|
__author__ = "Vladyslav Dehtiarov"
|
|
50
50
|
__email__ = "vvdehtiarov@gmail.com"
|
|
51
51
|
__license__ = "MIT"
|
|
@@ -53,6 +53,10 @@ __license__ = "MIT"
|
|
|
53
53
|
# Core
|
|
54
54
|
from .core import GPEExplainer
|
|
55
55
|
|
|
56
|
+
# Certified explanations and leaf tables
|
|
57
|
+
from .certified import CertifiedGPE, lower_bound, min_coverage
|
|
58
|
+
from .compiled import CompiledExplanations, compile_explanations
|
|
59
|
+
|
|
56
60
|
# Variants
|
|
57
61
|
from .variants import (
|
|
58
62
|
GPEOptimal,
|
|
@@ -75,6 +79,7 @@ from .novel_methods import (
|
|
|
75
79
|
|
|
76
80
|
# Data Structures
|
|
77
81
|
from .explanation import (
|
|
82
|
+
Certificate,
|
|
78
83
|
Explanation,
|
|
79
84
|
Rule,
|
|
80
85
|
Condition
|
|
@@ -108,6 +113,14 @@ __all__ = [
|
|
|
108
113
|
# Core Explainer
|
|
109
114
|
"GPEExplainer",
|
|
110
115
|
|
|
116
|
+
# Certified explanations and leaf tables
|
|
117
|
+
"CertifiedGPE",
|
|
118
|
+
"Certificate",
|
|
119
|
+
"CompiledExplanations",
|
|
120
|
+
"compile_explanations",
|
|
121
|
+
"lower_bound",
|
|
122
|
+
"min_coverage",
|
|
123
|
+
|
|
111
124
|
# Variants
|
|
112
125
|
"GPEOptimal",
|
|
113
126
|
"GPEWeighted",
|