modeldiff-ml 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.
- modeldiff_ml-0.1.0/.github/workflows/publish-to-pypi.yml +50 -0
- modeldiff_ml-0.1.0/.gitignore +220 -0
- modeldiff_ml-0.1.0/LICENSE +21 -0
- modeldiff_ml-0.1.0/PKG-INFO +251 -0
- modeldiff_ml-0.1.0/README.md +201 -0
- modeldiff_ml-0.1.0/examples/classification_example.py +38 -0
- modeldiff_ml-0.1.0/examples/classification_report.html +23 -0
- modeldiff_ml-0.1.0/examples/regression_example.py +23 -0
- modeldiff_ml-0.1.0/pyproject.toml +62 -0
- modeldiff_ml-0.1.0/src/modeldiff/__init__.py +14 -0
- modeldiff_ml-0.1.0/src/modeldiff/adapters/__init__.py +5 -0
- modeldiff_ml-0.1.0/src/modeldiff/adapters/sklearn.py +31 -0
- modeldiff_ml-0.1.0/src/modeldiff/analysis/__init__.py +5 -0
- modeldiff_ml-0.1.0/src/modeldiff/analysis/disagreement.py +40 -0
- modeldiff_ml-0.1.0/src/modeldiff/analysis/distributions.py +26 -0
- modeldiff_ml-0.1.0/src/modeldiff/analysis/regions.py +210 -0
- modeldiff_ml-0.1.0/src/modeldiff/api.py +249 -0
- modeldiff_ml-0.1.0/src/modeldiff/cli.py +74 -0
- modeldiff_ml-0.1.0/src/modeldiff/config.py +57 -0
- modeldiff_ml-0.1.0/src/modeldiff/metrics/__init__.py +15 -0
- modeldiff_ml-0.1.0/src/modeldiff/metrics/base.py +28 -0
- modeldiff_ml-0.1.0/src/modeldiff/metrics/classification.py +53 -0
- modeldiff_ml-0.1.0/src/modeldiff/metrics/regression.py +27 -0
- modeldiff_ml-0.1.0/src/modeldiff/reporting/__init__.py +7 -0
- modeldiff_ml-0.1.0/src/modeldiff/reporting/console.py +69 -0
- modeldiff_ml-0.1.0/src/modeldiff/reporting/html.py +88 -0
- modeldiff_ml-0.1.0/src/modeldiff/reporting/json.py +13 -0
- modeldiff_ml-0.1.0/src/modeldiff/result.py +143 -0
- modeldiff_ml-0.1.0/src/modeldiff/statistics/__init__.py +7 -0
- modeldiff_ml-0.1.0/src/modeldiff/statistics/bootstrap.py +32 -0
- modeldiff_ml-0.1.0/src/modeldiff/statistics/multiple_testing.py +21 -0
- modeldiff_ml-0.1.0/src/modeldiff/statistics/permutation.py +42 -0
- modeldiff_ml-0.1.0/src/modeldiff/utils.py +84 -0
- modeldiff_ml-0.1.0/tests/conftest.py +41 -0
- modeldiff_ml-0.1.0/tests/test_api.py +114 -0
- modeldiff_ml-0.1.0/tests/test_disagreement.py +19 -0
- modeldiff_ml-0.1.0/tests/test_metrics.py +50 -0
- modeldiff_ml-0.1.0/tests/test_regions.py +62 -0
- modeldiff_ml-0.1.0/tests/test_reporting.py +70 -0
- modeldiff_ml-0.1.0/tests/test_statistics.py +31 -0
- modeldiff_ml-0.1.0/uv.lock +1266 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: Publish modeldiff-ml to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
name: Build distribution
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v6
|
|
17
|
+
with:
|
|
18
|
+
persist-credentials: false
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v6
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.x"
|
|
23
|
+
- name: Install build frontend
|
|
24
|
+
run: python -m pip install build
|
|
25
|
+
- name: Build wheel and source distribution
|
|
26
|
+
run: python -m build
|
|
27
|
+
- name: Store distributions
|
|
28
|
+
uses: actions/upload-artifact@v5
|
|
29
|
+
with:
|
|
30
|
+
name: python-package-distributions
|
|
31
|
+
path: dist/
|
|
32
|
+
|
|
33
|
+
publish:
|
|
34
|
+
name: Publish distribution to PyPI
|
|
35
|
+
needs: build
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
environment:
|
|
38
|
+
name: pypi
|
|
39
|
+
url: https://pypi.org/p/modeldiff-ml
|
|
40
|
+
permissions:
|
|
41
|
+
id-token: write
|
|
42
|
+
|
|
43
|
+
steps:
|
|
44
|
+
- name: Download distributions
|
|
45
|
+
uses: actions/download-artifact@v6
|
|
46
|
+
with:
|
|
47
|
+
name: python-package-distributions
|
|
48
|
+
path: dist/
|
|
49
|
+
- name: Publish to PyPI
|
|
50
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs/Zensical documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
201
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
203
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ethan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: modeldiff-ml
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Behavioral regression testing for machine-learning models
|
|
5
|
+
Project-URL: Homepage, https://github.com/ecklein/modeldiff-ml
|
|
6
|
+
Project-URL: Repository, https://github.com/ecklein/modeldiff-ml
|
|
7
|
+
Project-URL: Issues, https://github.com/ecklein/modeldiff-ml/issues
|
|
8
|
+
Author-email: Ethan Klein <ethan.kleinc@gmail.com>
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 ethan
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: machine-learning,model-comparison,regression-testing,statistics
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
37
|
+
Requires-Python: >=3.11
|
|
38
|
+
Requires-Dist: numpy>=1.24
|
|
39
|
+
Requires-Dist: pandas>=2.0
|
|
40
|
+
Requires-Dist: scipy>=1.10
|
|
41
|
+
Provides-Extra: dev
|
|
42
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
43
|
+
Requires-Dist: pandas-stubs>=2.0; extra == 'dev'
|
|
44
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
45
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
46
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
47
|
+
Requires-Dist: scikit-learn>=1.4; extra == 'dev'
|
|
48
|
+
Requires-Dist: scipy-stubs>=1.10; extra == 'dev'
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
|
|
51
|
+
# ModelDiff-ML
|
|
52
|
+
|
|
53
|
+
Your candidate model improved AUC from 0.84 to 0.85. But did it get better everywhere?
|
|
54
|
+
|
|
55
|
+
ModelDiff-ML compares two machine-learning models at the observation level and automatically
|
|
56
|
+
discovers interpretable, statistically validated regions where the candidate behaves differently
|
|
57
|
+
from the baseline. It is a small Python library built around NumPy, pandas, and SciPy—not an MLOps
|
|
58
|
+
platform.
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
ordinary evaluation: "The average metric improved."
|
|
62
|
+
ModelDiff-ML: "It improved overall, but regressed for high-x1, low-x2 observations."
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
ModelDiff-ML requires Python 3.11 or newer. The distribution is named `modeldiff-ml`; its
|
|
68
|
+
Python import package remains the concise `modeldiff`.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install modeldiff-ml
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
For local development:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
python -m venv .venv
|
|
78
|
+
. .venv/bin/activate
|
|
79
|
+
pip install -e '.[dev]'
|
|
80
|
+
pytest
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Quickstart
|
|
84
|
+
|
|
85
|
+
ModelDiff-ML supports fitted sklearn-style models:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import modeldiff
|
|
89
|
+
|
|
90
|
+
report = modeldiff.compare(
|
|
91
|
+
baseline=old_model,
|
|
92
|
+
candidate=new_model,
|
|
93
|
+
X=X_test,
|
|
94
|
+
y=y_test,
|
|
95
|
+
task="binary_classification",
|
|
96
|
+
metric="log_loss",
|
|
97
|
+
random_state=42,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
print(report.summary())
|
|
101
|
+
report.to_json("modeldiff-ml.json")
|
|
102
|
+
report.to_html("modeldiff-ml.html")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Binary classifiers must expose `predict_proba(X)` with two columns. ModelDiff-ML deliberately does not
|
|
106
|
+
turn an estimator's uncalibrated `decision_function` into a probability. Regression estimators need
|
|
107
|
+
only `predict(X)`.
|
|
108
|
+
|
|
109
|
+
## Raw predictions
|
|
110
|
+
|
|
111
|
+
The framework is model-agnostic when predictions are already available:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from modeldiff import ModelDiffConfig, compare_predictions
|
|
115
|
+
|
|
116
|
+
config = ModelDiffConfig(
|
|
117
|
+
max_depth=3,
|
|
118
|
+
min_region_fraction=0.02,
|
|
119
|
+
n_bootstrap=1000,
|
|
120
|
+
n_permutations=2000,
|
|
121
|
+
random_state=42,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
report = compare_predictions(
|
|
125
|
+
baseline_predictions=old_probabilities,
|
|
126
|
+
candidate_predictions=new_probabilities,
|
|
127
|
+
X=X_test,
|
|
128
|
+
y=y_test,
|
|
129
|
+
task="binary_classification",
|
|
130
|
+
metric="log_loss",
|
|
131
|
+
config=config,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
significant_regressions = report.regressions(significant_only=True)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`X` may be a pandas DataFrame or two-dimensional NumPy array. DataFrames produce more readable
|
|
138
|
+
conditions. Arrays receive the names `x0`, `x1`, and so on.
|
|
139
|
+
|
|
140
|
+
## Interpreting delta
|
|
141
|
+
|
|
142
|
+
ModelDiff-ML uses one convention everywhere:
|
|
143
|
+
|
|
144
|
+
```text
|
|
145
|
+
delta_i = candidate_loss_i - baseline_loss_i
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
- Positive delta: the candidate is worse.
|
|
149
|
+
- Negative delta: the candidate is better.
|
|
150
|
+
- Zero: equal loss.
|
|
151
|
+
|
|
152
|
+
The supported classification losses are log loss, Brier loss (`"brier"`), and accuracy loss
|
|
153
|
+
(`"accuracy"`). Classification reports also include accuracy, log loss, Brier score, and rank-based
|
|
154
|
+
ROC AUC. Regression supports squared error (`"squared_error"` or `"mse"`), RMSE (`"rmse"`), and
|
|
155
|
+
absolute error (`"absolute_error"` or `"mae"`).
|
|
156
|
+
|
|
157
|
+
For RMSE, the overall metric is square-rooted after aggregation; region discovery still operates on
|
|
158
|
+
observation-level squared error. For accuracy, the primary loss is misclassification rate while the
|
|
159
|
+
aggregate metrics table also reports conventional accuracy.
|
|
160
|
+
|
|
161
|
+
## How region discovery works
|
|
162
|
+
|
|
163
|
+
1. ModelDiff-ML computes a loss difference for every observation.
|
|
164
|
+
2. It deterministically divides the data into discovery and validation partitions.
|
|
165
|
+
3. Numeric candidate conditions come from empirical quantiles. Categorical candidates use frequent
|
|
166
|
+
equality and inequality conditions.
|
|
167
|
+
4. A from-scratch beam search builds conjunctions up to `max_depth`, scoring each as
|
|
168
|
+
`abs(mean_delta) * sqrt(region_fraction)` (with sign-aware variants for each direction).
|
|
169
|
+
5. Highly overlapping regions are removed using Jaccard similarity.
|
|
170
|
+
6. The exact selected conditions are applied unchanged to the validation partition.
|
|
171
|
+
7. Validation effects receive percentile bootstrap confidence intervals and paired sign-flip
|
|
172
|
+
p-values. Benjamini–Hochberg correction produces q-values across all tested regions.
|
|
173
|
+
|
|
174
|
+
This separation matters: searching for a threshold and reporting a p-value from those same rows
|
|
175
|
+
would understate selection bias. ModelDiff-ML's independent holdout is a practical first defense.
|
|
176
|
+
|
|
177
|
+
## Classification example
|
|
178
|
+
|
|
179
|
+
[`examples/classification_example.py`](examples/classification_example.py) creates a candidate that
|
|
180
|
+
is better overall but deliberately worse when `x1` is high and `x2` is low:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
python examples/classification_example.py
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
This is the central ModelDiff-ML use case: aggregate improvement can hide a meaningful local
|
|
187
|
+
regression. A generated standalone report is available at
|
|
188
|
+
[`examples/classification_report.html`](examples/classification_report.html).
|
|
189
|
+
|
|
190
|
+
## Regression example
|
|
191
|
+
|
|
192
|
+
[`examples/regression_example.py`](examples/regression_example.py) compares two arrays of regression
|
|
193
|
+
predictions and discovers a planted high-error slice.
|
|
194
|
+
|
|
195
|
+
## CLI and CI
|
|
196
|
+
|
|
197
|
+
The CLI reads precomputed predictions from CSV. Unless excluded, columns other than the target and
|
|
198
|
+
prediction columns are features:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
modeldiff-ml compare \
|
|
202
|
+
--data validation.csv \
|
|
203
|
+
--target y \
|
|
204
|
+
--baseline-pred old_prediction \
|
|
205
|
+
--candidate-pred new_prediction \
|
|
206
|
+
--task binary_classification \
|
|
207
|
+
--metric log_loss \
|
|
208
|
+
--html report.html \
|
|
209
|
+
--json report.json
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Use `--exclude COLUMN` repeatedly to omit non-feature columns. CI-oriented checks return exit code 1:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
modeldiff-ml compare ... --fail-on-significant-regression
|
|
216
|
+
modeldiff-ml compare ... --max-overall-regression 0.01
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The JSON output has schema version `1.0`, contains no model objects, and is suitable for CI artifact
|
|
220
|
+
processing.
|
|
221
|
+
|
|
222
|
+
## Configuration
|
|
223
|
+
|
|
224
|
+
`ModelDiffConfig` controls the discovery fraction, quantile grid, beam width, maximum depth, minimum
|
|
225
|
+
and maximum support, overlap threshold, resampling counts, confidence and significance levels,
|
|
226
|
+
classification threshold, numerical epsilon, and random seed. Defaults favor understandable output
|
|
227
|
+
and avoid tiny slices. Missing feature values are never imputed; they evaluate as false for V1
|
|
228
|
+
conditions.
|
|
229
|
+
|
|
230
|
+
## Statistical scope and limitations
|
|
231
|
+
|
|
232
|
+
Discovered subgroups are exploratory. Independent validation and FDR correction reduce false
|
|
233
|
+
discoveries, but do not eliminate them. Results can still be unstable with small data, distribution
|
|
234
|
+
shift, correlated repeated observations, or extensive repeated analyses by a human. A fresh final
|
|
235
|
+
test set is appropriate before high-stakes deployment decisions.
|
|
236
|
+
|
|
237
|
+
V1 supports binary classification and regression only. It does not include multiclass evaluation,
|
|
238
|
+
causal claims, fairness-specific analysis, time/group-aware splitting, distributed execution, SHAP,
|
|
239
|
+
LLM evaluation, monitoring infrastructure, model registries, dashboards, or automated remediation.
|
|
240
|
+
|
|
241
|
+
## Roadmap
|
|
242
|
+
|
|
243
|
+
- Group-aware and time-based validation strategies
|
|
244
|
+
- Multiclass observation-level losses
|
|
245
|
+
- Cross-validated discovery and stability summaries
|
|
246
|
+
- Pluggable, documented region scoring policies
|
|
247
|
+
- Richer calibrated-score adapters
|
|
248
|
+
|
|
249
|
+
## License
|
|
250
|
+
|
|
251
|
+
MIT
|