MODULE REFERENCE

boxcox

anomx.data.processing.transformers.boxcox

Box-Cox Transformer

BoxCox

BoxCox(name: str = 'BoxCox', lmbda: float | Sequence[float] | Sequence[Sequence[float]] | None = None, optim_method: Literal['mle', 'pearsonr'] = 'mle', global_fit: bool = False, n_jobs: int = 1, verbose: bool = False, columns: str | list[str] | None = None)

Bases: FittableDataTransformer, InvertibleDataTransformer

Signature parameters
ParameterTypeDefault
namestr'BoxCox'
lmbdafloat | Sequence[float] | Sequence[Sequence[float]] | NoneNone
optim_methodLiteral['mle', 'pearsonr']'mle'
global_fitboolFalse
n_jobsint1
verboseboolFalse
columnsstr | list[str] | NoneNone

Box-Cox data transformer.

See [1]_ for more information about Box-Cox transforms.

The transformation is applied independently for each dimension (component) of the time series. For stochastic series, it is done jointly over all samples, 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

name

A specific name for the transformer

lmbda

The parameter \lambda of the Box-Cox transform. If a single float is given, the same \lambda value will be used for all dimensions of the series, for all the series. If a sequence is given, there is one value per component in the series. If a sequence of sequence is given, there is one value per component for all series. If None given, will automatically find an optimal value of \lambda (for each dimension of the time series, for each time series) using scipy.stats.boxcox_normmax with method=optim_method.

optim_method

Specifies which method to use to find an optimal value for the lmbda parameter. Either 'mle' or 'pearsonr'. Ignored if lmbda is not None.

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, 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

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.

Examples

>>> from anomx.data.timeseries import TimeSeries
>>> from anomx.data.processing.transformers import BoxCox
>>> series = TimeSeries.from_values([112., 118., 132., 129., 121., 135.])
>>> transformer = BoxCox(lmbda=0.2)
>>> series_transformed = transformer.fit_transform(series)
>>> print(series_transformed.values()[:5])
[[7.84735157]
 [7.98214351]
 [8.2765364 ]
 [8.21563229]
 [8.04749318]]

References

.. [1] https://otexts.com/fpp2/transformations.html#mathematical-transformations

Members

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

Returns Sequence[float] | pd.Series

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