Skip to content

sklearn-genetic-optEvolutionary tuning and feature selection

Tune hyperparameters or select features by recombining candidates and scoring them with cross-validation.

How crossover makes a candidate

Uniform crossover of two feature masksParent A has bits 1 0 0 1 0 1, and parent B has bits 0 1 1 1 1 0. One choice at each position, A B A B B A, produces an offspring with bits 1 1 0 1 1 1.Column123456Parent A100101Parent B011110Inherit fromOffspringA1B1A0B1B1A1
Illustrative feature masks. A 1 keeps that column; a 0 drops it.

How It Works

Candidate configurations are scored with cross-validation, then selected and recombined across generations.

01

Initialize Population

Choose a diverse initial population, optionally including known-good parameter configurations.

02

Evaluate Fitness

Cross-validation scores each candidate. Optional caching avoids repeated evaluation of identical configurations.

03

Select & Reproduce

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

04

Converge or Continue

Diversity controls and early-stopping callbacks are available when the search needs them.

Population →Evaluate →Select →Crossover →Mutate →Best params

Run Your First Search

Install the package, define a search space, call fit. Set a cross-validation budget, then compare the result with a simple baseline.

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 EvolutionConfig, GASearchCV, RuntimeConfig
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(random_state=42),
    cv=5,
    param_grid=param_grid,
    evolution_config=EvolutionConfig(population_size=20, generations=15),
    random_state=42,
    runtime_config=RuntimeConfig(n_jobs=-1),
)

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

Learning Paths

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

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

Released under the MIT License.