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 previouswindow_sizerows. If there are not enough rows, the value isNan.Parameters: - window_size : int, 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 previouswindow_sizeelements.-
__init__(self, window_size: 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¶ Compute the moving average, for every row of
time_series, of the previouswindow_sizeelements.Parameters: - time_series : pd.DataFrame, shape (n_samples, 1), required
The DataFrame on which to compute the rolling moving average
Returns: - time_series_t : pd.DataFrame, shape (n_samples, 1)
A DataFrame, with the same length as
time_series, containing the rolling moving average for each element.
- window_size : int, optional, default: