Running and Monitoring Optimization =========================================== In this step, we cover how to execute the optimization process with :class:`GeneticSearch ` and monitor key metrics. The progress output from `GeneticSearch` provides real-time feedback, allowing you to track the optimization’s performance across generations and assess convergence. Executing the Optimization -------------------------- Once you have defined your model and hyperparameter space with :class:`HyperparameterSpaceBuilder `, you’re ready to execute the optimization with `GeneticSearch`. To start the optimization, call the `fit` method on your `GeneticSearch` instance, passing in the feature matrix (`X`) and target vector (`y`). This initiates the genetic algorithm, which runs the optimization over the specified number of generations and population size, iteratively refining hyperparameters. **Example: Running GeneticSearch** The example below demonstrates running `GeneticSearch` with a basic configuration: .. code-block:: python from mloptimizer.interfaces import GeneticSearch, HyperparameterSpaceBuilder from xgboost import XGBClassifier from sklearn.datasets import load_iris # Load the dataset X, y = load_iris(return_X_y=True) # Define the hyperparameter space using the default space for XGBClassifier hyperparam_space = HyperparameterSpaceBuilder.get_default_space(XGBClassifier) # Initialize GeneticSearch opt = GeneticSearch( estimator_class=XGBClassifier, hyperparam_space=hyperparam_space, genetic_params_dict={"generations": 10, "population_size": 20}, seed=42 ) # Execute the optimization opt.fit(X, y) print("Optimization completed. Best estimator found.") Progress Monitoring Output -------------------------- During the optimization process, `GeneticSearch` provides real-time feedback on the console, updating progress with each generation. The typical output includes information about: - **Progress Percentage**: Displays the percentage of generations completed out of the total specified. - **Best Fitness**: Shows the highest score (fitness) achieved so far, reflecting the performance of the best hyperparameter set found by the algorithm. - **Generation Speed**: Indicates the processing rate (e.g., iterations per second) to give an estimate of runtime. **Example Output** Here's a sample output from `GeneticSearch` while running the `fit()` method: .. code-block:: text Genetic execution: 0%| | 0/31 [00:00