# giotto.time_series.Stationarizer¶

class giotto.time_series.Stationarizer(operation='return')

Methods for stationarizing time series data.

Time series may be stationarized to remove or reduce linear or exponential trends.

Parameters
operation'return' | 'log-return', default: 'return'

The type of stationarization operation to perform. It can have two values:

• 'return': This option transforms the time series $${X_t}_t$$ into the time series of relative returns, i.e. the ratio $$(X_t-X_{ t-1})/X_t$$.

• 'log-return': This option transforms the time series $${X_t}_t$$ into the time series of relative log-returns, i.e. $$\log(X_t/X_{ t-1})$$.

Examples

>>> import numpy as np
>>> from giotto.time_series import Stationarizer
>>> # Create a noisy signal
>>> signal = np.asarray([np.sin(x /40) + 5 + np.random.random()
>>>                      for x in range(0, 300)]).reshape(-1, 1)
>>> # Initialize the stationarizer
>>> stationarizer = Stationarizer(operation='return')
>>> # Fit and transform the signal
>>> signal_stationarized = stationarizer.fit_transform(signal)
>>> print(signal_stationarized.shape)
(299,)


Methods

 fit(self, X[, y]) Do nothing and return the estimator unchanged. fit_transform(self, X[, y]) Fit to data, then transform it. fit_transform_resample(self, X, y, …) Fit to data, then transform the input and resample the target. get_params(self[, deep]) Get parameters for this estimator. resample(self, y[, X]) Resample y. set_params(self, \*\*params) Set the parameters of this estimator. transform(self, X[, y]) Stationarize X by applying the procedure given by operation. transform_resample(self, X, y) Fit to data, then transform it.
__init__(self, operation='return')

Initialize self. See help(type(self)) for accurate signature.

fit(self, X, y=None)

Do nothing and return the estimator unchanged.

This method is there to implement the usual scikit-learn API and hence work in pipelines.

Parameters
Xndarray, shape (n_samples,) or (n_samples, …)

Input data.

yNone

Ignored.

Returns
selfobject
fit_transform(self, X, y=None, **fit_params)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters
Xndarray of shape (n_samples, …)

Input data.

yNone

There is no need for a target in a transformer, yet the pipeline API requires this parameter.

Returns
Xtnumpy array of shape (n_samples, …)

Transformed input.

fit_transform_resample(self, X, y, **fit_params)

Fit to data, then transform the input and resample the target. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X ans a resampled version of y.

Parameters
Xndarray of shape (n_samples, …)

Input data.

yndarray of shape (n_samples, )

Target data.

Returns
Xtndarray of shape (n_samples, …)

Transformed input.

yrndarray of shape (n_samples, …)

Resampled target.

get_params(self, deep=True)

Get parameters for this estimator.

Parameters
deepboolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsmapping of string to any

Parameter names mapped to their values.

resample(self, y, X=None)

Resample y.

Parameters
yndarray, shape (n_samples,)

Target.

XNone

There is no need for input data, yet the pipeline API requires this parameter.

Returns
yrndarray, shape (n_samples_new,)

Resampled target. n_samples_new = n_samples - 1.

set_params(self, **params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns
self
transform(self, X, y=None)

Stationarize X by applying the procedure given by operation.

Parameters
Xndarray, shape (n_samples,) or (n_samples, …)

Input data.

yNone

There is no need for a target, yet the pipeline API requires this parameter.

Returns
Xtndarray, shape (n_samples_new, …)

Stationarized array. n_samples_new = n_samples - 1.

transform_resample(self, X, y)

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters
Xndarray of shape (n_samples, …)

Input data.

yndarray of shape (n_samples, )

Target data.

Returns
Xtndarray of shape (n_samples, …)

Transformed input.