canari.optimizer#
This module automates the search for optimal hyperparameters of
Model and SKF instances by leveraging the
external libraries Ray Tune and Optuna.
- class canari.optimizer.Optimizer(model: Callable, param: dict, model_input: dict | None = None, num_optimization_trial: int | None = 50, grid_search: bool | None = False, mode: str | None = 'min', algorithm: str | None = 'TPE', back_end: str | None = 'ray', num_startup_trials: int | None = 20)[source]#
Bases:
objectOptimize hyperparameters for
ModelandSKFusing the Ray Tune and Optuna external libraries. Optimization is based on the metric saved inmetric_optimforModelormetric_optimforSKF.- Parameters:
model (Callable) – Function that returns a model instance given a model configuration.
param (Dict[str, list]) – Parameter search space: two-value lists [min, max] for defining the bounds of the optimization. Users can also use Ray Tune search space object such as: tune.randint(12, 53), tune.uniform(0.1, 0.4), tune.loguniform(1e-1, 4e-1).
model_input (Dict) – Any other inputs for the model that is different from the model’s parameters.
num_optimization_trial (int, optional) – Number of random search trials (ignored for grid-search). Defaults to 50.
grid_search (bool, optional) – If True, perform grid search. Defaults to False.
algorithm (str, optional) – Search algorithm: ‘TPE’ (OptunaSearch) or ‘random’ (random sampling). Defaults to ‘TPE’.
mode (str, optional) – Direction for optimization stopping: “min” or “max”. Defaults to “min”.
back_end (str, optional) – “ray”. Using the external library Ray for optimization.
num_startup_trials (int, optional) – Number of start up trial when using TPE sampling. Defaults to 20.
- model_optim#
The best model instance initialized with optimal parameters after running optimize().
- param_optim#
The best hyperparameter configuration found during optimization.
- Type:
Dict
- get_best_model()[source]#
Retrieve the optimized model instance after running optimization.
- Returns:
Model instance initialized with the best hyperparameter values.
- get_best_param() Dict[source]#
Retrieve the optimized parameters after running optimization.
- Returns:
Best hyperparameter values.
- Return type:
dict