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
periodUnion[pd.Timedelta, str], optional, default: '365 days'

The period of the generated time series.

amplitudefloat, optional, default: 0.5

The amplitude of the time series.

start_dateUnion[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 transform method, otherwise the start date is inferred from it.

lengthint, optional, default: 50

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

index_periodUnion[DatetimeIndex, int], optional, default: None

The period of the index of the output DataFrame. This is used only if X is not passed in the transform method, 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, amplitude and length, starting from the selected start_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
Xpd.DataFrame, shape (n_samples, n_features), required

Input data.

yNone

There is no need of a target in a transformer, yet the pipeline API requires this parameter.

Returns
selfPeriodicSeasonal

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 sinusoid, with the given period, amplitude and length, starting from the selected start_date. If time_series is not None, the start_date is replaced by the start date of the time series and the output sinusoid will have the same index as time_series.

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. If is not passed, then the start_date and index_period must have been passed in the constructor when the object was instantiated.

Returns
periodic_featurepd.DataFrame, shape (n_samples, 1)

The DataFrame containing the generated period feature.

Raises
ValueError

Raised if time_series is not passed and the start_date or the index_period are not present.