tempor.methods.pipeline package

Submodules

Module contents

A package directory for the pipeline functionality.

class tempor.methods.pipeline.PipelineBase(plugin_params: dict[str, dict] | None = None, **kwargs: Any)[source]

Bases: object

Instantiate the pipeline, (optionally) providing initialization parameters for constituent step plugins.

Note

The implementations of the methods on this class (fit, sample_hyperparameters, etc.) are auto-generated by the PipelineMeta metaclass.

Parameters:
plugin_params : Optional[Dict[str, Dict]], optional

A dictionary like {"plugin_1_name": {"init_param_1": value, ...}, ...}. Defaults to None.

**kwargs : Any

Any keyword arguments.

stages : list

A list of method plugin instances corresponding to each step in the pipeline.

plugin_types : list[type]

A list of types denoting the class of each step in the pipeline.

static pipeline_seq(*args: Any) str[source]

Get a string representation of the pipeline, stating each stage plugin, e.g. like: 'preprocessing.imputation.temporal.bfill->...->prediction.one_off.classification.nn_classifier'

Parameters:
*args : Any

Any positional arguments.

Returns:

String representation of the pipeline.

Return type:

str

static hyperparameter_space(*args: Any, **kwargs: Any) dict[str, list[Params]][source]

The pipeline version of the estimator static method of the same name. All the hyperparameters of the different stages will be returned.

Parameters:
*args : Any

Any positional arguments.

**kwargs : Any

Any keyword arguments.

Returns:

A dictionary with each stage plugin names as keys and corresponding hyperparameter space (List[Params]) as values.

Return type:

Dict[str, List[Params]]

static hyperparameter_space_for_step(name: str, *args: Any, **kwargs: Any) list[Params][source]

Return the hyperparameter space (List[Params]) for the step of the pipeline as specified by name.

Parameters:
name : str

Name of the pipeline step (i.e. the name of the underlying plugin).

*args : Any

Any positional arguments.

**kwargs : Any

Any keyword arguments.

Returns:

the hyperparameter space for the step of the pipeline.

Return type:

List[Params]

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

The pipeline version of the estimator method of the same name. Returns a hyperparameter sample.

Parameters:
*args : Any

Any positional arguments.

override : Optional[List[Params]], optional

A list of hyperparameter samples to override the default sampling. Defaults to None.

**kwargs : Any

Any keyword arguments.

Returns:

a dictionary with hyperparameter names as keys and corresponding hyperparameter samples as values.

Return type:

Dict[str, Any]

fit(data: BaseDataset, *args: Any, **kwargs: Any) Self[source]

The pipeline version of the estimator fit method.

By analogy to sklearn, under the hood, fit_transform will be called on all the pipeline steps except for the last one (the transformer steps of the pipeline), and fit will be called on the last step (the predictive step of the pipeline).

Parameters:
data : dataset.BaseDataset

Input dataset.

*args : Any

Any positional arguments.

**kwargs : Any

Any keyword arguments.

Returns:

Returns the fitted pipeline itself.

Return type:

Self

predict(data: PredictiveDataset, *args: Any, **kwargs: Any) Any[source]

The pipeline version of the estimator predict method. Applicable if the final step of the pipeline has a predict method implemented.

Parameters:
data : dataset.PredictiveDataset

Input dataset.

*args : Any

Any positional arguments.

**kwargs : Any

Any keyword arguments.

Returns:

the same return type as the final step of the pipeline.

Return type:

Any

predict_proba(data: PredictiveDataset, *args: Any, **kwargs: Any) Any[source]

The pipeline version of the estimator predict_proba method. Applicable if the final step of the pipeline has a predict_proba method implemented.

Parameters:
data : dataset.PredictiveDataset

Input dataset.

*args : Any

Any positional arguments.

**kwargs : Any

Any keyword arguments.

Returns:

the same return type as the final step of the pipeline.

Return type:

Any

predict_counterfactuals(data: PredictiveDataset, *args: Any, **kwargs: Any) Any[source]

The pipeline version of the estimator predict_counterfactuals method. Applicable if the final step of the pipeline has a predict_counterfactuals method implemented.

Parameters:
data : dataset.PredictiveDataset

Input dataset.

*args : Any

Any positional arguments.

**kwargs : Any

Any keyword arguments.

Returns:

the same return type as the final step of the pipeline.

Return type:

Any

property predictor_category : str

Return the category of the final step of the pipeline.

Returns:

The category of the final step of the pipeline.

Return type:

str

property params : dict[str, DictConfig]

Return a dictionary with the parameters (.params) of each step of the pipeline (keyed by the stage name).

Returns:

The requisite dictionary.

Return type:

Dict[str, omegaconf.DictConfig]

tempor.methods.pipeline.prepend_base(base: type, bases: list[type]) list[type][source]

Prepend a base class to a list of base classes, if it is not already present.

Parameters:
base : Type

Base class to prepend.

bases : List[Type]

List of base classes.

Returns:

The list of base classes, with the base class prepended.

Return type:

List[Type]

tempor.methods.pipeline.raise_not_implemented(*args: Any, **kwargs: Any) NoReturn[source]

Raise a NotImplementedError if a method like _fit/predict/... is not implemented.

Parameters:
*args : Any

Any positional arguments.

**kwargs : Any

Any keyword arguments.

Raises:

NotImplementedError – The requisite error.

Returns:

Does not return, raises error.

Return type:

NoReturn

class tempor.methods.pipeline.PipelineMeta(_PipelineMeta__name: str, _PipelineMeta__bases: tuple[type, ...], _PipelineMeta__namespace: dict[str, Any], plugins: tuple[type, ...] = (), **kwds: Any)[source]

Bases: ABCMeta

The metaclass __new__ method for defining the pipeline classes.

Parameters:
cls : Any

The class.

__name : str

The name of the class.

__bases : Tuple[type, ...]

The list of base classes.

__namespace : Dict[str, Any]

The namespace of the class.

plugins : Tuple[Type, ...], optional

The list of pipeline plugins. Defaults to tuple().

**kwds : Any

Any keyword arguments to be passed to super().__new__.

Returns:

The class.

Return type:

Any

static parse_bases(bases: tuple[type, ...], plugins: tuple[type, ...]) tuple[type, ...][source]

Append the applicable base classes (those that are the last pipeline step is a subclass of) to bases.

Parameters:
bases : Tuple[type, ...]

List of base classes.

plugins : Tuple[Type, ...]

The list of the pipeline’s plugins.

Returns:

The appended list of base classes.

Return type:

Tuple[type, …]

tempor.methods.pipeline.pipeline_classes(names: list[str]) tuple[type, ...][source]

Return a list sequence of method plugin classes based on a sequence of fully-qualified names provided.

Parameters:
names : List[str]

A sequence of fully-qualified names of method plugins, corresponding to pipeline steps.

Returns:

The corresponding sequence of method plugin classes.

Return type:

Tuple[Type, …]

tempor.methods.pipeline.pipeline(plugins_str: list[str]) type[PipelineBase][source]

Use this method to create pipelines.

Generates a pipeline (PipelineBase) class with an implementation of the necessary methods (fit, sample_hyperparameters etc.), based on a sequence of steps defined by plugins_str.

All but the last steps must be data transformer plugins, and the last step must be a predictive method plugin.

This method will return a pipeline class (Type[PipelineBase]), which should be instantiated. At time of instantiation, __init__ input parameters for each step’s method plugin can be provided. See PipelineBase for details.

Parameters:
plugins_str : List[str]

A sequence of method plugins’ fully-qualified names (e.g. "prediction.one_off.classification.nn_classifier").

Returns:

The pipeline class (not instance) is returned.

Return type:

Type[PipelineBase]