Skip to content

Hyperparameter optimizer

fyt.core.hyperparameter_optimizer

Hyperparameter optimization using Optuna.

Extracted from Trainer to follow the Single Responsibility Principle.

HyperparameterOptimizer

Owns the Optuna study lifecycle for hyperparameter optimization.

Parameters:

Name Type Description Default
optuna_config OptunaConfig

Optuna configuration.

required
cross_validation_config CrossValidationConfig

Cross-validation configuration.

required
model_type str

Type of model to optimize.

required
model_params dict[str, Any]

Base model parameters.

required
experiment_logger BaseExperimentLogger | None

Experiment logger for logging trial results.

None
random_state int

Random state for reproducibility.

42
validation_size float

Validation fraction for the non-CV evaluation mode.

0.2
task TaskType

Learning task type (drives CV strategy and stratification).

CLASSIFICATION
pipeline_builder Callable[[], list[tuple[str, Any]]] | None

Callable returning fresh, unfitted (name, transformer) preprocessing steps. When provided and optuna_config.leakage_safe_cv is on, every trial is evaluated with a full sklearn Pipeline so preprocessing and feature selection are re-fit inside each CV fold (no fold leakage). When off, the steps are fit once on the whole training set (faster, optimistically biased).

None

best_params property

The best hyperparameters found by Optuna.

direction property

Optimization direction as a string ('maximize' or 'minimize').

metric_key property

Normalized name of the optimization metric (trial results column).

random_state property writable

The random state.

results_df property

The DataFrame of all trial results.

optimize(data_split)

Run Optuna hyperparameter optimization.

Parameters:

Name Type Description Default
data_split DataSplit

Data split containing training data for optimization.

required

Returns:

Type Description
dict[str, Any]

Best hyperparameters found. Empty dict if optimization is disabled.