compileml 0.1.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.
- compileml-0.1.0/LICENSE +201 -0
- compileml-0.1.0/NOTICE +5 -0
- compileml-0.1.0/PKG-INFO +375 -0
- compileml-0.1.0/README.md +323 -0
- compileml-0.1.0/pyproject.toml +105 -0
- compileml-0.1.0/setup.cfg +4 -0
- compileml-0.1.0/src/compileml/__init__.py +17 -0
- compileml-0.1.0/src/compileml/artifact/__init__.py +7 -0
- compileml-0.1.0/src/compileml/artifact/build.py +241 -0
- compileml-0.1.0/src/compileml/artifact/calibration.py +52 -0
- compileml-0.1.0/src/compileml/artifact/recalibrate.py +98 -0
- compileml-0.1.0/src/compileml/bands/__init__.py +15 -0
- compileml-0.1.0/src/compileml/bands/builders.py +123 -0
- compileml-0.1.0/src/compileml/bands/certified.py +496 -0
- compileml-0.1.0/src/compileml/cli.py +261 -0
- compileml-0.1.0/src/compileml/compile/__init__.py +26 -0
- compileml-0.1.0/src/compileml/compile/distill.py +61 -0
- compileml-0.1.0/src/compileml/compile/extract.py +304 -0
- compileml-0.1.0/src/compileml/compile/quantize.py +78 -0
- compileml-0.1.0/src/compileml/export/__init__.py +10 -0
- compileml-0.1.0/src/compileml/export/cobol.py +190 -0
- compileml-0.1.0/src/compileml/export/sql.py +134 -0
- compileml-0.1.0/src/compileml/py.typed +0 -0
- compileml-0.1.0/src/compileml/runtime/__init__.py +47 -0
- compileml-0.1.0/src/compileml/runtime/_intmath.py +29 -0
- compileml-0.1.0/src/compileml/runtime/bands.py +27 -0
- compileml-0.1.0/src/compileml/runtime/calibrate.py +38 -0
- compileml-0.1.0/src/compileml/runtime/decide.py +144 -0
- compileml-0.1.0/src/compileml/runtime/explain.py +134 -0
- compileml-0.1.0/src/compileml/runtime/io.py +79 -0
- compileml-0.1.0/src/compileml/runtime/score.py +40 -0
- compileml-0.1.0/src/compileml/validate/__init__.py +5 -0
- compileml-0.1.0/src/compileml/validate/framework.py +275 -0
- compileml-0.1.0/src/compileml/viz/__init__.py +38 -0
- compileml-0.1.0/src/compileml/viz/_arrow.py +81 -0
- compileml-0.1.0/src/compileml/viz/_data.py +132 -0
- compileml-0.1.0/src/compileml/viz/plots.py +768 -0
- compileml-0.1.0/src/compileml/viz/svg.py +149 -0
- compileml-0.1.0/src/compileml.egg-info/PKG-INFO +375 -0
- compileml-0.1.0/src/compileml.egg-info/SOURCES.txt +51 -0
- compileml-0.1.0/src/compileml.egg-info/dependency_links.txt +1 -0
- compileml-0.1.0/src/compileml.egg-info/entry_points.txt +2 -0
- compileml-0.1.0/src/compileml.egg-info/requires.txt +26 -0
- compileml-0.1.0/src/compileml.egg-info/top_level.txt +1 -0
- compileml-0.1.0/tests/test_bands.py +169 -0
- compileml-0.1.0/tests/test_cli.py +179 -0
- compileml-0.1.0/tests/test_compile.py +240 -0
- compileml-0.1.0/tests/test_export.py +191 -0
- compileml-0.1.0/tests/test_reference.py +51 -0
- compileml-0.1.0/tests/test_runtime.py +251 -0
- compileml-0.1.0/tests/test_runtime_stdlib_only.py +56 -0
- compileml-0.1.0/tests/test_validate.py +145 -0
- compileml-0.1.0/tests/test_viz.py +272 -0
compileml-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Carlos Ortiz
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
compileml-0.1.0/NOTICE
ADDED
compileml-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: compileml
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Compile tree-ensemble models into deterministic, auditable, integer-exact decision artifacts — score, calibration, risk bands, and reason codes in one portable JSON, runnable with zero ML dependencies.
|
|
5
|
+
Author-email: Carlos Ortiz <orgoca@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/orgoca/CompileML
|
|
8
|
+
Project-URL: Documentation, https://orgoca.github.io/CompileML
|
|
9
|
+
Project-URL: Repository, https://github.com/orgoca/CompileML
|
|
10
|
+
Project-URL: Issues, https://github.com/orgoca/CompileML/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/orgoca/CompileML/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: credit-risk,model-deployment,explainability,determinism,scorecard,adverse-action,model-governance,xgboost,lightgbm,cobol
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
License-File: NOTICE
|
|
30
|
+
Requires-Dist: numpy>=1.24
|
|
31
|
+
Requires-Dist: scikit-learn>=1.3
|
|
32
|
+
Provides-Extra: xgboost
|
|
33
|
+
Requires-Dist: xgboost>=1.7; extra == "xgboost"
|
|
34
|
+
Provides-Extra: lightgbm
|
|
35
|
+
Requires-Dist: lightgbm>=4.0; extra == "lightgbm"
|
|
36
|
+
Provides-Extra: viz
|
|
37
|
+
Requires-Dist: matplotlib>=3.7; extra == "viz"
|
|
38
|
+
Requires-Dist: pandas>=2.0; extra == "viz"
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-cov>=4.1; extra == "dev"
|
|
42
|
+
Requires-Dist: hypothesis>=6.90; extra == "dev"
|
|
43
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
44
|
+
Requires-Dist: black>=24.0; extra == "dev"
|
|
45
|
+
Requires-Dist: mypy>=1.8; extra == "dev"
|
|
46
|
+
Requires-Dist: pandas>=2.0; extra == "dev"
|
|
47
|
+
Provides-Extra: docs
|
|
48
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
|
|
49
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
50
|
+
Requires-Dist: matplotlib>=3.7; extra == "docs"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# CompileML
|
|
54
|
+
|
|
55
|
+
[](https://github.com/orgoca/CompileML/actions/workflows/ci.yml)
|
|
56
|
+
[](https://pypi.org/project/compileml/)
|
|
57
|
+
[](https://pypi.org/project/compileml/)
|
|
58
|
+
[](LICENSE)
|
|
59
|
+
|
|
60
|
+
**Compile tree-ensemble models into deterministic, auditable decision artifacts.**
|
|
61
|
+
|
|
62
|
+
## The idea
|
|
63
|
+
|
|
64
|
+
Training a model and running a model are different problems.
|
|
65
|
+
|
|
66
|
+
Training happens in Python, with modern libraries and plenty of compute. Production may happen in a SQL warehouse, a constrained service, or a mainframe that has never heard of scikit-learn. In regulated decisions, the output also needs to be calibrated, assigned to a risk band, explained, validated, and reproduced later.
|
|
67
|
+
|
|
68
|
+
Too often, each of those steps develops its own version of the truth.
|
|
69
|
+
|
|
70
|
+
CompileML takes a fitted tree model and compiles the whole decision into one hashed JSON artifact:
|
|
71
|
+
|
|
72
|
+
* the score;
|
|
73
|
+
* the calibrated probability;
|
|
74
|
+
* the risk bands;
|
|
75
|
+
* the reason codes;
|
|
76
|
+
* and the information needed to explain the result.
|
|
77
|
+
|
|
78
|
+
That artifact can run through a standard-library-only Python runtime or be exported to SQL or COBOL. The important outputs are integers, so the same input produces the same score, band, probability, and explanation wherever the artifact runs.
|
|
79
|
+
|
|
80
|
+
The point is not to preserve Python everywhere. The point is to stop needing Python everywhere.
|
|
81
|
+
|
|
82
|
+
## Quick example
|
|
83
|
+
|
|
84
|
+
Train however you want. The example below uses a strong model as a teacher and distills it into a shallow whitebox:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from compileml.compile import train_whitebox
|
|
88
|
+
from compileml.bands import monotone_quantile_bands
|
|
89
|
+
from compileml.artifact import build_artifact, save_artifact
|
|
90
|
+
|
|
91
|
+
whitebox, fidelity = train_whitebox(
|
|
92
|
+
X_train,
|
|
93
|
+
teacher.predict_proba(X_train)[:, 1],
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
latent = whitebox.predict(X_train).clip(0, 1)
|
|
97
|
+
|
|
98
|
+
bands = monotone_quantile_bands(
|
|
99
|
+
latent,
|
|
100
|
+
y_train,
|
|
101
|
+
n_bands=10,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
artifact = build_artifact(
|
|
105
|
+
whitebox,
|
|
106
|
+
feature_names,
|
|
107
|
+
baseline=medians,
|
|
108
|
+
band_edges=bands,
|
|
109
|
+
calibration_latent=latent,
|
|
110
|
+
calibration_y=y_train,
|
|
111
|
+
reasons=REASON_DICTIONARY,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
save_artifact(artifact, "decision.json")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Production does not need the training stack:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from compileml.runtime import load_artifact, decide
|
|
121
|
+
|
|
122
|
+
artifact = load_artifact("decision.json")
|
|
123
|
+
decision = decide(artifact, applicant_row)
|
|
124
|
+
|
|
125
|
+
# {
|
|
126
|
+
# "band": "G07",
|
|
127
|
+
# "pd": 0.1284,
|
|
128
|
+
# "latent_int": 146,
|
|
129
|
+
# "reasons_negative": [
|
|
130
|
+
# {
|
|
131
|
+
# "code": "HIGH_UTILIZATION",
|
|
132
|
+
# "message": "…",
|
|
133
|
+
# "impact_int": 56,
|
|
134
|
+
# }
|
|
135
|
+
# ],
|
|
136
|
+
# "reasons_positive": [...],
|
|
137
|
+
# "artifact_hash": "84372c36…",
|
|
138
|
+
# }
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The runtime imports nothing outside the Python standard library.
|
|
142
|
+
|
|
143
|
+
Or skip the Python runtime entirely:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
compileml export decision.json --target sql --out scorer.sql
|
|
147
|
+
compileml export decision.json --target cobol --out scorer.cob
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Why I built this
|
|
151
|
+
|
|
152
|
+
I have seen good models become much less impressive on the way to production.
|
|
153
|
+
|
|
154
|
+
The model starts in Python. Someone rewrites it in SQL. Someone else builds the bands in a spreadsheet. Calibration lives in another script. Reason codes are produced through a separate explanation process. Six months later, everybody is discussing “the model,” but they are no longer talking about exactly the same thing.
|
|
155
|
+
|
|
156
|
+
Three problems show up repeatedly.
|
|
157
|
+
|
|
158
|
+
### Scores drift
|
|
159
|
+
|
|
160
|
+
Floating-point arithmetic is not a reassuring foundation for a decision that must be reproduced across languages and systems. Small differences in accumulation, precision, or implementation can move a score near a boundary.
|
|
161
|
+
|
|
162
|
+
A credit score should be a fact, not a distribution over environments.
|
|
163
|
+
|
|
164
|
+
CompileML quantizes model leaves once, at compile time. After that, scoring is integer addition, banding is integer comparison, and calibration is integer table lookup.
|
|
165
|
+
|
|
166
|
+
### Explanations do not reconcile
|
|
167
|
+
|
|
168
|
+
Post-hoc explainers are useful, but an explanation of a regulated decision should not merely resemble the decision.
|
|
169
|
+
|
|
170
|
+
CompileML computes attribution from the compiled model in integer units. The feature impacts, baseline, and residual satisfy a reconciliation identity that validation can add back independently.
|
|
171
|
+
|
|
172
|
+
For whiteboxes of depth two or less, the pairwise decomposition is complete and the residual is zero.
|
|
173
|
+
|
|
174
|
+
### The deployment stack is not the modeling stack
|
|
175
|
+
|
|
176
|
+
Banks and other large institutions run important decisions on SQL systems, core platforms, and mainframes. Requiring the entire training environment in production is often unrealistic and sometimes unnecessary.
|
|
177
|
+
|
|
178
|
+
CompileML moves complexity to compile time and leaves production with a small, explicit artifact.
|
|
179
|
+
|
|
180
|
+
## What the artifact guarantees
|
|
181
|
+
|
|
182
|
+
Given the same artifact and the same input values, CompileML is designed to produce the same governed integer outputs across supported runtimes.
|
|
183
|
+
|
|
184
|
+
The repository tests this rather than asking you to take it on faith:
|
|
185
|
+
|
|
186
|
+
* SQL output is executed in SQLite and compared row by row with the Python runtime.
|
|
187
|
+
* Generated COBOL is compiled and run in CI, then checked against the reference implementation.
|
|
188
|
+
* The same seeded artifact is built on Linux, macOS, and Windows and the hashes are compared.
|
|
189
|
+
* Attribution is added back to the decision during validation.
|
|
190
|
+
* Recalibration tests verify that the model and band edges remain unchanged.
|
|
191
|
+
* The standard-library-only runtime is enforced by inspecting its imports.
|
|
192
|
+
|
|
193
|
+
The artifact includes a SHA-256 hash. Loaders verify it by default and reject a document whose contents no longer match the stored hash. This detects modification or corruption; it is an integrity check, not a cryptographic signature of who produced the artifact.
|
|
194
|
+
|
|
195
|
+
## Measured performance
|
|
196
|
+
|
|
197
|
+
The committed benchmark uses deterministic synthetic credit data with 40,000 rows and 23 features. It runs on a consumer laptop through the pure-Python runtime.
|
|
198
|
+
|
|
199
|
+
You can reproduce every number with:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
python benchmarks/run_benchmarks.py
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
| Metric | Value |
|
|
206
|
+
| ------------------------------------------ | -------------------------: |
|
|
207
|
+
| Teacher Gini, 300-tree GBM | 0.667 |
|
|
208
|
+
| **Compiled integer artifact Gini** | **0.653 — 97.9% retained** |
|
|
209
|
+
| Band-ordinal Gini, 10 bands | 0.647 — 97.0% retained |
|
|
210
|
+
| Spearman correlation, teacher vs. artifact | 0.977 |
|
|
211
|
+
| Score + band + calibrated PD | **0.03 ms median** |
|
|
212
|
+
| Score + band + calibrated PD, p95 | 0.04 ms |
|
|
213
|
+
| Full exact explanation, 23 features | 8.4 ms median |
|
|
214
|
+
| Band assignment alone | 0.2 µs |
|
|
215
|
+
| Artifact size | 97 KB |
|
|
216
|
+
| Identical hash on rebuild | Yes |
|
|
217
|
+
|
|
218
|
+
One honest qualification: scoring is very fast; full explanation is not equally cheap.
|
|
219
|
+
|
|
220
|
+
The exact pairwise decomposition requires:
|
|
221
|
+
|
|
222
|
+
```text
|
|
223
|
+
1 + p + p(p−1)/2
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
ensemble traversals for `p` features. It is exact rather than sampled, and that has a cost.
|
|
227
|
+
|
|
228
|
+
In practice: explain everything. A few milliseconds per decision is real-time for credit decisioning — the bureau pull costs more — and complete attribution on every decision is what turns portfolio questions (marginal analysis, driver drift, fairness cuts) into census facts instead of sample estimates. It also means every production decision carries its own explanation in the record, computed at decision time under the same artifact hash.
|
|
229
|
+
|
|
230
|
+
The quadratic cost matters in one place: re-explaining an entire book in batch, or artifacts with very wide feature sets. That is what the leaf-time roadmap item addresses — not live latency, which was never the constraint.
|
|
231
|
+
|
|
232
|
+
## What CompileML is not
|
|
233
|
+
|
|
234
|
+
CompileML is not a new training framework. Use XGBoost, LightGBM, scikit-learn, or another teacher that can be distilled into the supported whitebox representation.
|
|
235
|
+
|
|
236
|
+
It is not a promise that your data pipelines are identical. Determinism means:
|
|
237
|
+
|
|
238
|
+
```text
|
|
239
|
+
same input values + same artifact = same governed outputs
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Producing the same input values across systems remains the caller’s responsibility.
|
|
243
|
+
|
|
244
|
+
It is also not a compliance certification. No library can certify an institution’s model, data, policy language, or governance process.
|
|
245
|
+
|
|
246
|
+
CompileML is infrastructure intended to make those things inspectable instead of asking validators to trust a chain of separate implementations.
|
|
247
|
+
|
|
248
|
+
## Reason codes belong to the institution
|
|
249
|
+
|
|
250
|
+
CompileML can determine which features moved a decision and by how much. It cannot decide how your institution should explain that result to a customer.
|
|
251
|
+
|
|
252
|
+
That language is policy, not mathematics.
|
|
253
|
+
|
|
254
|
+
You provide the reason dictionary:
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
REASON_DICTIONARY = {
|
|
258
|
+
"BILLS_PAID_LATE": {
|
|
259
|
+
"code": "LATE_PAYMENTS",
|
|
260
|
+
"negative": "Recent payments were made after their due date.",
|
|
261
|
+
"positive": "Consistent on-time payment history.",
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
# Add one entry per feature.
|
|
265
|
+
# `suppress: True` hides policy-masked features.
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Features without an entry still work, but they receive generic fallback messages. CompileML measures reason coverage, records it in the artifact, warns when coverage is incomplete, and can make full coverage a validation requirement.
|
|
270
|
+
|
|
271
|
+
The tooling should not quietly pretend that generic feature names are suitable adverse-action notices.
|
|
272
|
+
|
|
273
|
+
## Seeing what the model did
|
|
274
|
+
|
|
275
|
+
The visualization package draws the outputs emitted by `decide()`. It does not independently recompute the model or explanation.
|
|
276
|
+
|
|
277
|
+
That matters: the chart cannot disagree with the deployed decision because both come from the same payload.
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
from compileml.viz import (
|
|
281
|
+
waterfall,
|
|
282
|
+
decision_drivers,
|
|
283
|
+
band_drivers,
|
|
284
|
+
band_ladder,
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
waterfall(
|
|
288
|
+
decide(artifact, row, include_contributions=True)
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
decision_drivers(sample_decisions, y=y_sample)
|
|
292
|
+
band_drivers(sample_decisions, y=y_sample)
|
|
293
|
+
band_ladder(score_decisions, y_sample)
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The image at the top of this README was rendered by `waterfall_svg()` from the repository’s committed reference artifact. That renderer also uses only the standard library.
|
|
297
|
+
|
|
298
|
+
## Validation
|
|
299
|
+
|
|
300
|
+
Run the validation framework against a holdout set:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
compileml validate artifact.json \
|
|
304
|
+
--csv holdout.csv \
|
|
305
|
+
--y-col DEFAULT
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
It checks:
|
|
309
|
+
|
|
310
|
+
1. artifact integrity;
|
|
311
|
+
2. explanation reconciliation;
|
|
312
|
+
3. fidelity to the source model;
|
|
313
|
+
4. band coverage and score resolution;
|
|
314
|
+
5. bad-rate monotonicity;
|
|
315
|
+
6. band-ladder churn;
|
|
316
|
+
7. explanation stability;
|
|
317
|
+
8. reason-code coverage.
|
|
318
|
+
|
|
319
|
+
These checks run against the compiled artifact through the same runtime used for production decisions. There is no separate notebook implementation allowed to become “almost the same” over time.
|
|
320
|
+
|
|
321
|
+
The command exits with `0` or `1`, so it can gate deployment in CI.
|
|
322
|
+
|
|
323
|
+
## Install
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
pip install compileml
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Optional teacher integrations:
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
pip install compileml[xgboost]
|
|
333
|
+
pip install compileml[lightgbm]
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Visualization dependencies:
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
pip install compileml[viz]
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
The compile side depends on NumPy and scikit-learn. The `compileml.runtime` package uses only the Python standard library.
|
|
343
|
+
|
|
344
|
+
If necessary, the runtime directory can be vendored into a constrained environment:
|
|
345
|
+
|
|
346
|
+
```text
|
|
347
|
+
src/compileml/runtime/
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Documentation
|
|
351
|
+
|
|
352
|
+
* [Quickstart](docs/quickstart.md)
|
|
353
|
+
* [Artifact specification](docs/ARTIFACT_SPEC.md)
|
|
354
|
+
* [Reason codes](docs/howto/reason-codes.md)
|
|
355
|
+
* [Recalibration without band churn](docs/howto/recalibrate.md)
|
|
356
|
+
* [Deploying to Python, SQL, and COBOL](docs/howto/deploy.md)
|
|
357
|
+
* [Validation framework](docs/howto/validate.md)
|
|
358
|
+
* [Visualization](docs/howto/visualize.md)
|
|
359
|
+
* [Executable notebooks](examples/)
|
|
360
|
+
|
|
361
|
+
## Roadmap
|
|
362
|
+
|
|
363
|
+
The current priorities are:
|
|
364
|
+
|
|
365
|
+
* compute exact attribution at leaf time — making explain-everything p-independent, cheap for full-book batch, and enabling reason-code emission in the SQL export;
|
|
366
|
+
* add Java and C exporters;
|
|
367
|
+
* complete calibrated-PD output in COBOL;
|
|
368
|
+
* add an optional NumPy batch scorer;
|
|
369
|
+
* add a fairness-audit module.
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
Apache-2.0.
|
|
374
|
+
|
|
375
|
+
Copyright 2026 Carlos Ortiz.
|