tempor.automl.pipeline_selector module

Module with pipeline selector helper class for AutoML.

tempor.automl.pipeline_selector.get_fqn(prefix: str, name: str) str[source]

Return a full plugin name from category / task type prefix and plugin name, that is {prefix}.{name}.

class tempor.automl.pipeline_selector.PipelineSelector(task_type: Literal[prediction.one_off.classification] | Literal[prediction.one_off.regression] | Literal[prediction.temporal.classification] | Literal[prediction.temporal.regression] | Literal[time_to_event] | Literal[treatments.one_off.classification] | Literal[treatments.one_off.regression] | Literal[treatments.temporal.classification] | Literal[treatments.temporal.regression], predictor: str, static_imputers: list[str] = ['static_tabular_imputer'], static_scalers: list[str] = ['static_standard_scaler', 'static_minmax_scaler'], temporal_imputers: list[str] = ['bfill', 'ts_tabular_imputer', 'ffill'], temporal_scalers: list[str] = ['ts_minmax_scaler', 'ts_standard_scaler'])[source]

Bases: object

A helper class for AutoML pipeline selection.

Defines custom version of methods:
  • hyperparameter_space,

  • sample_hyperparameters.

Adds methods to create a pipeline from sampled hyperparameters:
  • pipeline_class_from_hps,

  • pipeline_from_hps.

Provides the tools to create candidate pipelines where the imputers / scalers are exposed as a categorical hyperparameter in the hyperparameter space. The hyperparameter space of these, and the final predictor step are also sampled.

Parameters:
task_type : PredictiveTaskType

The task type of the predictors.

predictor : str

The predictor estimator to be used as the last stage of the pipelines.

static_imputers : List[str], optional

A list of candidate static imputers. Defaults to DEFAULT_STATIC_IMPUTERS.

static_scalers : List[str], optional

A list of candidate static scalers. Defaults to DEFAULT_STATIC_SCALERS.

temporal_imputers : List[str], optional

A list of candidate temporal imputers. Defaults to DEFAULT_TEMPORAL_IMPUTERS.

temporal_scalers : List[str], optional

A list of candidate temporal scalers. Defaults to DEFAULT_TEMPORAL_SCALERS.

static format_hps_names(plugin: Any, hps: list[Params]) list[Params][source]

Format hyperparameter space of a plugin by giving each Param name as [plugin.name](hyperparameter.name). Necessary for differentiating hyperparameters of different stages in the pipeline.

Parameters:
plugin : Any

Plugin (method).

hps : List[Params]

Hyperparameter space definition.

Returns:

Updated hyperparameter space definition.

Return type:

List[Params]

hyperparameter_space(*args: Any, override: list[Params] | None = None, **kwargs: Any) list[Params][source]

The customized hyperparameter_space implementation. The hyperparameter space is built up of the hyperparameters of each pipeline steps (the preprocessors, and the final predictive step). CategoricalParams for choosing which preprocessor to use are also added (if at least one static_imputer, … are provided). Parameter names are customized to be able to differentiate pipeline stages (see format_hps_names).

Parameters:
*args : Any

Arguments to be passed on to the hyperparameter_space methods of the pipeline steps.

override : Optional[List[Params]], optional

Hyperparameter space override for the final predictive step of the pipeline. Defaults to None.

**kwargs : Any

Keyword arguments to be passed on to the hyperparameter_space methods of the pipeline steps.

Returns:

Returned hyperparameter space.

Return type:

List[Params]

sample_hyperparameters(*args: Any, override: list[Params] | None = None, **kwargs: Any) dict[str, Any][source]

The customized sample_hyperparameters implementation. Uses the customized hyperparameter_space.

Parameters:
*args : Any

Arguments to be passed on to the hyperparameter_space methods of the pipeline steps.

override : Optional[List[Params]], optional

Hyperparameter space override for the final predictive step of the pipeline. Defaults to None.

**kwargs : Any

Keyword arguments to be passed on to the hyperparameter_space methods of the pipeline steps.

Returns:

Sampled hyperparameters dictionary.

Return type:

Dict[str, Any]

pipeline_class_from_hps(hps: dict[str, Any]) tuple[type[PipelineBase], dict[str, dict]][source]

Return a pipeline class from the sampled hyperparameters hps.

Parameters:
hps : Dict[str, Any]

The sampled hyperparameters for the pipeline.

Returns:

(pipeline_cls, pipeline_params), the pipeline class and the params to initialize the pipeline with.

Return type:

Tuple[Type[PipelineBase], Dict[str, Dict]]

pipeline_from_hps(hps: dict[str, Any]) PipelineBase[source]

Return a pipeline instance from the sampled hyperparameters hps.

Parameters:
hps : Dict[str, Any]

The sampled hyperparameters for the pipeline.

Returns:

The pipeline.

Return type:

PipelineBase