gtime.feature_extraction.MovingAverage

class gtime.feature_extraction.MovingAverage(window_size: int = 1)

For each row in time_series, compute the moving average of the previous window_size rows. If there are not enough rows, the value is Nan.

Parameters
window_sizeint, optional, default: 1

The number of previous points on which to compute the moving average.

Examples

>>> import pandas as pd
>>> from gtime.feature_extraction import MovingAverage
>>> ts = pd.DataFrame([0, 1, 2, 3, 4, 5])
>>> mv_avg = MovingAverage(window_size=2)
>>> mv_avg.fit_transform(ts)
   0__MovingAverage
0               NaN
1               0.5
2               1.5
3               2.5
4               3.5
5               4.5

Methods

fit(self, X[, y])

Fit the estimator.

fit_transform(self, X[, y])

Fit to data, then transform it.

get_feature_names(self)

Return feature names for output features.

get_params(self[, deep])

Get parameters for this estimator.

set_params(self, \*\*params)

Set the parameters of this estimator.

transform(self, time_series)

Compute the moving average, for every row of time_series, of the previous window_size elements.

__init__(self, window_size:int=1)

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

fit(self, X, y=None)

Fit the estimator.

Parameters
Xpd.DataFrame, shape (n_samples, n_features)

Input data.

yNone

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

Returns
selfobject

Returns self.

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
Xnumpy array of shape [n_samples, n_features]

Training set.

ynumpy array of shape [n_samples]

Target values.

**fit_paramsdict

Additional fit parameters.

Returns
X_newnumpy array of shape [n_samples, n_features_new]

Transformed array.

get_feature_names(self)

Return feature names for output features.

Returns
output_feature_namesndarray, shape (n_output_features,)

Array of feature names.

get_params(self, deep=True)

Get parameters for this estimator.

Parameters
deepbool, default=True

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.

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.

Parameters
**paramsdict

Estimator parameters.

Returns
selfobject

Estimator instance.

transform(self, time_series:pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame

Compute the moving average, for every row of time_series, of the previous window_size elements.

Parameters
time_seriespd.DataFrame, shape (n_samples, 1), required

The DataFrame on which to compute the rolling moving average

Returns
time_series_tpd.DataFrame, shape (n_samples, 1)

A DataFrame, with the same length as time_series, containing the rolling moving average for each element.