MODULE REFERENCE
scaler
anomx.data.processing.transformers.scalerScaler
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
| Parameter | Type | Default |
|---|---|---|
scaler | — | None |
name | — | 'Scaler' |
global_fit | bool | False |
n_jobs | int | 1 |
verbose | bool | False |
columns | str | list[str] | None | None |
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()andinverse_transform()methods. Default:sklearn.preprocessing.MinMaxScalerwithfeature_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
TimeSeriespassed to thefit()method should be used to fit a *single* set of parameters, or if a different set of parameters should be independently fitted to each providedTimeSeries. IfTrue, then aSequence[TimeSeries]is passed tots_fitand a single set of parameters is fitted using all providedTimeSeries. IfFalse, then eachTimeSeriesis individually passed tots_fit, and a different set of fitted parameters if yielded for each of these fitting operations. SeeFittableDataTransformerdocumentation 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 differentTimeSeries. Defaults to1(sequential). Setting the parameter to-1means 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
BaseDataTransformerdocumentation. 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| Parameter | Type | Default |
|---|---|---|
series | TimeSeries | required |
params | Mapping[str, Any] | required |
**kwargs | — | — |
Returns TimeSeries
ts_inverse_transformstaticmethod
ts_inverse_transform(series: TimeSeries, params: Mapping[str, Any], insample: TimeSeries | None = None, **kwargs) -> TimeSeries| Parameter | Type | Default |
|---|---|---|
series | TimeSeries | required |
params | Mapping[str, Any] | required |
insample | TimeSeries | None | None |
**kwargs | — | — |
Returns TimeSeries
ts_fitstaticmethod
ts_fit(series: TimeSeriesLike, params: Mapping[str, Any], *args, **kwargs) -> Any| Parameter | Type | Default |
|---|---|---|
series | TimeSeriesLike | required |
params | Mapping[str, Any] | required |
*args | — | — |
**kwargs | — | — |
Returns Any
Inherited members
fitFittableDataTransformertransformFittableDataTransformerfit_transformFittableDataTransformerset_verboseBaseDataTransformerset_n_jobsBaseDataTransformerapply_component_maskBaseDataTransformerunapply_component_maskBaseDataTransformerstack_samplesBaseDataTransformerunstack_samplesBaseDataTransformernameBaseDataTransformerinverse_transformInvertibleDataTransformer