HyperparameterTuner#
- class openstef_models.integrations.optuna.tuner.HyperparameterTuner[ConfigT: BaseConfig](*, config: ConfigT, train_dataset: TimeSeriesDataset, create_workflow: Callable[[ConfigT], CustomForecastingWorkflow], target_quantile: Union[Quantile, Literal['global']], metric_name: str, direction: Literal['maximize', 'minimize'] = 'maximize', n_trials: int = 20, n_jobs: int = 1, seed: int | None = 42, study_name: str = 'hyperparameter_tuning')[source]
Bases:
BaseConfig,Generic[ConfigT]Bayesian hyperparameter tuner powered by Optuna.
Orchestrates an Optuna study over the tunable search spaces declared on
HyperParamsfields of the provided config. Override methods prefixed with_to customise study creation, objective evaluation, or parameter suggestion.- Parameters:
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'ignore', 'protected_namespaces': ()}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- config: ConfigT
- train_dataset: TimeSeriesDataset
- create_workflow: Callable[[ConfigT], CustomForecastingWorkflow]
- metric_name: str
- direction: Literal['maximize', 'minimize']
- n_trials: int
- n_jobs: int
- study_name: str
- static suggest_value(trial: Trial, trial_key: str, tuning_range: TuningRange) bool | int | float | str | None[source]
Suggest a single parameter value via the Optuna trial API.
Override to add custom suggestion logic or constraints.
- tune(*, show_progress_bar: bool = True) tuple[ConfigT, Study][source]
Run the Optuna study and return the best config.
- Return type:
tuple[ConfigT,Study]- Returns:
(best_config, study)tuple.- Raises:
ValueError – If no tunable fields are found or metric_name is invalid.
- Parameters:
show_progress_bar (
bool)
- fit_with_tuning(*, show_progress_bar: bool = True) TuningResult[ConfigT][source]
Tune, then fit a final workflow with the best config.
- Return type:
TuningResult[ConfigT]- Returns:
TuningResultwith the best config and Optuna study.- Raises:
RuntimeError – If the final workflow fit fails after tuning.
- Parameters:
show_progress_bar (
bool)