gtime.feature_extraction.MovingCustomFunction

class gtime.feature_extraction.MovingCustomFunction(custom_feature_function: Callable, window_size: int = 1, raw: bool = True)

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

Parameters
custom_feature_functionCallable, required.

The function to use to generate a pd.DataFrame containing the feature.

window_sizeint, optional, default: 1

The number of previous points on which to compute the custom function.

rawbool, optional, default: True
  • False : passes each row or column as a Series to the function.

  • True or None : the passed function will receive ndarray objects

instead.

If you are just applying a NumPy reduction function this will achieve much better performance. Credits: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.window.Rolling.apply.html

Examples

>>> import pandas as pd
>>> import numpy as np
>>> from gtime.feature_extraction import MovingCustomFunction
>>> ts = pd.DataFrame([0, 1, 2, 3, 4, 5])
>>> mv_custom = MovingCustomFunction(np.max, window_size=2)
>>> mv_custom.transform(ts)
   0__MovingCustomFunction
0                      NaN
1                      1.0
2                      2.0
3                      3.0
4                      4.0
5                      5.0

Methods

fit(self, time_series[, 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)

For every row of time_series, compute the moving custom function of the

__init__(self, custom_feature_function:Callable, window_size:int=1, raw:bool=True)

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

fit(self, time_series:pandas.core.frame.DataFrame, y=None)

Fit the estimator.

Parameters
time_seriespd.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
For every row of time_series, compute the moving custom function of the

previous window_size elements.

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

The DataFrame on which to compute the rolling moving custom function.

Returns
time_series_tpd.DataFrame, shape (n_samples, 1)

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