gtime.feature_generation.Constant

class gtime.feature_generation.Constant(constant: int = 0, length: int = None)

Generate a pd.DataFrame with one column, of the same length as the input X and containing the value constant across the whole column.

Parameters
constantint, optional, default: 2

The value to use to generate the constant column of the pd.DataFrame.

lengthint, optional, default: 50

The length of the DataFrame to generate. This is used only if X is not passed in the transform method, otherwise the length is inferred from it.

Examples

>>> import pandas as pd
>>> from gtime.feature_generation import Constant
>>> X = pd.DataFrame(range(0, 5), index=pd.date_range(start='2019-04-18',  end='2019-04-22', freq='d'))
>>> constant = Constant(constant=3)
>>> constant.fit_transform(X)
            0__Constant
2019-04-18          3.0
2019-04-19          3.0
2019-04-20          3.0
2019-04-21          3.0
2019-04-22          3.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, NoneType]=None)

Generate a pd.DataFrame with one column with the same length as time_series and with the same index, containing a value equal to constant.

__init__(self, constant:int=0, length:int=None)

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

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

Fit the estimator.

Parameters
Xpd.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
selfConstant

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.

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 with one column with the same length as time_series and with the same index, containing a value equal to constant.

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

The input DataFrame. If passed, the output DataFrame is going to have the same index as time_series.

Returns
constant_series_renamedpd.DataFrame, shape (length, 1)

A constant series, with the same length of X and with the same index.