oversampleqa 0.5.1__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 (36) hide show
  1. oversampleqa-0.5.1/AUTHORS.md +30 -0
  2. oversampleqa-0.5.1/LICENSE +21 -0
  3. oversampleqa-0.5.1/PKG-INFO +237 -0
  4. oversampleqa-0.5.1/README.md +186 -0
  5. oversampleqa-0.5.1/pyproject.toml +238 -0
  6. oversampleqa-0.5.1/src/oversampleqa/__init__.py +210 -0
  7. oversampleqa-0.5.1/src/oversampleqa/_provenance.py +131 -0
  8. oversampleqa-0.5.1/src/oversampleqa/_render.py +81 -0
  9. oversampleqa-0.5.1/src/oversampleqa/_rng.py +83 -0
  10. oversampleqa-0.5.1/src/oversampleqa/advanced_benchmark.py +1076 -0
  11. oversampleqa-0.5.1/src/oversampleqa/benchmark.py +399 -0
  12. oversampleqa-0.5.1/src/oversampleqa/caching.py +262 -0
  13. oversampleqa-0.5.1/src/oversampleqa/cli.py +115 -0
  14. oversampleqa-0.5.1/src/oversampleqa/cli_enhanced.py +1498 -0
  15. oversampleqa-0.5.1/src/oversampleqa/clustering.py +98 -0
  16. oversampleqa-0.5.1/src/oversampleqa/config_templates.py +85 -0
  17. oversampleqa-0.5.1/src/oversampleqa/deprecation.py +131 -0
  18. oversampleqa-0.5.1/src/oversampleqa/distance.py +237 -0
  19. oversampleqa-0.5.1/src/oversampleqa/estimator.py +229 -0
  20. oversampleqa-0.5.1/src/oversampleqa/exceptions.py +60 -0
  21. oversampleqa-0.5.1/src/oversampleqa/extended_distances.py +336 -0
  22. oversampleqa-0.5.1/src/oversampleqa/fidelity.py +755 -0
  23. oversampleqa-0.5.1/src/oversampleqa/inference.py +1016 -0
  24. oversampleqa-0.5.1/src/oversampleqa/memory_efficient_validator.py +414 -0
  25. oversampleqa-0.5.1/src/oversampleqa/metrics.py +295 -0
  26. oversampleqa-0.5.1/src/oversampleqa/optimized_distance.py +903 -0
  27. oversampleqa-0.5.1/src/oversampleqa/plotting.py +517 -0
  28. oversampleqa-0.5.1/src/oversampleqa/plugin_contract.py +296 -0
  29. oversampleqa-0.5.1/src/oversampleqa/plugin_system.py +362 -0
  30. oversampleqa-0.5.1/src/oversampleqa/py.typed +0 -0
  31. oversampleqa-0.5.1/src/oversampleqa/report.py +114 -0
  32. oversampleqa-0.5.1/src/oversampleqa/reports.py +288 -0
  33. oversampleqa-0.5.1/src/oversampleqa/surrogate.py +105 -0
  34. oversampleqa-0.5.1/src/oversampleqa/typed_validator.py +423 -0
  35. oversampleqa-0.5.1/src/oversampleqa/types.py +378 -0
  36. oversampleqa-0.5.1/src/oversampleqa/validator.py +860 -0
@@ -0,0 +1,30 @@
1
+ # Authors and Contributors
2
+
3
+ ## Lead Developer
4
+ - **Diogo Ribeiro** ([@diogoribeiro7](https://github.com/diogoribeiro7))
5
+ - ESMAD - Instituto Politecnico do Porto
6
+ - Lead Data Scientist at Mysense.ai
7
+ - Email: dfr@esmad.ipp.pt
8
+ - ORCID: https://orcid.org/0009-0001-2022-7072
9
+
10
+ ## Contributors
11
+
12
+ *Contributors will be listed here as they make contributions to the project.*
13
+
14
+ ### How to be Listed
15
+
16
+ Contributors are automatically added when they:
17
+ - Submit merged pull requests
18
+ - Report bugs that lead to fixes
19
+ - Contribute to documentation
20
+ - Help with community support
21
+
22
+ ## Acknowledgments
23
+
24
+ This project implements validation methodology from:
25
+ - Hassanat et al., "Stop Oversampling for Class Imbalance Learning: A Critical Review" (2022)
26
+
27
+ ### Inspiration and References
28
+ - scikit-learn community for API design patterns
29
+ - imbalanced-learn for oversampling integration
30
+ - NumPy and SciPy communities for numerical computing standards
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 OversampleQA contributors
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,237 @@
1
+ Metadata-Version: 2.4
2
+ Name: oversampleqa
3
+ Version: 0.5.1
4
+ Summary: A diagnostic toolkit to validate oversampling methods.
5
+ License: MIT
6
+ License-File: AUTHORS.md
7
+ License-File: LICENSE
8
+ Keywords: imbalanced-learning,oversampling,synthetic-data,validation,benchmarking,machine-learning
9
+ Author: Diogo Ribeiro
10
+ Author-email: dfr@esmad.ipp.pt
11
+ Requires-Python: >=3.10
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Provides-Extra: performance
27
+ Requires-Dist: click (>=8.1.7,<9.0.0)
28
+ Requires-Dist: imbalanced-learn (>=0.14.0,<0.15.0)
29
+ Requires-Dist: jinja2 (>=3.0.0,<4.0.0)
30
+ Requires-Dist: matplotlib (>=3.5.0,<4.0.0)
31
+ Requires-Dist: numpy (>=2.2.6,<3.0.0)
32
+ Requires-Dist: pandas (>=2.3.0,<3.0.0)
33
+ Requires-Dist: platformdirs (>=3.0)
34
+ Requires-Dist: psutil (>=5.9) ; extra == "performance"
35
+ Requires-Dist: pydantic (>=2.9.2,<3.0.0)
36
+ Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
37
+ Requires-Dist: rich (>=14.2,<16.0)
38
+ Requires-Dist: scikit-learn (>=1.0.0,<2.0.0)
39
+ Requires-Dist: scipy (>=1.14,<2.0)
40
+ Requires-Dist: seaborn (>=0.13.2,<0.14.0)
41
+ Requires-Dist: tqdm (>=4.66) ; extra == "performance"
42
+ Requires-Dist: umap-learn (>=0.5.0,<0.6.0)
43
+ Project-URL: Bug Tracker, https://github.com/diogoribeiro7/OversampleQA/issues
44
+ Project-URL: Changelog, https://github.com/diogoribeiro7/OversampleQA/blob/main/CHANGELOG.md
45
+ Project-URL: Citation, https://github.com/diogoribeiro7/OversampleQA/blob/main/CITATION.cff
46
+ Project-URL: Documentation, https://github.com/diogoribeiro7/OversampleQA/tree/main/docs
47
+ Project-URL: Homepage, https://github.com/diogoribeiro7/OversampleQA
48
+ Project-URL: Repository, https://github.com/diogoribeiro7/OversampleQA
49
+ Description-Content-Type: text/markdown
50
+
51
+ # OversampleQA
52
+
53
+ [![CI](https://img.shields.io/github/actions/workflow/status/diogoribeiro7/OversampleQA/ci.yml?branch=main)](https://github.com/diogoribeiro7/OversampleQA/actions)
54
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/downloads/)
55
+ [![PyPI](https://img.shields.io/pypi/v/oversampleqa.svg)](https://pypi.org/project/oversampleqa/)
56
+ [![License](https://img.shields.io/github/license/diogoribeiro7/OversampleQA)](LICENSE)
57
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21940361.svg)](https://doi.org/10.5281/zenodo.21940361)
58
+
59
+ A diagnostic toolkit to validate, audit, and benchmark oversampling methods for imbalanced classification.
60
+
61
+ ## What It Does
62
+
63
+ - Validates oversampling quality with a hidden-majority error rate (binary and multiclass).
64
+ - Offers a broad set of distance metrics (Hassanat, Euclidean, Mahalanobis, etc.).
65
+ - Includes optimized and memory-efficient distance matrix computation.
66
+ - Supports benchmarking across datasets and oversamplers with exportable results.
67
+ - Provides a rich CLI with profiles, templates, shell completion, and diagnostics.
68
+ - Extensible via a plugin system for custom metrics and validators.
69
+
70
+ ## Concepts
71
+
72
+ OversampleQA validates synthetic samples by hiding a portion of the majority class and asking whether generated points look more like the hidden majority or the real minority. Each synthetic sample is scored by its nearest-neighbor distance to both groups using a chosen metric. If a synthetic sample is closer to the hidden majority than to the minority, it is counted as an error. The resulting error rate is a direct signal of how often oversampling produces majority-like artifacts. Lower error rates suggest better minority fidelity, but the absolute value depends on the dataset, metric, and hidden ratio. For multiclass data, the same idea generalizes to a confusion-style error matrix across classes.
73
+
74
+ ## Install
75
+
76
+ Python 3.10+ is required. Install the latest release from PyPI:
77
+
78
+ ```bash
79
+ pip install oversampleqa
80
+ ```
81
+
82
+ For the optional performance helpers:
83
+
84
+ ```bash
85
+ pip install "oversampleqa[performance]"
86
+ ```
87
+
88
+ For development or unreleased changes, install from source:
89
+
90
+ ```bash
91
+ git clone https://github.com/diogoribeiro7/OversampleQA.git
92
+ cd OversampleQA
93
+ poetry install
94
+ ```
95
+
96
+ To depend on the current repository state from another project:
97
+
98
+ ```bash
99
+ pip install git+https://github.com/diogoribeiro7/OversampleQA.git
100
+ ```
101
+
102
+ ## Quick Start (Python)
103
+
104
+ ```bash
105
+ python - <<'PY'
106
+ from sklearn.datasets import make_classification
107
+ from imblearn.over_sampling import SMOTE
108
+ from oversampleqa import validate_oversampling
109
+
110
+ X, y = make_classification(
111
+ n_samples=1000,
112
+ n_features=20,
113
+ n_informative=10,
114
+ n_redundant=10,
115
+ n_clusters_per_class=1,
116
+ weights=[0.9, 0.1],
117
+ random_state=42,
118
+ )
119
+
120
+ error_rate = validate_oversampling(
121
+ X=X,
122
+ y=y,
123
+ minority_label=1,
124
+ oversampler=SMOTE(random_state=42),
125
+ hidden_ratio=0.1,
126
+ metric="hassanat",
127
+ )
128
+
129
+ print(f"SMOTE validation error rate: {error_rate:.3f}")
130
+ PY
131
+ ```
132
+
133
+ ## CLI
134
+
135
+ ```bash
136
+ oversampleqa --help
137
+ ```
138
+
139
+ ```bash
140
+ oversampleqa validate data.csv \
141
+ --target target \
142
+ --minority-label 1 \
143
+ --oversampler SMOTE \
144
+ --metric hassanat \
145
+ --hidden-ratio 0.1 \
146
+ --export json \
147
+ --output runs
148
+ ```
149
+
150
+ ```bash
151
+ oversampleqa profiles
152
+ oversampleqa template --template production -o oversampleqa.yaml
153
+ oversampleqa benchmark --output benchmark_results
154
+ oversampleqa doctor
155
+ ```
156
+
157
+ Legacy minimal CLI (if you prefer a smaller surface):
158
+
159
+ ```bash
160
+ oversampleqa-validate --help
161
+ ```
162
+
163
+ ## Configuration
164
+
165
+ The enhanced CLI loads configuration from `~/.oversampleqa/config.yaml` by default. You can override it with `--config` and select profiles with `--profile`.
166
+
167
+ ## Examples And Docs
168
+
169
+ - Code samples live in `examples/` and `tutorials/`.
170
+ - Sphinx documentation sources are in `docs/`.
171
+
172
+ Build docs:
173
+
174
+ ```bash
175
+ make docs
176
+ ```
177
+
178
+ ## Development
179
+
180
+ ```bash
181
+ # One-liner
182
+ make setup
183
+
184
+ # Or run onboarding helper
185
+ poetry run python scripts/onboard.py
186
+
187
+ # Manual steps
188
+ poetry install
189
+ poetry run pre-commit install
190
+ poetry run pre-commit install --hook-type commit-msg
191
+ ```
192
+
193
+ ## Quality Checks
194
+
195
+ ```bash
196
+ # Lint and typecheck -- both pass clean
197
+ make lint typecheck
198
+ # Run tests with coverage
199
+ make coverage
200
+ # Security audit
201
+ make security
202
+ # Build docs the way CI does, with warnings as errors
203
+ make docs
204
+ # Full pre-commit suite
205
+ poetry run pre-commit run --all-files
206
+ ```
207
+
208
+ Linting and formatting are handled by [ruff](https://docs.astral.sh/ruff/) alone;
209
+ the enforced rule set lives in `pyproject.toml`. These commands work on Windows
210
+ and Linux alike.
211
+
212
+ ## Citation
213
+
214
+ If you use OversampleQA in academic work, please cite it. Machine-readable metadata
215
+ lives in `CITATION.cff`, which GitHub renders as a "Cite this repository" button.
216
+
217
+ ```bibtex
218
+ @software{ribeiro_oversampleqa,
219
+ author = {Ribeiro, Diogo},
220
+ title = {{OversampleQA: a diagnostic toolkit to validate, audit,
221
+ and benchmark oversampling methods}},
222
+ version = {0.5.1},
223
+ year = {2026},
224
+ doi = {10.5281/zenodo.21940361},
225
+ url = {https://doi.org/10.5281/zenodo.21940361}
226
+ }
227
+ ```
228
+
229
+ The DOI above is the concept DOI: it always resolves to the newest archived
230
+ version. To cite an exact archived release, use the version DOI listed in
231
+ `CITATION.cff` after Zenodo has minted it. See
232
+ [Citing OversampleQA](docs/citation.rst) for the release and DOI sequence.
233
+
234
+ ## License
235
+
236
+ MIT. See `LICENSE`.
237
+
@@ -0,0 +1,186 @@
1
+ # OversampleQA
2
+
3
+ [![CI](https://img.shields.io/github/actions/workflow/status/diogoribeiro7/OversampleQA/ci.yml?branch=main)](https://github.com/diogoribeiro7/OversampleQA/actions)
4
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/downloads/)
5
+ [![PyPI](https://img.shields.io/pypi/v/oversampleqa.svg)](https://pypi.org/project/oversampleqa/)
6
+ [![License](https://img.shields.io/github/license/diogoribeiro7/OversampleQA)](LICENSE)
7
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21940361.svg)](https://doi.org/10.5281/zenodo.21940361)
8
+
9
+ A diagnostic toolkit to validate, audit, and benchmark oversampling methods for imbalanced classification.
10
+
11
+ ## What It Does
12
+
13
+ - Validates oversampling quality with a hidden-majority error rate (binary and multiclass).
14
+ - Offers a broad set of distance metrics (Hassanat, Euclidean, Mahalanobis, etc.).
15
+ - Includes optimized and memory-efficient distance matrix computation.
16
+ - Supports benchmarking across datasets and oversamplers with exportable results.
17
+ - Provides a rich CLI with profiles, templates, shell completion, and diagnostics.
18
+ - Extensible via a plugin system for custom metrics and validators.
19
+
20
+ ## Concepts
21
+
22
+ OversampleQA validates synthetic samples by hiding a portion of the majority class and asking whether generated points look more like the hidden majority or the real minority. Each synthetic sample is scored by its nearest-neighbor distance to both groups using a chosen metric. If a synthetic sample is closer to the hidden majority than to the minority, it is counted as an error. The resulting error rate is a direct signal of how often oversampling produces majority-like artifacts. Lower error rates suggest better minority fidelity, but the absolute value depends on the dataset, metric, and hidden ratio. For multiclass data, the same idea generalizes to a confusion-style error matrix across classes.
23
+
24
+ ## Install
25
+
26
+ Python 3.10+ is required. Install the latest release from PyPI:
27
+
28
+ ```bash
29
+ pip install oversampleqa
30
+ ```
31
+
32
+ For the optional performance helpers:
33
+
34
+ ```bash
35
+ pip install "oversampleqa[performance]"
36
+ ```
37
+
38
+ For development or unreleased changes, install from source:
39
+
40
+ ```bash
41
+ git clone https://github.com/diogoribeiro7/OversampleQA.git
42
+ cd OversampleQA
43
+ poetry install
44
+ ```
45
+
46
+ To depend on the current repository state from another project:
47
+
48
+ ```bash
49
+ pip install git+https://github.com/diogoribeiro7/OversampleQA.git
50
+ ```
51
+
52
+ ## Quick Start (Python)
53
+
54
+ ```bash
55
+ python - <<'PY'
56
+ from sklearn.datasets import make_classification
57
+ from imblearn.over_sampling import SMOTE
58
+ from oversampleqa import validate_oversampling
59
+
60
+ X, y = make_classification(
61
+ n_samples=1000,
62
+ n_features=20,
63
+ n_informative=10,
64
+ n_redundant=10,
65
+ n_clusters_per_class=1,
66
+ weights=[0.9, 0.1],
67
+ random_state=42,
68
+ )
69
+
70
+ error_rate = validate_oversampling(
71
+ X=X,
72
+ y=y,
73
+ minority_label=1,
74
+ oversampler=SMOTE(random_state=42),
75
+ hidden_ratio=0.1,
76
+ metric="hassanat",
77
+ )
78
+
79
+ print(f"SMOTE validation error rate: {error_rate:.3f}")
80
+ PY
81
+ ```
82
+
83
+ ## CLI
84
+
85
+ ```bash
86
+ oversampleqa --help
87
+ ```
88
+
89
+ ```bash
90
+ oversampleqa validate data.csv \
91
+ --target target \
92
+ --minority-label 1 \
93
+ --oversampler SMOTE \
94
+ --metric hassanat \
95
+ --hidden-ratio 0.1 \
96
+ --export json \
97
+ --output runs
98
+ ```
99
+
100
+ ```bash
101
+ oversampleqa profiles
102
+ oversampleqa template --template production -o oversampleqa.yaml
103
+ oversampleqa benchmark --output benchmark_results
104
+ oversampleqa doctor
105
+ ```
106
+
107
+ Legacy minimal CLI (if you prefer a smaller surface):
108
+
109
+ ```bash
110
+ oversampleqa-validate --help
111
+ ```
112
+
113
+ ## Configuration
114
+
115
+ The enhanced CLI loads configuration from `~/.oversampleqa/config.yaml` by default. You can override it with `--config` and select profiles with `--profile`.
116
+
117
+ ## Examples And Docs
118
+
119
+ - Code samples live in `examples/` and `tutorials/`.
120
+ - Sphinx documentation sources are in `docs/`.
121
+
122
+ Build docs:
123
+
124
+ ```bash
125
+ make docs
126
+ ```
127
+
128
+ ## Development
129
+
130
+ ```bash
131
+ # One-liner
132
+ make setup
133
+
134
+ # Or run onboarding helper
135
+ poetry run python scripts/onboard.py
136
+
137
+ # Manual steps
138
+ poetry install
139
+ poetry run pre-commit install
140
+ poetry run pre-commit install --hook-type commit-msg
141
+ ```
142
+
143
+ ## Quality Checks
144
+
145
+ ```bash
146
+ # Lint and typecheck -- both pass clean
147
+ make lint typecheck
148
+ # Run tests with coverage
149
+ make coverage
150
+ # Security audit
151
+ make security
152
+ # Build docs the way CI does, with warnings as errors
153
+ make docs
154
+ # Full pre-commit suite
155
+ poetry run pre-commit run --all-files
156
+ ```
157
+
158
+ Linting and formatting are handled by [ruff](https://docs.astral.sh/ruff/) alone;
159
+ the enforced rule set lives in `pyproject.toml`. These commands work on Windows
160
+ and Linux alike.
161
+
162
+ ## Citation
163
+
164
+ If you use OversampleQA in academic work, please cite it. Machine-readable metadata
165
+ lives in `CITATION.cff`, which GitHub renders as a "Cite this repository" button.
166
+
167
+ ```bibtex
168
+ @software{ribeiro_oversampleqa,
169
+ author = {Ribeiro, Diogo},
170
+ title = {{OversampleQA: a diagnostic toolkit to validate, audit,
171
+ and benchmark oversampling methods}},
172
+ version = {0.5.1},
173
+ year = {2026},
174
+ doi = {10.5281/zenodo.21940361},
175
+ url = {https://doi.org/10.5281/zenodo.21940361}
176
+ }
177
+ ```
178
+
179
+ The DOI above is the concept DOI: it always resolves to the newest archived
180
+ version. To cite an exact archived release, use the version DOI listed in
181
+ `CITATION.cff` after Zenodo has minted it. See
182
+ [Citing OversampleQA](docs/citation.rst) for the release and DOI sequence.
183
+
184
+ ## License
185
+
186
+ MIT. See `LICENSE`.