algorithm-genome 0.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.
- algorithm_genome-0.3.0/MANIFEST.in +7 -0
- algorithm_genome-0.3.0/Makefile +17 -0
- algorithm_genome-0.3.0/PKG-INFO +223 -0
- algorithm_genome-0.3.0/README.md +194 -0
- algorithm_genome-0.3.0/algorithm_genome/__init__.py +13 -0
- algorithm_genome-0.3.0/algorithm_genome/__main__.py +3 -0
- algorithm_genome-0.3.0/algorithm_genome/algorithm_library.py +60 -0
- algorithm_genome-0.3.0/algorithm_genome/assets/default_recommender.joblib +0 -0
- algorithm_genome-0.3.0/algorithm_genome/assets/model_info.json +28 -0
- algorithm_genome-0.3.0/algorithm_genome/benchmark_datasets.py +130 -0
- algorithm_genome-0.3.0/algorithm_genome/bundled_model.py +27 -0
- algorithm_genome-0.3.0/algorithm_genome/command_line.py +116 -0
- algorithm_genome-0.3.0/algorithm_genome/create_example_datasets.py +35 -0
- algorithm_genome-0.3.0/algorithm_genome/dataset_genome.py +110 -0
- algorithm_genome-0.3.0/algorithm_genome/download_public_datasets.py +251 -0
- algorithm_genome-0.3.0/algorithm_genome/framework.py +101 -0
- algorithm_genome-0.3.0/algorithm_genome/improve_meta_model.py +186 -0
- algorithm_genome-0.3.0/algorithm_genome/model_pipeline.py +68 -0
- algorithm_genome-0.3.0/algorithm_genome/prepare_additional_datasets.py +105 -0
- algorithm_genome-0.3.0/algorithm_genome/recommend_algorithms.py +177 -0
- algorithm_genome-0.3.0/algorithm_genome/terminal_output.py +270 -0
- algorithm_genome-0.3.0/algorithm_genome/train_meta_model.py +142 -0
- algorithm_genome-0.3.0/algorithm_genome/train_neural_recommender.py +402 -0
- algorithm_genome-0.3.0/algorithm_genome.egg-info/PKG-INFO +223 -0
- algorithm_genome-0.3.0/algorithm_genome.egg-info/SOURCES.txt +42 -0
- algorithm_genome-0.3.0/algorithm_genome.egg-info/dependency_links.txt +1 -0
- algorithm_genome-0.3.0/algorithm_genome.egg-info/entry_points.txt +2 -0
- algorithm_genome-0.3.0/algorithm_genome.egg-info/requires.txt +11 -0
- algorithm_genome-0.3.0/algorithm_genome.egg-info/top_level.txt +1 -0
- algorithm_genome-0.3.0/examples/predict.py +36 -0
- algorithm_genome-0.3.0/examples/recommend.py +33 -0
- algorithm_genome-0.3.0/examples/train_recommender.py +48 -0
- algorithm_genome-0.3.0/examples/use_framework.py +52 -0
- algorithm_genome-0.3.0/examples/verify_and_save.py +40 -0
- algorithm_genome-0.3.0/pyproject.toml +42 -0
- algorithm_genome-0.3.0/scripts/check_release.py +126 -0
- algorithm_genome-0.3.0/setup.cfg +4 -0
- algorithm_genome-0.3.0/tests/test_bundled_recommender.py +84 -0
- algorithm_genome-0.3.0/tests/test_command_line_workflow.py +49 -0
- algorithm_genome-0.3.0/tests/test_dataset_genome.py +41 -0
- algorithm_genome-0.3.0/tests/test_meta_learning_workflow.py +250 -0
- algorithm_genome-0.3.0/tests/test_neural_recommender.py +164 -0
- algorithm_genome-0.3.0/tests/test_public_dataset_training.py +183 -0
- algorithm_genome-0.3.0/tests/test_terminal_output.py +61 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
PYTHON ?= .venv/bin/python
|
|
2
|
+
.DEFAULT_GOAL := help
|
|
3
|
+
.PHONY: help test release check-release
|
|
4
|
+
|
|
5
|
+
help:
|
|
6
|
+
@$(PYTHON) -m algorithm_genome --help
|
|
7
|
+
|
|
8
|
+
test:
|
|
9
|
+
@$(PYTHON) -m pytest -q
|
|
10
|
+
|
|
11
|
+
release: test
|
|
12
|
+
@$(PYTHON) -m build --no-isolation
|
|
13
|
+
@$(PYTHON) -m twine check dist/*
|
|
14
|
+
@$(MAKE) check-release
|
|
15
|
+
|
|
16
|
+
check-release:
|
|
17
|
+
@$(PYTHON) -B scripts/check_release.py dist/
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: algorithm-genome
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Scriptable Python framework for learned classification algorithm recommendations
|
|
5
|
+
Project-URL: Source, https://github.com/mayank1232w/Algorithm-Genome
|
|
6
|
+
Project-URL: Issues, https://github.com/mayank1232w/Algorithm-Genome/issues
|
|
7
|
+
Keywords: machine-learning,meta-learning,classification,algorithm-selection
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: scikit-learn==1.9.1
|
|
21
|
+
Requires-Dist: pandas<4,>=2.2
|
|
22
|
+
Requires-Dist: numpy<3,>=2
|
|
23
|
+
Requires-Dist: joblib<2,>=1.4
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
26
|
+
Provides-Extra: release
|
|
27
|
+
Requires-Dist: build>=1.2; extra == "release"
|
|
28
|
+
Requires-Dist: twine>=6; extra == "release"
|
|
29
|
+
|
|
30
|
+
# Algorithm Genome
|
|
31
|
+
|
|
32
|
+
A Python library that recommends classification algorithms for labeled tabular
|
|
33
|
+
data. A pretrained recommender is included: import the library and pass a pandas
|
|
34
|
+
DataFrame. No repository checkout, downloaded training corpus, separate model
|
|
35
|
+
file, or runtime network connection is needed.
|
|
36
|
+
|
|
37
|
+
Python 3.11 or newer is required. The package pins scikit-learn to the bundled
|
|
38
|
+
model's training version, 1.9.1, so pip installs a compatible version automatically.
|
|
39
|
+
|
|
40
|
+
Install the wheel from this project's `dist/` folder, or share that file with
|
|
41
|
+
another user:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python -m pip install ./dist/algorithm_genome-0.3.0-py3-none-any.whl
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
After the package owner publishes version 0.3.0 to PyPI, the public command will be:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
python -m pip install algorithm-genome
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The release artifacts are prepared locally; this repository change does not
|
|
54
|
+
upload them to PyPI. For local development, use `python -m pip install -e '.[test]'`.
|
|
55
|
+
|
|
56
|
+
Use the library from any working directory:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import pandas as pd
|
|
60
|
+
from algorithm_genome import Recommender, TrainedClassifier
|
|
61
|
+
|
|
62
|
+
# Load the pretrained model installed with the library.
|
|
63
|
+
model = Recommender()
|
|
64
|
+
data = pd.read_csv("my_dataset.csv")
|
|
65
|
+
|
|
66
|
+
# Rank algorithms without training candidate classifiers.
|
|
67
|
+
report = model.recommend(data, target="outcome")
|
|
68
|
+
print(pd.DataFrame(report["ranking"]))
|
|
69
|
+
print(report["meta_model_training_warnings"])
|
|
70
|
+
|
|
71
|
+
# Cross-validate candidates, evaluate a reserved holdout, and refit the winner.
|
|
72
|
+
result = model.verify(data, target="outcome", budget_seconds=60)
|
|
73
|
+
print(result.selected_algorithm)
|
|
74
|
+
print(result.report["holdout_metrics"])
|
|
75
|
+
|
|
76
|
+
# Predict now, or save the selected classifier for later scripts.
|
|
77
|
+
new_rows = pd.read_csv("new_rows.csv")
|
|
78
|
+
predictions = result.predict(new_rows)
|
|
79
|
+
result.save("my_output")
|
|
80
|
+
classifier = TrainedClassifier.load("my_output/selected_classifier.joblib")
|
|
81
|
+
predictions = classifier.predict(new_rows)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The pretrained neural model was trained on 51 dataset versions from 43 source
|
|
85
|
+
groups. It remains **experimental**: its optimizer reported a convergence warning,
|
|
86
|
+
which is retained in reports. On seven previously reserved source groups it lost
|
|
87
|
+
2.086 macro-F1 points on average at the first choice, compared with 1.204 for a
|
|
88
|
+
simple fixed portfolio trained on the same corpus. Lower loss is better. These
|
|
89
|
+
small-cohort results do not establish general recommendation reliability.
|
|
90
|
+
Package resources include `assets/model_info.json` with provenance, checksum,
|
|
91
|
+
training warnings, and the evaluation summary. No raw training tables are shipped.
|
|
92
|
+
|
|
93
|
+
Simple commented scripts are in `examples/` in the source distribution. Copy them
|
|
94
|
+
into your own working folder and run:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
python recommend.py # Uses the installed pretrained model immediately
|
|
98
|
+
python verify_and_save.py # Saves the best measured classifier to algorithm_genome_output/
|
|
99
|
+
python predict.py # Loads that classifier and predicts two new rows
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
They use generated data and explain each framework call. Training is optional:
|
|
103
|
+
`train_recommender.py` illustrates fitting your own model with four small bundled
|
|
104
|
+
scikit-learn datasets. Its output, `my_recommender.joblib`, can be opened using
|
|
105
|
+
`Recommender.load("my_recommender.joblib")`. Four sources demonstrate execution;
|
|
106
|
+
they do not establish recommendation quality. The combined `use_framework.py`
|
|
107
|
+
example accepts your CSVs and an optional custom `--model`:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
python use_framework.py my_dataset.csv --target outcome \
|
|
111
|
+
--predict-csv new_rows.csv --output my_output
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
To train from your own historical DataFrames:
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from algorithm_genome import Dataset, Recommender, benchmark_datasets
|
|
118
|
+
|
|
119
|
+
# historical_tables maps source names to labeled DataFrames.
|
|
120
|
+
datasets = [
|
|
121
|
+
Dataset(id=name, data=frame, target="outcome", group=name)
|
|
122
|
+
for name, frame in historical_tables.items()
|
|
123
|
+
]
|
|
124
|
+
benchmark = benchmark_datasets(datasets)
|
|
125
|
+
model = Recommender.fit(benchmark)
|
|
126
|
+
print(model.artifact["evaluation"])
|
|
127
|
+
model.save("my_recommender.joblib")
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
At least four independent source groups with all ten successful candidate results
|
|
131
|
+
are required. Related dataset variants must share a `group`. Benchmarking also
|
|
132
|
+
accepts a CSV manifest and optional resumable checkpoint:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
benchmark = benchmark_datasets(
|
|
136
|
+
"dataset_manifest.json", output_path="benchmark.json", resume=True,
|
|
137
|
+
)
|
|
138
|
+
model = Recommender.fit(benchmark)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Manifest entries contain `id`, `path`, `target`, and optional `group`/`source`.
|
|
142
|
+
CSV paths are relative to the manifest. Duplicate content is rejected. Inputs are
|
|
143
|
+
validated before fitting; resume reuses only complete compatible results.
|
|
144
|
+
|
|
145
|
+
Public API:
|
|
146
|
+
|
|
147
|
+
| Interface | Result |
|
|
148
|
+
| --- | --- |
|
|
149
|
+
| `Recommender()` | Included pretrained recommender; no paths or downloads |
|
|
150
|
+
| `Dataset(id, data, target, group=None)` | Historical table and source identity |
|
|
151
|
+
| `benchmark_datasets(datasets_or_manifest, output_path=None, progress=False, resume=False)` | Dictionary of measured candidate scores/times and genomes |
|
|
152
|
+
| `Recommender.fit(benchmark_or_path)` | Custom recommender with group-separated evaluation |
|
|
153
|
+
| `Recommender.load(path)` / `model.save(path)` | Read/write a custom trusted joblib artifact |
|
|
154
|
+
| `model.recommend(data, target)` | Predicted ranking, genome, summaries, and warnings |
|
|
155
|
+
| `model.verify(data, target, *, top_k=3, budget_seconds=300, progress=None)` | `VerificationResult` with `report` and `classifier` |
|
|
156
|
+
| `result.predict(data)` / `classifier.predict(data)` | NumPy array of string labels |
|
|
157
|
+
| `result.save(directory)` | Report JSON, predicted ranking CSV, classifier joblib |
|
|
158
|
+
| `TrainedClassifier.load(path)` / `classifier.save(path)` | Read/write a selected classifier |
|
|
159
|
+
| `extract_dataset_genome(X, y)` | Seventeen properties from aligned training rows |
|
|
160
|
+
|
|
161
|
+
Library calls are quiet by default. `verify(progress=callback)` emits event
|
|
162
|
+
dictionaries such as `candidate_start` and `candidate_complete`. Existing
|
|
163
|
+
lower-level `train_meta_model`, `recommend_algorithms`, and
|
|
164
|
+
`verify_recommendations` functions remain exported.
|
|
165
|
+
|
|
166
|
+
The installed CLI uses the pretrained model by default too:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
algorithm-genome recommend my_dataset.csv --target outcome --verify --output my_output
|
|
170
|
+
algorithm-genome predict my_output/selected_classifier.joblib \
|
|
171
|
+
new_rows.csv --output predictions.csv
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Supply `--meta-model custom.joblib` to use your own recommender, `--json` for
|
|
175
|
+
machine output, or `--verbose` for detailed terminal metrics. Research utilities
|
|
176
|
+
are available through `python -m algorithm_genome.download_public_datasets`,
|
|
177
|
+
`prepare_additional_datasets`, `improve_meta_model`, and
|
|
178
|
+
`train_neural_recommender`; use their `--help` options.
|
|
179
|
+
|
|
180
|
+
Scope and interpretation:
|
|
181
|
+
|
|
182
|
+
- Independent-row labeled tabular **classification**, with an explicit target.
|
|
183
|
+
Regression, forecasting, image models, and text models are not implemented.
|
|
184
|
+
- At least 30 distinct labeled rows, two classes, and three rows per class.
|
|
185
|
+
Missing-target rows and duplicate records are removed. Features can be numeric
|
|
186
|
+
or categorical. Outputs are strings; use `pd.read_csv(..., dtype={"outcome": str})`
|
|
187
|
+
to preserve labels such as `01`.
|
|
188
|
+
- Ten fixed candidate configurations, with no automatic hyperparameter tuning.
|
|
189
|
+
Ranking scores predict relative macro-F1, not accuracy or confidence.
|
|
190
|
+
- Verification reserves a holdout before extracting its recommendation genome.
|
|
191
|
+
Preprocessing is fitted inside each CV training fold. The final classifier is
|
|
192
|
+
refitted on all usable rows after holdout evaluation.
|
|
193
|
+
- `top_k` prioritizes the shortlist, followed by a challenger and remaining
|
|
194
|
+
candidates. Runtime budgets are soft and checked between fits; active fits finish.
|
|
195
|
+
- Prediction inputs need the training feature names. Column order may differ,
|
|
196
|
+
extra columns are ignored, and missing or duplicate columns raise `ValueError`.
|
|
197
|
+
- Custom joblib files must be trusted and use matching dependency versions.
|
|
198
|
+
The default model is loaded from verified package resources.
|
|
199
|
+
|
|
200
|
+
To build a release from the source tree:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
python -m pip install -e '.[test,release]'
|
|
204
|
+
make release
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
`make release` runs the test suite, builds both archives, checks their metadata,
|
|
208
|
+
and tests installed copies of the wheel and a wheel rebuilt from the source
|
|
209
|
+
archive. The installation checks run from temporary working directories with
|
|
210
|
+
network access blocked and editable-install hooks disabled. They exercise the
|
|
211
|
+
default recommender, verification, saving/reloading, predictions, and the installed
|
|
212
|
+
CLI. Build tooling and declared dependencies must already be installed; the
|
|
213
|
+
release checks do not download anything. Use a `dist/` folder containing only the
|
|
214
|
+
current version. To check existing archives alone, run
|
|
215
|
+
`python scripts/check_release.py dist/` (also `make check-release` in a checkout).
|
|
216
|
+
Without Make, run `python -m pytest -q`, `python -m build --no-isolation`,
|
|
217
|
+
`python -m twine check dist/*`, and the check script in that order.
|
|
218
|
+
|
|
219
|
+
The resulting wheel and source archive both include the pretrained model. Only
|
|
220
|
+
the package owner should upload the reviewed release using an authenticated PyPI
|
|
221
|
+
account with `python -m twine upload dist/*`, following the
|
|
222
|
+
[Python packaging guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/).
|
|
223
|
+
Uploading is separate from building and local installation.
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Algorithm Genome
|
|
2
|
+
|
|
3
|
+
A Python library that recommends classification algorithms for labeled tabular
|
|
4
|
+
data. A pretrained recommender is included: import the library and pass a pandas
|
|
5
|
+
DataFrame. No repository checkout, downloaded training corpus, separate model
|
|
6
|
+
file, or runtime network connection is needed.
|
|
7
|
+
|
|
8
|
+
Python 3.11 or newer is required. The package pins scikit-learn to the bundled
|
|
9
|
+
model's training version, 1.9.1, so pip installs a compatible version automatically.
|
|
10
|
+
|
|
11
|
+
Install the wheel from this project's `dist/` folder, or share that file with
|
|
12
|
+
another user:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
python -m pip install ./dist/algorithm_genome-0.3.0-py3-none-any.whl
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
After the package owner publishes version 0.3.0 to PyPI, the public command will be:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
python -m pip install algorithm-genome
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The release artifacts are prepared locally; this repository change does not
|
|
25
|
+
upload them to PyPI. For local development, use `python -m pip install -e '.[test]'`.
|
|
26
|
+
|
|
27
|
+
Use the library from any working directory:
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import pandas as pd
|
|
31
|
+
from algorithm_genome import Recommender, TrainedClassifier
|
|
32
|
+
|
|
33
|
+
# Load the pretrained model installed with the library.
|
|
34
|
+
model = Recommender()
|
|
35
|
+
data = pd.read_csv("my_dataset.csv")
|
|
36
|
+
|
|
37
|
+
# Rank algorithms without training candidate classifiers.
|
|
38
|
+
report = model.recommend(data, target="outcome")
|
|
39
|
+
print(pd.DataFrame(report["ranking"]))
|
|
40
|
+
print(report["meta_model_training_warnings"])
|
|
41
|
+
|
|
42
|
+
# Cross-validate candidates, evaluate a reserved holdout, and refit the winner.
|
|
43
|
+
result = model.verify(data, target="outcome", budget_seconds=60)
|
|
44
|
+
print(result.selected_algorithm)
|
|
45
|
+
print(result.report["holdout_metrics"])
|
|
46
|
+
|
|
47
|
+
# Predict now, or save the selected classifier for later scripts.
|
|
48
|
+
new_rows = pd.read_csv("new_rows.csv")
|
|
49
|
+
predictions = result.predict(new_rows)
|
|
50
|
+
result.save("my_output")
|
|
51
|
+
classifier = TrainedClassifier.load("my_output/selected_classifier.joblib")
|
|
52
|
+
predictions = classifier.predict(new_rows)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The pretrained neural model was trained on 51 dataset versions from 43 source
|
|
56
|
+
groups. It remains **experimental**: its optimizer reported a convergence warning,
|
|
57
|
+
which is retained in reports. On seven previously reserved source groups it lost
|
|
58
|
+
2.086 macro-F1 points on average at the first choice, compared with 1.204 for a
|
|
59
|
+
simple fixed portfolio trained on the same corpus. Lower loss is better. These
|
|
60
|
+
small-cohort results do not establish general recommendation reliability.
|
|
61
|
+
Package resources include `assets/model_info.json` with provenance, checksum,
|
|
62
|
+
training warnings, and the evaluation summary. No raw training tables are shipped.
|
|
63
|
+
|
|
64
|
+
Simple commented scripts are in `examples/` in the source distribution. Copy them
|
|
65
|
+
into your own working folder and run:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
python recommend.py # Uses the installed pretrained model immediately
|
|
69
|
+
python verify_and_save.py # Saves the best measured classifier to algorithm_genome_output/
|
|
70
|
+
python predict.py # Loads that classifier and predicts two new rows
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
They use generated data and explain each framework call. Training is optional:
|
|
74
|
+
`train_recommender.py` illustrates fitting your own model with four small bundled
|
|
75
|
+
scikit-learn datasets. Its output, `my_recommender.joblib`, can be opened using
|
|
76
|
+
`Recommender.load("my_recommender.joblib")`. Four sources demonstrate execution;
|
|
77
|
+
they do not establish recommendation quality. The combined `use_framework.py`
|
|
78
|
+
example accepts your CSVs and an optional custom `--model`:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python use_framework.py my_dataset.csv --target outcome \
|
|
82
|
+
--predict-csv new_rows.csv --output my_output
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
To train from your own historical DataFrames:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from algorithm_genome import Dataset, Recommender, benchmark_datasets
|
|
89
|
+
|
|
90
|
+
# historical_tables maps source names to labeled DataFrames.
|
|
91
|
+
datasets = [
|
|
92
|
+
Dataset(id=name, data=frame, target="outcome", group=name)
|
|
93
|
+
for name, frame in historical_tables.items()
|
|
94
|
+
]
|
|
95
|
+
benchmark = benchmark_datasets(datasets)
|
|
96
|
+
model = Recommender.fit(benchmark)
|
|
97
|
+
print(model.artifact["evaluation"])
|
|
98
|
+
model.save("my_recommender.joblib")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
At least four independent source groups with all ten successful candidate results
|
|
102
|
+
are required. Related dataset variants must share a `group`. Benchmarking also
|
|
103
|
+
accepts a CSV manifest and optional resumable checkpoint:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
benchmark = benchmark_datasets(
|
|
107
|
+
"dataset_manifest.json", output_path="benchmark.json", resume=True,
|
|
108
|
+
)
|
|
109
|
+
model = Recommender.fit(benchmark)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Manifest entries contain `id`, `path`, `target`, and optional `group`/`source`.
|
|
113
|
+
CSV paths are relative to the manifest. Duplicate content is rejected. Inputs are
|
|
114
|
+
validated before fitting; resume reuses only complete compatible results.
|
|
115
|
+
|
|
116
|
+
Public API:
|
|
117
|
+
|
|
118
|
+
| Interface | Result |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| `Recommender()` | Included pretrained recommender; no paths or downloads |
|
|
121
|
+
| `Dataset(id, data, target, group=None)` | Historical table and source identity |
|
|
122
|
+
| `benchmark_datasets(datasets_or_manifest, output_path=None, progress=False, resume=False)` | Dictionary of measured candidate scores/times and genomes |
|
|
123
|
+
| `Recommender.fit(benchmark_or_path)` | Custom recommender with group-separated evaluation |
|
|
124
|
+
| `Recommender.load(path)` / `model.save(path)` | Read/write a custom trusted joblib artifact |
|
|
125
|
+
| `model.recommend(data, target)` | Predicted ranking, genome, summaries, and warnings |
|
|
126
|
+
| `model.verify(data, target, *, top_k=3, budget_seconds=300, progress=None)` | `VerificationResult` with `report` and `classifier` |
|
|
127
|
+
| `result.predict(data)` / `classifier.predict(data)` | NumPy array of string labels |
|
|
128
|
+
| `result.save(directory)` | Report JSON, predicted ranking CSV, classifier joblib |
|
|
129
|
+
| `TrainedClassifier.load(path)` / `classifier.save(path)` | Read/write a selected classifier |
|
|
130
|
+
| `extract_dataset_genome(X, y)` | Seventeen properties from aligned training rows |
|
|
131
|
+
|
|
132
|
+
Library calls are quiet by default. `verify(progress=callback)` emits event
|
|
133
|
+
dictionaries such as `candidate_start` and `candidate_complete`. Existing
|
|
134
|
+
lower-level `train_meta_model`, `recommend_algorithms`, and
|
|
135
|
+
`verify_recommendations` functions remain exported.
|
|
136
|
+
|
|
137
|
+
The installed CLI uses the pretrained model by default too:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
algorithm-genome recommend my_dataset.csv --target outcome --verify --output my_output
|
|
141
|
+
algorithm-genome predict my_output/selected_classifier.joblib \
|
|
142
|
+
new_rows.csv --output predictions.csv
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Supply `--meta-model custom.joblib` to use your own recommender, `--json` for
|
|
146
|
+
machine output, or `--verbose` for detailed terminal metrics. Research utilities
|
|
147
|
+
are available through `python -m algorithm_genome.download_public_datasets`,
|
|
148
|
+
`prepare_additional_datasets`, `improve_meta_model`, and
|
|
149
|
+
`train_neural_recommender`; use their `--help` options.
|
|
150
|
+
|
|
151
|
+
Scope and interpretation:
|
|
152
|
+
|
|
153
|
+
- Independent-row labeled tabular **classification**, with an explicit target.
|
|
154
|
+
Regression, forecasting, image models, and text models are not implemented.
|
|
155
|
+
- At least 30 distinct labeled rows, two classes, and three rows per class.
|
|
156
|
+
Missing-target rows and duplicate records are removed. Features can be numeric
|
|
157
|
+
or categorical. Outputs are strings; use `pd.read_csv(..., dtype={"outcome": str})`
|
|
158
|
+
to preserve labels such as `01`.
|
|
159
|
+
- Ten fixed candidate configurations, with no automatic hyperparameter tuning.
|
|
160
|
+
Ranking scores predict relative macro-F1, not accuracy or confidence.
|
|
161
|
+
- Verification reserves a holdout before extracting its recommendation genome.
|
|
162
|
+
Preprocessing is fitted inside each CV training fold. The final classifier is
|
|
163
|
+
refitted on all usable rows after holdout evaluation.
|
|
164
|
+
- `top_k` prioritizes the shortlist, followed by a challenger and remaining
|
|
165
|
+
candidates. Runtime budgets are soft and checked between fits; active fits finish.
|
|
166
|
+
- Prediction inputs need the training feature names. Column order may differ,
|
|
167
|
+
extra columns are ignored, and missing or duplicate columns raise `ValueError`.
|
|
168
|
+
- Custom joblib files must be trusted and use matching dependency versions.
|
|
169
|
+
The default model is loaded from verified package resources.
|
|
170
|
+
|
|
171
|
+
To build a release from the source tree:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
python -m pip install -e '.[test,release]'
|
|
175
|
+
make release
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`make release` runs the test suite, builds both archives, checks their metadata,
|
|
179
|
+
and tests installed copies of the wheel and a wheel rebuilt from the source
|
|
180
|
+
archive. The installation checks run from temporary working directories with
|
|
181
|
+
network access blocked and editable-install hooks disabled. They exercise the
|
|
182
|
+
default recommender, verification, saving/reloading, predictions, and the installed
|
|
183
|
+
CLI. Build tooling and declared dependencies must already be installed; the
|
|
184
|
+
release checks do not download anything. Use a `dist/` folder containing only the
|
|
185
|
+
current version. To check existing archives alone, run
|
|
186
|
+
`python scripts/check_release.py dist/` (also `make check-release` in a checkout).
|
|
187
|
+
Without Make, run `python -m pytest -q`, `python -m build --no-isolation`,
|
|
188
|
+
`python -m twine check dist/*`, and the check script in that order.
|
|
189
|
+
|
|
190
|
+
The resulting wheel and source archive both include the pretrained model. Only
|
|
191
|
+
the package owner should upload the reviewed release using an authenticated PyPI
|
|
192
|
+
account with `python -m twine upload dist/*`, following the
|
|
193
|
+
[Python packaging guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/).
|
|
194
|
+
Uploading is separate from building and local installation.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Learn algorithm recommendations from dataset and algorithm genomes."""
|
|
2
|
+
|
|
3
|
+
from .dataset_genome import extract_dataset_genome
|
|
4
|
+
from .benchmark_datasets import Dataset, benchmark_datasets
|
|
5
|
+
from .framework import Recommender, VerificationResult
|
|
6
|
+
from .recommend_algorithms import TrainedClassifier, recommend_algorithms, verify_recommendations
|
|
7
|
+
from .train_meta_model import train_meta_model
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"Dataset", "Recommender", "TrainedClassifier", "VerificationResult",
|
|
11
|
+
"benchmark_datasets", "extract_dataset_genome", "recommend_algorithms",
|
|
12
|
+
"verify_recommendations", "train_meta_model",
|
|
13
|
+
]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Candidate configurations and explicit algorithm genome attributes."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
|
|
7
|
+
from sklearn.ensemble import ExtraTreesClassifier, GradientBoostingClassifier, RandomForestClassifier
|
|
8
|
+
from sklearn.linear_model import LogisticRegression, RidgeClassifier
|
|
9
|
+
from sklearn.naive_bayes import GaussianNB
|
|
10
|
+
from sklearn.neighbors import KNeighborsClassifier
|
|
11
|
+
from sklearn.svm import SVC
|
|
12
|
+
from sklearn.tree import DecisionTreeClassifier
|
|
13
|
+
|
|
14
|
+
LIBRARY_VERSION = 1
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def algorithm_library():
|
|
18
|
+
# Qualitative properties are hypotheses for the meta-model, not suitability scores.
|
|
19
|
+
definitions = [
|
|
20
|
+
("logistic_regression", LogisticRegression(max_iter=1500, class_weight="balanced", random_state=42),
|
|
21
|
+
"linear", "convex", "low", "high", "medium", "linear", "low", True),
|
|
22
|
+
("decision_tree", DecisionTreeClassifier(class_weight="balanced", random_state=42),
|
|
23
|
+
"tree", "greedy", "low", "high", "medium", "nonlinear", "high", False),
|
|
24
|
+
("random_forest", RandomForestClassifier(n_estimators=80, class_weight="balanced", random_state=42, n_jobs=1),
|
|
25
|
+
"ensemble", "bagging", "medium", "low", "high", "nonlinear", "high", False),
|
|
26
|
+
("extra_trees", ExtraTreesClassifier(n_estimators=80, class_weight="balanced", random_state=42, n_jobs=1),
|
|
27
|
+
"ensemble", "randomized_bagging", "medium", "low", "high", "nonlinear", "high", False),
|
|
28
|
+
("gradient_boosting", GradientBoostingClassifier(n_estimators=70, random_state=42),
|
|
29
|
+
"ensemble", "boosting", "medium", "low", "medium", "nonlinear", "high", False),
|
|
30
|
+
("nearest_neighbors", KNeighborsClassifier(n_neighbors=5),
|
|
31
|
+
"instance", "lazy", "low", "medium", "low", "nonlinear", "high", True),
|
|
32
|
+
("support_vector_machine", SVC(class_weight="balanced", cache_size=200),
|
|
33
|
+
"kernel", "convex", "high", "low", "medium", "nonlinear", "high", True),
|
|
34
|
+
("gaussian_naive_bayes", GaussianNB(),
|
|
35
|
+
"probabilistic", "closed_form", "low", "high", "low", "nonlinear", "low", False),
|
|
36
|
+
("linear_discriminant", LinearDiscriminantAnalysis(solver="lsqr", shrinkage="auto"),
|
|
37
|
+
"linear", "closed_form", "medium", "high", "medium", "linear", "low", True),
|
|
38
|
+
("ridge_classifier", RidgeClassifier(class_weight="balanced", solver="lsqr"),
|
|
39
|
+
"linear", "closed_form", "low", "high", "medium", "linear", "low", True),
|
|
40
|
+
]
|
|
41
|
+
fields = ["structure", "optimization", "training_cost", "interpretability", "robustness",
|
|
42
|
+
"boundary", "capacity", "scaling_sensitive"]
|
|
43
|
+
return {name: {"estimator": estimator, "genome": {
|
|
44
|
+
"paradigm": "supervised", "task": "classification", **dict(zip(fields, attributes)),
|
|
45
|
+
}} for name, estimator, *attributes in definitions}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def library_signature():
|
|
49
|
+
configurations = {name: {"genome": item["genome"], "parameters": item["estimator"].get_params()}
|
|
50
|
+
for name, item in algorithm_library().items()}
|
|
51
|
+
return hashlib.sha256(json.dumps(configurations, sort_keys=True).encode()).hexdigest()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def meta_features(dataset_genome, algorithm_name, include_algorithm_genome=True):
|
|
55
|
+
item = algorithm_library()[algorithm_name]
|
|
56
|
+
features = {f"dataset_{key}": value for key, value in dataset_genome.items()}
|
|
57
|
+
features["algorithm_name"] = algorithm_name
|
|
58
|
+
if include_algorithm_genome:
|
|
59
|
+
features.update({f"algorithm_{key}": value for key, value in item["genome"].items()})
|
|
60
|
+
return features
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Algorithm Genome pretrained neural recommender",
|
|
3
|
+
"package_version": "0.3.0",
|
|
4
|
+
"sklearn_version": "1.9.1",
|
|
5
|
+
"sha256": "c7ea17bdcd38941b6b50b3708d549f0624487b32e2db73303cc319d29a513df7",
|
|
6
|
+
"source_artifact_sha256": "698a9d7c340b5d7e9aca71be09a6828cb184a9c6c61b0125a48e57051797d0e6",
|
|
7
|
+
"training_dataset_count": 51,
|
|
8
|
+
"training_source_group_count": 43,
|
|
9
|
+
"genome_input_count": 17,
|
|
10
|
+
"candidate_count": 10,
|
|
11
|
+
"architecture": "17 inputs, 8 tanh hidden units, 10 relative macro-F1 outputs",
|
|
12
|
+
"status": "experimental",
|
|
13
|
+
"training_warnings": [
|
|
14
|
+
"lbfgs failed to converge after 29 iteration(s) (status=2):\nABNORMAL: \n\nYou might also want to scale the data as shown in:\n https://scikit-learn.org/stable/modules/preprocessing.html"
|
|
15
|
+
],
|
|
16
|
+
"evaluation": {
|
|
17
|
+
"reserved_source_groups": 7,
|
|
18
|
+
"neural_first_choice_f1_points_lost": 2.086,
|
|
19
|
+
"same_corpus_fixed_portfolio_first_choice_f1_points_lost": 1.204,
|
|
20
|
+
"note": "The simple portfolio was stronger on this small examined cohort. This is not a guarantee for new datasets."
|
|
21
|
+
},
|
|
22
|
+
"notes": [
|
|
23
|
+
"This is the existing 51-dataset/43-source-group artifact; no retraining or final-cohort selection was performed for packaging.",
|
|
24
|
+
"Source tables, user data, project-local paths, and selected classifiers are not distributed with the model.",
|
|
25
|
+
"Ranking scores are predicted relative macro-F1 advantages, not accuracy or confidence probabilities.",
|
|
26
|
+
"The production optimizer warning is retained in recommendation reports."
|
|
27
|
+
]
|
|
28
|
+
}
|