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 previouswindow_sizerows. If there are not enough rows, the value isNan.Parameters: - custom_feature_function : Callable, required.
The function to use to generate a
pd.DataFramecontaining the feature.- window_size : int, optional, default:
1 The number of previous points on which to compute the custom function.
- raw : bool, optional, default:
True False: passes each row or column as a Series to the function.TrueorNone: 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.fit_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_series : 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¶ - For every row of
time_series, compute the moving custom function of the - previous
window_sizeelements.
Parameters: - time_series : pd.DataFrame, shape (n_samples, 1), required
The DataFrame on which to compute the rolling moving custom function.
Returns: - time_series_t : pd.DataFrame, shape (n_samples, 1)
A DataFrame, with the same length as
time_series, containing the rolling moving custom function for each element.
- For every row of