sklearn-genetic-opt
Tune a scikit-learn estimator or find a smaller set of features. Give the search a model, a scorer and a budget. It evaluates candidates with cross-validation, refits the winner and lets you call predict on new data. Use it when the combinations of parameters or columns would make an exhaustive search too expensive.
Stable documentation · Backend tutorial · Benchmarks · Plot gallery
Run your first search
Install the published package on Python 3.12 or newer:
python -m pip install sklearn-genetic-opt
How deep should a decision tree grow? Search integer depths and two split criteria on the training set. Compare the winning cross-validation score with balanced accuracy on data the search never saw.
from sklearn.datasets import load_breast_cancer
from sklearn.metrics import balanced_accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn_genetic import GASearchCV
from sklearn_genetic.space import Categorical, Integer
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
X, y, stratify=y, test_size=0.25, random_state=7
)
tree = DecisionTreeClassifier(random_state=7)
settings = dict(cv=3, scoring="balanced_accuracy", population_size=8,
generations=3, random_state=7, n_jobs=1, verbose=False)
search = GASearchCV(
tree,
param_grid={"max_depth": Integer(2, 12), "criterion": Categorical(["gini", "entropy"])},
**settings,
).fit(X_train, y_train)
print(search.best_params_, search.best_score_)
print(balanced_accuracy_score(y_test, search.predict(X_test)))
Which columns does the tree need?
Reuse the model, folds and budget with GAFeatureSelectionCV. Set an upper limit of eight columns. The fitted selector applies its mask during prediction.
from sklearn_genetic import GAFeatureSelectionCV
selector = GAFeatureSelectionCV(tree, max_features=8, **settings).fit(X_train, y_train)
print(selector.get_support(indices=True))
print(balanced_accuracy_score(y_test, selector.predict(X_test)))
Choose an optimizer
Version 0.16.0 includes DEAP by default and supports four optional engines. Install the extra for the engine you want. For example, to use pymoo:
python -m pip install "sklearn-genetic-opt[pymoo]==0.16.0"
Change one parameter on either estimator to run the same experiment with a different engine. Cloning keeps the earlier result available for comparison.
from sklearn.base import clone
alternative = clone(selector).set_params(optimizer_backend="pymoo")
alternative.fit(X_train, y_train)
print(alternative.get_support(indices=True), alternative.fit_stats_["cross_validate_calls"])
Backend |
What it brings to the search |
|---|---|
deap |
Included by default. Choose genetic operators, adaptive schedules and local search. |
scipy |
Differential evolution for bounded spaces. It can stop early when the population converges. |
nevergrad |
OnePlusOne adjusts its mutations as candidates succeed or fail. TwoPointsDE is also available. |
cmaes |
CatCMA with Margin learns how numeric variables vary together and adapts category probabilities. |
pymoo |
Uses type-specific operators for mixed parameters and a binary genetic algorithm for feature masks. |
Each optional engine has a pip extra with the same name. All five support live plotting, early stopping and resuming from a completed generation. The engine reference lists supported domains, controls and checkpoint requirements. To integrate another optimizer, see the plugin protocol.
How do they compare? Across five held-out splits, pymoo had the lowest mean RMSE on both synthetic linear-regression feature-selection tasks. DEAP had the lowest mean RMSE when tuning a tree on Friedman #1. The benchmarks compare nine workloads at matched counts of actual CV calls and include overhead, raw measurements and commands to reproduce the runs.
Inspect a fitted search
Use cv_results_ for individual candidates and history for progress by generation. This example from the digits walkthrough shows how a neural network search progressed and which candidates finished near the top.
Go further
Build a search with the GASearchCV, GAFeatureSelectionCV and search space references.
Track a long run with the checkpoint recipe, plot gallery and backend tutorial.
Work on the project with the contributor guide and release notes.
Cite sklearn-genetic-opt
If you use the library in research, cite the version used in your experiment. For version 0.16.0, cite Rodrigo Arenas (2026), sklearn-genetic-opt (version 0.16.0) [Computer software]. The software citation contains the machine-readable metadata. For BibTeX, use:
@software{arenas2026sklearn_genetic_opt,
author = {Arenas, Rodrigo},
title = {{sklearn-genetic-opt}},
year = {2026},
version = {0.16.0},
url = {https://pypi.org/project/sklearn-genetic-opt/0.16.0/}
}
Metadata
Release files for sklearn-genetic-opt 0.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sklearn_genetic_opt-0.16.0.tar.gz | 104.4 kB | With provenance | Details for sklearn_genetic_opt-0.16.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sklearn_genetic_opt-0.16.0-py3-none-any.whl | Python 3 | none | any | Details for sklearn_genetic_opt-0.16.0-py3-none-any.whl |
Total release size: 220.7 kB
Release files / sklearn_genetic_opt-0.16.0.tar.gz
| Download URL | sklearn_genetic_opt-0.16.0.tar.gz |
|---|---|
| Size | 104.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9761001dffbf2d6fc53d96d71a9c0fefa0471b029685bbabafa7d6f0f3633062
|
|
BLAKE2b-256 checksum How to use checksums |
c8689d4e3c25b8970af0b1a67cb43c49760f13f1ea2eec7bf71fa99919dc8321
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / sklearn_genetic_opt-0.16.0-py3-none-any.whl
| Download URL | sklearn_genetic_opt-0.16.0-py3-none-any.whl |
|---|---|
| Size | 116.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94ea157755951c2b169edf43ee29503c0c5421f39b27507d9293472899c2a0e5
|
|
BLAKE2b-256 checksum How to use checksums |
827b77bb05e04814b9f66242afa46ef882a472e440978bb5be39d701f4042f19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for sklearn-genetic-opt 0.16.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sklearn_genetic_opt-0.16.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.