gtime.feature_generation.PeriodicSeasonal¶
-
class
gtime.feature_generation.PeriodicSeasonal(period: Union[pandas._libs.tslibs.timedeltas.Timedelta, str] = '365 days', amplitude: float = 0.5, start_date: Union[pandas._libs.tslibs.timestamps.Timestamp, str, None] = None, length: Optional[int] = 50, index_period: Union[pandas.core.indexes.datetimes.DatetimeIndex, int, None] = None)¶ Create a sinusoid from a given date and with a given period and amplitude.
Parameters: - period : Union[pd.Timedelta, str], optional, default:
'365 days' The period of the generated time series.
- amplitude : float, optional, default:
0.5 The amplitude of the time series.
- start_date : Union[pd.Timestamp, str], optional, default:
None The date from which to start generating the feature. This is used only if X is not passed in the
transformmethod, otherwise the start date is inferred from it.- length : int, optional, default:
50 The length of the sinusoid. This is used only if X is not passed in the
transformmethod, otherwise the length is inferred from it.- index_period : Union[DatetimeIndex, int], optional, default:
None The period of the index of the output
DataFrame. This is used only if X is not passed in thetransformmethod, otherwise the index period is taken from it.
Examples
>>> import pandas as pd >>> from gtime.feature_generation import PeriodicSeasonal >>> X = pd.DataFrame(range(0, 10), index=pd.date_range(start='2019-04-18', end='2019-04-27', freq='d')) >>> periodic = PeriodicSeasonal() >>> periodic.fit_transform(X) 0__PeriodicSeasonal 2019-04-18 0.000000 2019-04-19 0.008607 2019-04-20 0.017211 2019-04-21 0.025810 2019-04-22 0.034401 2019-04-23 0.042982 2019-04-24 0.051551 2019-04-25 0.060104 2019-04-26 0.068639 2019-04-27 0.077154
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 sinusoid, with the given period,amplitudeandlength, starting from the selectedstart_date.-
__init__(self, period: Union[pandas._libs.tslibs.timedeltas.Timedelta, str] = '365 days', amplitude: float = 0.5, start_date: Union[pandas._libs.tslibs.timestamps.Timestamp, str, NoneType] = None, length: Union[int, NoneType] = 50, index_period: Union[pandas.core.indexes.datetimes.DatetimeIndex, int, NoneType] = None)¶ Initialize self. See help(type(self)) for accurate signature.
-
fit(self, X: pandas.core.frame.DataFrame, y=None) → 'PeriodicSeasonal'¶ Fit the estimator.
Parameters: - X : pd.DataFrame, shape (n_samples, n_features), required
Input data.
- y : None
There is no need of a target in a transformer, yet the pipeline API requires this parameter.
Returns: - self : PeriodicSeasonal
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 sinusoid, with the given
period,amplitudeandlength, starting from the selectedstart_date. Iftime_seriesis notNone, thestart_dateis replaced by the start date of the time series and the output sinusoid will have the same index astime_series.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. If is not passed, then thestart_dateandindex_periodmust have been passed in the constructor when the object was instantiated.
Returns: - periodic_feature : pd.DataFrame, shape (n_samples, 1)
The DataFrame containing the generated period feature.
Raises: - ValueError
Raised if
time_seriesis not passed and thestart_dateor theindex_periodare not present.
- time_series : pd.DataFrame, shape (n_samples, 1), optional, default:
- period : Union[pd.Timedelta, str], optional, default: