MODULE REFERENCE

pipeline

anomx.data.processing.pipeline

Pipeline

Pipeline

Pipeline(transformers: Sequence[BaseDataTransformer], copy: bool = False, verbose: bool | None = None, n_jobs: int | None = None)
Signature parameters
ParameterTypeDefault
transformersSequence[BaseDataTransformer]required
copyboolFalse
verbosebool | NoneNone
n_jobsint | NoneNone

Pipeline to combine multiple data transformers, chaining them together.

Parameters

transformers

Sequence of data transformers.

copy

If set makes a (deep) copy of each data transformer before adding them to the pipeline

n_jobs

The number of jobs to run in parallel. Parallel jobs are created only when a Sequence[TimeSeries] is passed as input to a method, parallelising operations regarding different TimeSeries. Defaults to 1 (sequential). Setting the parameter to -1 means using all the available processors. Note: for a small amount of data, the parallelisation overhead could end up increasing the total required amount of time. Note: this parameter will overwrite the value set in each single transformer. Leave this parameter set to None for keeping the original transformers' configurations.

verbose

Whether to print progress of the operations. Note: this parameter will overwrite the value set in each single transformer. Leave this parameter set to None for keeping the transformers configurations.

Examples

>>> import numpy as np
>>> from anomx.data.timeseries import TimeSeries
>>> from anomx.data.processing.transformers import Scaler, MissingValuesFiller
>>> from anomx.data.processing.pipeline import Pipeline
>>> values = np.arange(start=0, stop=10, step=2.)
>>> values[1:3] = np.nan
>>> series = TimeSeries.from_values(values)
>>> pipeline = Pipeline([MissingValuesFiller(), Scaler()])
>>> series_transformed = pipeline.fit_transform(series)
>>> print(series_transformed.values())
[[0.  ]
 [0.25]
 [0.5 ]
 [0.75]
 [1.  ]]

Members

fitmethod
fit(data: TimeSeriesLike)

Fit all fittable transformers in pipeline.

Parameters

data

(Sequence of) TimeSeries to fit on.

Signature parameters
ParameterTypeDefault
dataTimeSeriesLikerequired
fit_transformmethod
fit_transform(data: TimeSeriesLike) -> TimeSeriesLike

For each data transformer in the pipeline, first fit the data if transformer is fittable then transform data using fitted transformer. The transformed data is then passed to next transformer.

Parameters

data

(Sequence of) TimeSeries to fit and transform on.

Returns

TimeSeriesLike

Transformed data.

Signature parameters
ParameterTypeDefault
dataTimeSeriesLikerequired

Returns TimeSeriesLike

transformmethod
transform(data: TimeSeriesLike, series_idx: int | Sequence[int] | None = None) -> TimeSeriesLike

For each data transformer in pipeline transform data. Then transformed data is passed to next transformer.

Parameters

data

(Sequence of) TimeSeries to be transformed.

series_idx

Optionally, the index(es) of each series corresponding to their positions within the series used to fit the transformer (to retrieve the appropriate transformer parameters).

Returns

TimeSeriesLike

Transformed data.

Signature parameters
ParameterTypeDefault
dataTimeSeriesLikerequired
series_idxint | Sequence[int] | NoneNone

Returns TimeSeriesLike

inverse_transformmethod
inverse_transform(data: TimeSeriesLike | Sequence[Sequence[TimeSeries]], partial: bool = False, series_idx: int | Sequence[int] | None = None, insample: TimeSeriesLike | None = None) -> TimeSeriesLike | Sequence[Sequence[TimeSeries]]

For each data transformer in the pipeline, inverse-transform data. Then inverse transformed data is passed to the next transformer. Transformers are traversed in reverse order. Raises value error if not all transformers are invertible and partial is set to False. Set partial to True for inverting only the InvertibleDataTransformer in the pipeline.

Parameters

data

(Sequence of) TimeSeries to inverse-transform.

partial

If set to True, the inverse transformation is applied even if the pipeline is not fully invertible, calling inverse_transform() only on transformers of type InvertibleDataTransformer.

series_idx

Optionally, the index(es) of each series corresponding to their positions within the series used to fit the transformer (to retrieve the appropriate transformer parameters).

insample

Optionally, the transformed historic (insample) part of data. This can be used when data is only a tail (for example a forecast) and inverse transforming requires information from earlier times (for example the anomx.data.processing.transformers.diff.Diff transformer). Each insample series must start before the data start time and extend at least until one step before the start time of the data. If data is a Sequence[Sequence[TimeSeries]], then insample should be a Sequence[TimeSeries] with the same length. Otherwise, it should have the same type as data. Only used by transformers that require information from earlier times.

Returns

TimeSeriesLike | Sequence[Sequence[TimeSeries]]

Inverse-transformed data; same structure as data.

Signature parameters
ParameterTypeDefault
dataTimeSeriesLike | Sequence[Sequence[TimeSeries]]required
partialboolFalse
series_idxint | Sequence[int] | NoneNone
insampleTimeSeriesLike | NoneNone

Returns TimeSeriesLike | Sequence[Sequence[TimeSeries]]

invertibleproperty
invertible: bool

Returns whether the pipeline is invertible or not. A pipeline is invertible if all transformers in the pipeline are themselves invertible.

Returns

bool

True if the pipeline is invertible, False otherwise

Returns bool

fittableproperty
fittable: bool

Returns whether the pipeline is fittable or not. A pipeline is fittable if at least one of the transformers in the pipeline is fittable.

Returns

bool

True if the pipeline is fittable, False otherwise

Returns bool