gtime.feature_extraction.CustomFeature

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

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

Parameters
funcCallable, required.

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

kwargsobject, 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_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.

inverse_transform(self, X)

Transform X using the inverse function.

Parameters
Xarray-like, shape (n_samples, n_features)

Input array.

Returns
X_outarray-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
**paramsdict

Estimator parameters.

Returns
selfobject

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_seriespd.DataFrame, shape (n_samples, 1), optional, default: None

The DataFrame on which to apply the the custom function.

Returns
X_t_dfpd.DataFrame, shape (length, 1)

A DataFrame containing the generated feature.