tempor.automl.tuner module¶
Module containing the interface for, and the implemented hyperparameter tuners.
- class tempor.automl.tuner.EvaluationCallback(*args, **kwargs)[source]¶
Bases:
ProtocolEvaluation callback callable.
Should take in
Type[BasePredictor]as first argument, then the dataset (PredictiveDataset), hyperparameters, returning afloatscore.Signature like:
(estimator: Type[BasePredictor], dataset: PredictiveDataset, *args: Any, **kwargs: Any) -> float.
- class tempor.automl.tuner.BaseTuner(study_name: str, direction: Literal[minimize] | Literal[maximize], **kwargs: Any)[source]¶
Bases:
ABCBase hyperparameter tuner from which tuner implementations should derive. Defines the initializer and the
tunemethod.- Parameters:¶
-
abstract tune(estimator: type[BasePredictor] | PipelineSelector, dataset: PredictiveDataset, evaluation_callback: EvaluationCallback, override_hp_space: list[Params] | None =
None, compute_baseline_score: bool =True, **kwargs: Any) tuple[list[float], list[dict]][source]¶ Run the hyperparameter tuner and return scores and chosen hyperparameters.
- Parameters:¶
- estimator : AutoMLCompatibleEstimator¶
Estimator class, or
PipelineSelector, whose hyperparameters will be tuned.- dataset : PredictiveDataset¶
Dataset to use.
- evaluation_callback : EvaluationCallback¶
Evaluation callback which will take in the estimator class, hyperparameters, and return a score.
- override_hp_space : Optional[List[Params]]¶
If this is not
None, hyperparameters will be sampled from this list, rather than from those defined in thehyperparameter_spacemethod of the estimator. Defaults toNone.- compute_baseline_score : bool, optional¶
If
True, a trial will be run with default parameters (hyperparameters passed to__init__as an empty dictionary). This will be returned as the zeroth item inscoresandparams. IfFalse, this will be skipped. Defaults toTrue.- **kwargs : Any
Currently unused.
- Returns:¶
(scores, params)tuple, containing a list of scores for the tuning runs and a list of dictionaries containing the parameters for each corresponding tuning run.- Return type:¶
Tuple[List[float], List[Dict]]
-
class tempor.automl.tuner.OptunaTuner(study_name: str, direction: Literal[minimize] | Literal[maximize], *, study_sampler: BaseSampler, study_storage: str | BaseStorage | None =
None, study_pruner: BasePruner | None =None, study_load_if_exists: bool =False, **kwargs: Any)[source]¶ Bases:
BaseTunerHyper parameter tuning (optimization) helper for an
optuna.study.Studyusing anyoptuna.sampler.BaseSampler.- Parameters:¶
- study_name : str¶
Study name.
- direction : metric_typing.MetricDirection¶
Optimization direction (
"minimize"or"maximize").- study_sampler : optuna.samplers.BaseSampler¶
An
optunasampler (passed tooptuna.create_study).- study_storage : Optional[Union[str, optuna.storages.BaseStorage]], optional¶
An
optunastorage object (passed tooptuna.create_study). Defaults toNone.- study_pruner : Optional[optuna.pruners.BasePruner], optional¶
An
optunapruner (passed tooptuna.create_study). Defaults toNone.- study_load_if_exists : bool, optional¶
The
load_if_existsparameter (passed tooptuna.create_study). Defaults toFalse.- **kwargs : Any
Currently unused.
- create_study() Study[source]¶
Create an
optuna.Studyto be used for tuning. Sets theself.studyattribute.
-
tune(estimator: type[BasePredictor] | PipelineSelector, dataset: PredictiveDataset, evaluation_callback: EvaluationCallback, override_hp_space: list[Params] | None =
None, compute_baseline_score: bool =True, optimize_kwargs: dict[str, Any] | None =None, **kwargs: Any) tuple[list[float], list[dict]][source]¶ Run the hyperparameter tuner and return scores and chosen hyperparameters.
- Parameters:¶
- estimator : AutoMLCompatibleEstimator¶
Estimator class, or
PipelineSelector, whose hyperparameters will be tuned.- dataset : PredictiveDataset¶
Dataset to use.
- evaluation_callback : EvaluationCallback¶
Evaluation callback which will take in the estimator class, hyperparameters, and return a score.
- override_hp_space : Optional[List[Params]]¶
If this is not
None, hyperparameters will be sampled from this list, rather than from those defined in thehyperparameter_spacemethod of the estimator. Defaults toNone.- compute_baseline_score : bool, optional¶
If
True, a trial will be run with default parameters (hyperparameters passed to__init__as an empty dictionary). This will be returned as the zeroth item inscoresandparams. IfFalse, this will be skipped. Defaults toTrue.- optimize_kwargs : Optional[Dict[str, Any]], optional¶
Keyword arguments to pass to
study.optimize. Defaults toNone.- **kwargs : Any
Currently unused.
- Returns:¶
(scores, params)tuple, containing a list of scores for the tuning runs and a list of dictionaries containing the parameters for each corresponding tuning run.- Return type:¶
Tuple[List[float], List[Dict]]