gtime.feature_generation.Constant¶
-
class
gtime.feature_generation.Constant(constant: int = 0, length: int = None)¶ Generate a
pd.DataFramewith one column, of the same length as the inputXand containing the valueconstantacross the whole column.Parameters: - constant : int, optional, default:
2 The value to use to generate the constant column of the
pd.DataFrame.- length : int, optional, default:
50 The length of the DataFrame to generate. This is used only if X is not passed in the
transformmethod, 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.DataFramewith one column with the same length astime_seriesand with the same index, containing a value equal toconstant.-
__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: - 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 : Constant
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: Union[pandas.core.frame.DataFrame, NoneType] = None) → pandas.core.frame.DataFrame¶ Generate a
pd.DataFramewith one column with the same length astime_seriesand with the same index, containing a value equal toconstant.Parameters: - time_series : pd.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_renamed : pd.DataFrame, shape (length, 1)
A constant series, with the same length of
Xand with the same index.
- time_series : pd.DataFrame, shape (n_samples, 1), optional, default:
- constant : int, optional, default: