Skip to content

sklearn-genetic-optHyperparameter Tuning for scikit-learn

Find better parameters faster. Evolutionary search handles cross-parameter interactions that GridSearchCV and RandomizedSearchCV miss — with feature selection, callbacks, and MLflow built in.

sklearn-genetic-opt logo

How It Works

Genetic algorithms mimic natural selection to explore hyperparameter space more efficiently than grid or random search.

01

Initialize Population

Latin hypercube sampling generates a diverse initial population covering the search space more evenly than random starts.

02

Evaluate Fitness

Each candidate configuration is cross-validated in parallel. Duplicates are cached — identical configs are never re-evaluated.

03

Select & Reproduce

Tournament selection picks the strongest individuals. Uniform crossover and mutation create offspring with new combinations.

04

Converge or Continue

Diversity control and fitness sharing prevent premature convergence. Callbacks stop the search when it plateaus or hits a budget.

Population Evaluate Select Crossover Mutate Best params

Why Evolutionary Algorithms?

Each method has strengths. Genetic algorithms win on large search spaces with parameter interactions.

MethodHandles InteractionsScales to 10+ Paramssklearn CompatibleFeature SelectionBest For
GridSearchCV~< 4 parameters, exhaustive coverage needed
RandomizedSearchCV~Quick baseline, budget constrained
Optuna~Bayesian search, non-sklearn objectives
RFE / SelectFromModel~Feature selection only, no hyperparameter tuning
sklearn-genetic-opt ✦Joint hyperparameter + feature search in one step

✦ = sklearn-genetic-opt  |  ✓ = yes  |  ~ = partial  |  ✗ = no

Up and Running in 30 Seconds

Install the package, define a search space, call fit. The GA finds better hyperparameters than a grid search in the same budget.

1Install
2Define search space
3Fit & inspect results
Python
# pip install sklearn-genetic-opt

from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from sklearn_genetic import GASearchCV
from sklearn_genetic.space import Integer, Continuous

X, y = load_breast_cancer(return_X_y=True)

param_grid = {
    "n_estimators":     Integer(50, 500),
    "max_depth":        Integer(3, 15),
    "min_samples_split": Integer(2, 20),
    "max_features":     Continuous(0.2, 1.0),
}

evolved_estimator = GASearchCV(
    estimator=RandomForestClassifier(),
    cv=5,
    param_grid=param_grid,
    population_size=20,
    generations=15,
    random_state=42,
    n_jobs=-1,
)

evolved_estimator.fit(X, y)
print(evolved_estimator.best_params_)
print(evolved_estimator.best_score_)

Solve Real Problems

Copy-paste recipes for common tasks. Each one runs as-is and takes 5–10 minutes to read.

Learning Paths

Choose based on your experience. Each path is a curated sequence of docs.

🌱Beginner

First Optimization

Never used a genetic algorithm? Start here. You'll run your first GASearchCV in under 10 minutes.

  1. Installation
  2. How hyperparameter optimization works
  3. Tune a Random Forest (tutorial)
  4. Basic usage example
Start the beginner path →
⚙️Intermediate

Production Tuning

You've run a basic search. Now learn callbacks, parallel evaluation, MLflow logging, and pipelines.

  1. Choosing the right search space
  2. Common tuning mistakes to avoid
  3. Tune XGBoost / LightGBM
  4. Callbacks & early stopping
Browse intermediate recipes →
🏆Advanced

Evolutionary Mastery

Deep-dive into GA mechanics, feature selection, custom operators, and multi-metric optimization.

  1. Feature selection with GAFeatureSelectionCV
  2. Warm-start and custom initialization
  3. Benchmarks vs Optuna & random search
  4. API reference — all parameters
View advanced recipes →

Works With Your Stack

Any scikit-learn compatible estimator works — including the most popular gradient boosting libraries.

Experiment Tracking
Parallelism
Visualization

See What You Get

Rich built-in visualizations — from fitness evolution to parameter interaction heatmaps.

Fitness evolution over generations
plot_fitness_evolution()

Track score improvement across generations

Search overview dashboard
plot_search_overview()

Full-run dashboard: diversity, stagnation, scores

Parameter interaction heatmap for XGBoost
plot_search_space()

Discover learning_rate × n_estimators interactions

Parameter evolution over generations
plot_parameter_evolution()

Watch each hyperparameter converge over time

Population diversity over generations
plot_diversity()

Monitor genetic diversity and diversity control events

Score landscape visualization
plot_score_landscape()

Visualize score surface across parameter pairs

Open Source & Community Driven

sklearn-genetic-opt is MIT licensed and actively maintained. Contributions, bug reports, and feature requests are welcome. If it saves you time, a GitHub star helps other practitioners discover it.

MITLicense
Python 3.12+Requirement
scikit-learnCompatible with
0.13Latest stable
pip install sklearn-genetic-opt

Released under the MIT License.