{ "cells": [ { "cell_type": "markdown", "id": "title", "metadata": {}, "source": [ "# Plotting the Search\n", "\n", "This notebook walks through the plotting helpers in `sklearn-genetic-opt`. It shows the default fitness view, richer history and logbook views, and two search-space plot styles that make it easier to understand how the optimizer explored the parameter space.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "setup", "metadata": { "ExecuteTime": { "end_time": "2026-06-20T18:39:21.425258Z", "start_time": "2026-06-20T18:39:21.225944600Z" }, "execution": { "iopub.execute_input": "2026-06-21T20:54:21.509277Z", "iopub.status.busy": "2026-06-21T20:54:21.508654Z", "iopub.status.idle": "2026-06-21T20:55:19.532231Z", "shell.execute_reply": "2026-06-21T20:55:19.530432Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " gen evals avg best div unique stag mut sel events\n", "---- ----- ------------- ------------- ------- ------- ----- ------- ----- ------------------\n", " 0 4 0.14741 0.30181 0.833 1.000 0 - - - \n", " 1 8 0.20587 0.30181 0.583 1.000 1 0.050 3 - \n", " 2 8 0.25733 0.30181 0.583 0.750 2 0.050 3 dup=3 \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " 3 8 0.27799 0.30181 0.333 0.750 3 0.050 3 dup=3 \n", " 4 8 0.26608 0.30181 0.250 0.500 4 0.050 3 dup=6 \n", " 5 8 0.26157 0.30181 0.417 0.750 5 0.050 3 dup=6 \n" ] }, { "data": { "text/html": [ "
GASearchCV(crossover_probability=0.9, cv=2,\n",
" estimator=DecisionTreeRegressor(ccp_alpha=0.19121381309034374,\n",
" max_depth=2, min_samples_split=10,\n",
" random_state=42),\n",
" generations=5, mutation_probability=0.05, n_jobs=1,\n",
" param_grid={'ccp_alpha': <sklearn_genetic.space.space.Continuous object at 0x0000022C95420EC0>,\n",
" 'criterion': <sklearn_genetic.space.space.Categorical object at 0x0000022C95421940>,\n",
" 'max_depth': <sklearn_genetic.space.space.Integer object at 0x0000022C95421A90>,\n",
" 'min_samples_split': <sklearn_genetic.space.space.Integer object at 0x0000022C954507D0>},\n",
" population_size=4, return_train_score=True, scoring='r2')In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. | \n", " | estimator | \n", "DecisionTreeR...ndom_state=42) | \n", "
| \n", " | cv | \n", "2 | \n", "
| \n", " | param_grid | \n", "{'ccp_alpha': <sklearn_gene...0022C95420EC0>, 'criterion': <sklearn_gene...0022C95421940>, 'max_depth': <sklearn_gene...0022C95421A90>, 'min_samples_split': <sklearn_gene...0022C954507D0>} | \n", "
| \n", " | scoring | \n", "'r2' | \n", "
| \n", " | population_size | \n", "4 | \n", "
| \n", " | generations | \n", "5 | \n", "
| \n", " | crossover_probability | \n", "0.9 | \n", "
| \n", " | mutation_probability | \n", "0.05 | \n", "
| \n", " | n_jobs | \n", "1 | \n", "
| \n", " | return_train_score | \n", "True | \n", "
| \n", " | tournament_size | \n", "3 | \n", "
| \n", " | elitism | \n", "True | \n", "
| \n", " | verbose | \n", "True | \n", "
| \n", " | keep_top_k | \n", "1 | \n", "
| \n", " | criteria | \n", "'max' | \n", "
| \n", " | algorithm | \n", "'eaMuPlusLambda' | \n", "
| \n", " | refit | \n", "True | \n", "
| \n", " | pre_dispatch | \n", "'2*n_jobs' | \n", "
| \n", " | error_score | \n", "nan | \n", "
| \n", " | log_config | \n", "None | \n", "
| \n", " | use_cache | \n", "True | \n", "
| \n", " | warm_start_configs | \n", "None | \n", "
| \n", " | evolution_config | \n", "None | \n", "
| \n", " | population_config | \n", "None | \n", "
| \n", " | runtime_config | \n", "None | \n", "
| \n", " | optimization_config | \n", "None | \n", "
| \n", " | parallel_backend | \n", "'auto' | \n", "
| \n", " | population_initializer | \n", "'smart' | \n", "
| \n", " | local_search | \n", "False | \n", "
| \n", " | local_search_top_k | \n", "1 | \n", "
| \n", " | local_search_steps | \n", "1 | \n", "
| \n", " | local_search_radius | \n", "0.1 | \n", "
| \n", " | diversity_control | \n", "True | \n", "
| \n", " | diversity_threshold | \n", "0.25 | \n", "
| \n", " | diversity_stagnation_generations | \n", "5 | \n", "
| \n", " | diversity_mutation_boost | \n", "2.0 | \n", "
| \n", " | random_immigrants_fraction | \n", "0.1 | \n", "
| \n", " | adaptive_selection | \n", "False | \n", "
| \n", " | selection_pressure_min | \n", "2 | \n", "
| \n", " | selection_pressure_max | \n", "None | \n", "
| \n", " | offspring_diversity_retries | \n", "0 | \n", "
| \n", " | fitness_sharing | \n", "False | \n", "
| \n", " | sharing_radius | \n", "0.2 | \n", "
| \n", " | sharing_alpha | \n", "1.0 | \n", "
| \n", " | final_selection | \n", "False | \n", "
| \n", " | final_selection_top_k | \n", "3 | \n", "
| \n", " | final_selection_cv | \n", "None | \n", "
| Name | \n", "Type | \n", "Value | \n", "
|---|---|---|
| X_ | \n", "ndarray[float64](296, 10) | \n", "[[ 0.01,-0.04,-0.03,...,-0. , 0.01, 0.01],\n", " [-0. ,-0.04, 0.05,..., 0.08, 0.08, 0.05],\n", " [ 0.01, 0.05,-0.01,..., 0.07, 0.04, 0.02],\n", " ...,\n", " [ 0.03,-0.04,-0.02,...,-0.04,-0.01,-0. ],\n", " [-0.01,-0.04,-0.02,...,-0. ,-0.04,-0.04],\n", " [-0.09,-0.04, 0.03,...,-0.04,-0.01,-0. ]] | \n", "\n", "\n", "
| best_estimator_ | \n", "DecisionTreeRegressor | \n", "DecisionTreeR...ndom_state=42) | \n", "\n", "\n", "
| best_index_ | \n", "int | \n", "0 | \n", "\n", "\n", "
| best_params_ | \n", "dict | \n", "{'cc...ha': 0.19121381309034374, 'cr...on': 'sq...or', 'ma...th': 2, 'mi...it': 10} | \n", "\n", "\n", "
| best_score_ | \n", "float | \n", "0.3018 | \n", "\n", "\n", "
| cv_results_ | \n", "dict | \n", "{'me...me': [np.float64(0....6529083251953), np.float64(0....3884506225586), np.float64(0....9275588989258), np.float64(0....9248733520508), ...], 'me...me': [np.float64(0....8908386230469), np.float64(0....0425109863281), np.float64(0....6118392944336), np.float64(0....9141006469727), ...], 'me...re': [np.float64(0.3018126431428106), np.float64(0....2439934859743), np.float64(0....5429826555526), np.float64(0....5928029179815), ...], 'me...re': [np.float64(0....3243791290727), np.float64(0.4981076194721688), np.float64(0.9428519269019859), np.float64(0.738897812386645), ...], ...} | \n", "\n", "\n", "
| estimator_ | \n", "DecisionTreeRegressor | \n", "DecisionTreeR...ndom_state=42) | \n", "\n", "\n", "
| final_selection_results_ | \n", "dict | \n", "{'ca...es': [], 'changed': False, 'cv': None, 'enabled': False, ...} | \n", "\n", "\n", "
| fit_stats_ | \n", "dict | \n", "{'ca...ts': 1, 'cr...ls': 43, 'du...es': 0, 'ev...es': 44, ...} | \n", "\n", "\n", "
| multimetric_ | \n", "bool | \n", "False | \n", "\n", "\n", "
| n_features_in_ | \n", "int | \n", "10 | \n", "\n", "\n", "
| n_splits_ | \n", "int | \n", "2 | \n", "\n", "\n", "
| refit_time_ | \n", "float | \n", "0.001968 | \n", "\n", "\n", "
| scorer_ | \n", "_Scorer | \n", "make_scorer(r...hod='predict') | \n", "\n", "\n", "
| y_ | \n", "ndarray[float64](296,) | \n", "[154.,192.,116.,...,148., 64.,302.] | \n", "\n", "\n", "
DecisionTreeRegressor(ccp_alpha=0.19121381309034374, max_depth=2,\n",
" min_samples_split=10, random_state=42)| \n", " | gen | \n", "fitness_best | \n", "fitness | \n", "fitness_max | \n", "unique_individual_ratio | \n", "genotype_diversity | \n", "mutation_probability | \n", "selection_pressure | \n", "random_immigrants | \n", "duplicate_replacements | \n", "local_refinements | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | \n", "1 | \n", "0.301813 | \n", "0.205867 | \n", "0.301813 | \n", "1.00 | \n", "0.583333 | \n", "0.05 | \n", "3.0 | \n", "0 | \n", "0 | \n", "0 | \n", "
| 2 | \n", "2 | \n", "0.301813 | \n", "0.257327 | \n", "0.301813 | \n", "0.75 | \n", "0.583333 | \n", "0.05 | \n", "3.0 | \n", "0 | \n", "3 | \n", "0 | \n", "
| 3 | \n", "3 | \n", "0.301813 | \n", "0.277993 | \n", "0.301813 | \n", "0.75 | \n", "0.333333 | \n", "0.05 | \n", "3.0 | \n", "0 | \n", "3 | \n", "0 | \n", "
| 4 | \n", "4 | \n", "0.301813 | \n", "0.266084 | \n", "0.301813 | \n", "0.50 | \n", "0.250000 | \n", "0.05 | \n", "3.0 | \n", "0 | \n", "6 | \n", "0 | \n", "
| 5 | \n", "5 | \n", "0.301813 | \n", "0.261574 | \n", "0.301813 | \n", "0.75 | \n", "0.416667 | \n", "0.05 | \n", "3.0 | \n", "0 | \n", "6 | \n", "0 | \n", "