gtime.feature_extraction.Shift

class gtime.feature_extraction.Shift(shift: int = 1)

Perform a shift of a DataFrame of size equal to shift.

Parameters:
shift : int, optional, default: 1

How much to shift.

Notes

The shift parameter can also accept negative values. However, this should be used carefully, since if the resulting feature is used for training or testing it might generate a leak from the feature.

Examples

>>> import pandas as pd
>>> from gtime.feature_extraction import Shift
>>> ts = pd.DataFrame([0, 1, 2, 3, 4, 5])
>>> shift = Shift(shift=3)
>>> shift.fit_transform(ts)
   0__Shift
0       NaN
1       NaN
2       NaN
3       0.0
4       1.0
5       2.0

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) Create a shifted version of time_series.
__init__(self, shift: int = 1)

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

fit(self, X, y=None)

Fit the estimator.

Parameters:
X : pd.DataFrame, shape (n_samples, n_features)

Input data.

y : None

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

Returns:
self : object

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

Training set.

y : numpy array of shape [n_samples]

Target values.

**fit_params : dict

Additional fit parameters.

Returns:
X_new : numpy array of shape [n_samples, n_features_new]

Transformed array.

get_feature_names(self)

Return feature names for output features.

Returns:
output_feature_names : ndarray, shape (n_output_features,)

Array of feature names.

get_params(self, deep=True)

Get parameters for this estimator.

Parameters:
deep : bool, default=True

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

Returns:
params : mapping 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:
**params : dict

Estimator parameters.

Returns:
self : object

Estimator instance.

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

Create a shifted version of time_series.

Parameters:
time_series : pd.DataFrame, shape (n_samples, 1), required

The DataFrame to shift.

Returns:
time_series_t : pd.DataFrame, shape (n_samples, 1)

The shifted version of the original time_series.