MODULE REFERENCE

scaler

anomx.data.processing.transformers.scaler

Scaler

Scaler

Scaler(scaler = None, name = 'Scaler', global_fit: bool = False, n_jobs: int = 1, verbose: bool = False, columns: str | list[str] | None = None)

Bases: FittableDataTransformer, InvertibleDataTransformer

Signature parameters
ParameterTypeDefault
scaler—None
name—'Scaler'
global_fitboolFalse
n_jobsint1
verboseboolFalse
columnsstr | list[str] | NoneNone

Generic wrapper class for using scalers on time series.

The underlying scaler has to implement the fit(), transform() and inverse_transform() methods (typically from scikit-learn).

When the scaler is applied on multivariate series, the scaling is done per-component. When the series are stochastic, the scaling is done across all samples (for each given component). The transformation is applied independently for each dimension (component) of the time series, effectively merging all samples of a component in order to compute the transform.

Notes

The scaler will not scale the series' static covariates. This has to be done either before constructing the series, or later on by extracting the covariates, transforming the values and then reapplying them to the series. For this, see TimeSeries properties TimeSeries.static_covariates and method TimeSeries.with_static_covariates()

Parameters

scaler

The scaler to transform the data with. It must provide fit(), transform() and inverse_transform() methods. Default: sklearn.preprocessing.MinMaxScaler with feature_range=(0, 1); this will scale all the values of a time series between 0 and 1.

name

A specific name for the scaler

global_fit

Optionally, whether all TimeSeries passed to the fit() method should be used to fit a *single* set of parameters, or if a different set of parameters should be independently fitted to each provided TimeSeries. If True, then a Sequence[TimeSeries] is passed to ts_fit and a single set of parameters is fitted using all provided TimeSeries. If False, then each TimeSeries is individually passed to ts_fit, and a different set of fitted parameters if yielded for each of these fitting operations. See FittableDataTransformer documentation for further details.

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.

verbose

Optionally, whether to print operations progress

columns

Optionally, a string or list of strings specifying the names of the components (columns) to transform. If specified, only these components will be transformed, and the remaining components will be kept untouched. For more information refer to the BaseDataTransformer documentation. In case the transformer is applied on multiple TimeSeries, it is expected that all series have the same column order.

Notes

In case the anomx.data.processing.transformers.Scaler is applied to multiple TimeSeries objects, a deep-copy of the chosen scaler will be instantiated, fitted, and stored, for each TimeSeries.

Examples

>>> from sklearn.preprocessing import MinMaxScaler
>>> from anomx.data.timeseries import TimeSeries
>>> from anomx.data.processing.transformers import Scaler
>>> series = TimeSeries.from_values([-2, 0, 2])
>>> scaler = MinMaxScaler(feature_range=(-1, 1))
>>> transformer = Scaler(scaler)
>>> series_transformed = transformer.fit_transform(series)
>>> print(series_transformed.values())
[[-1.]
 [ 0.]
 [ 1.]]

Members

ts_transformstaticmethod
ts_transform(series: TimeSeries, params: Mapping[str, Any], **kwargs) -> TimeSeries
Signature parameters
ParameterTypeDefault
seriesTimeSeriesrequired
paramsMapping[str, Any]required
**kwargs——

Returns TimeSeries

ts_inverse_transformstaticmethod
ts_inverse_transform(series: TimeSeries, params: Mapping[str, Any], insample: TimeSeries | None = None, **kwargs) -> TimeSeries
Signature parameters
ParameterTypeDefault
seriesTimeSeriesrequired
paramsMapping[str, Any]required
insampleTimeSeries | NoneNone
**kwargs——

Returns TimeSeries

ts_fitstaticmethod
ts_fit(series: TimeSeriesLike, params: Mapping[str, Any], *args, **kwargs) -> Any
Signature parameters
ParameterTypeDefault
seriesTimeSeriesLikerequired
paramsMapping[str, Any]required
*args——
**kwargs——

Returns Any