gtime.feature_extraction.CustomFeature

class gtime.feature_extraction.CustomFeature(func: Callable, **kwargs)

Constructs a transformer from an arbitrary callable. This transformer is a wrapper of sklearn.preprocessing.FunctionTransformer but returns a pd.Dataframe.

Parameters:
func : Callable, required.

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

kwargs : object, optional.

Optional arguments to pass to the transform method.

Examples

>>> import pandas as pd
>>> from gtime.feature_extraction import CustomFeature
>>> def custom_function(X, power):
...     return X**power
>>> X = pd.DataFrame([0, 1, 2, 3, 4, 5])
>>> custom_feature = CustomFeature(custom_function, power=3)
>>> custom_feature.fit_transform(X)
   0__CustomFeature
0                 0
1                 1
2                 8
3                27
4                64
5               125

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.
inverse_transform(self, X) Transform X using the inverse function.
set_params(self, \*\*params) Set the parameters of this estimator.
transform(self, time_series, NoneType] = None) Generate a pd.DataFrame, given time_series as input to the func, as well as other optional arguments.
__init__(self, func: Callable, **kwargs: object)

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

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

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.

inverse_transform(self, X)

Transform X using the inverse function.

Parameters:
X : array-like, shape (n_samples, n_features)

Input array.

Returns:
X_out : array-like, shape (n_samples, n_features)

Transformed input.

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: Union[pandas.core.frame.DataFrame, NoneType] = None) → pandas.core.frame.DataFrame

Generate a pd.DataFrame, given time_series as input to the func, as well as other optional arguments.

Parameters:
time_series : pd.DataFrame, shape (n_samples, 1), optional, default: None

The DataFrame on which to apply the the custom function.

Returns:
X_t_df : pd.DataFrame, shape (length, 1)

A DataFrame containing the generated feature.