gluonts.time_feature package#
- class gluonts.time_feature.Constant(*, value: float = 0.0)[source]#
Bases:
pydantic.v1.main.BaseModel
Constant time feature using a predefined value.
- value: float#
- class gluonts.time_feature.SpecialDateFeatureSet(feature_names: typing.List[str], kernel_function: typing.Callable[[int], int] = <function indicator>)[source]#
Bases:
object
Implements calculation of holiday features. The SpecialDateFeatureSet is applied on a pandas Series with Datetimeindex and returns a 2D array of the shape (len(dates), num_features), where num_features are the number of holidays.
Note that for lower than daily granularity the distance to the holiday is still computed on a per-day basis.
Example use:
>>> from gluonts.time_feature.holiday import ( ... squared_exponential_kernel, ... SpecialDateFeatureSet, ... CHRISTMAS_DAY, ... CHRISTMAS_EVE ... ) >>> import pandas as pd >>> sfs = SpecialDateFeatureSet([CHRISTMAS_EVE, CHRISTMAS_DAY]) >>> date_indices = pd.date_range( ... start="2016-12-24", ... end="2016-12-31", ... freq='D' ... ) >>> sfs(date_indices) array([[1., 0., 0., 0., 0., 0., 0., 0.], [0., 1., 0., 0., 0., 0., 0., 0.]])
Example use for using a squared exponential kernel:
>>> kernel = squared_exponential_kernel(alpha=1.0) >>> sfs = SpecialDateFeatureSet([CHRISTMAS_EVE, CHRISTMAS_DAY], kernel) >>> sfs(date_indices) array([[1.00000000e+00, 3.67879441e-01, 1.83156389e-02, 1.23409804e-04, 1.12535175e-07, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [3.67879441e-01, 1.00000000e+00, 3.67879441e-01, 1.83156389e-02, 1.23409804e-04, 1.12535175e-07, 0.00000000e+00, 0.00000000e+00]])
- gluonts.time_feature.day_of_month(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Day of month encoded as value between [-0.5, 0.5]
- gluonts.time_feature.day_of_month_index(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Day of month encoded as zero-based index, between 0 and 11.
- gluonts.time_feature.day_of_week(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Day of week encoded as value between [-0.5, 0.5]
- gluonts.time_feature.day_of_week_index(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Day of week encoded as zero-based index, between 0 and 6.
- gluonts.time_feature.day_of_year(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Day of year encoded as value between [-0.5, 0.5]
- gluonts.time_feature.day_of_year_index(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Day of year encoded as zero-based index, between 0 and 365.
- gluonts.time_feature.get_lags_for_frequency(freq_str: str, lag_ub: int = 1200, num_lags: Optional[int] = None, num_default_lags: int = 7) List[int] [source]#
Generates a list of lags that that are appropriate for the given frequency string.
By default all frequencies have the following lags: [1, 2, 3, 4, 5, 6, 7]. Remaining lags correspond to the same season (+/- delta) in previous k cycles. Here delta and k are chosen according to the existing code.
- Parameters
freq_str – Frequency string of the form [multiple][granularity] such as “12H”, “5min”, “1D” etc.
lag_ub – The maximum value for a lag.
num_lags – Maximum number of lags; by default all generated lags are returned.
num_default_lags – The number of default lags; by default it is 7.
- gluonts.time_feature.get_seasonality(freq: str, seasonalities={'B': 5, 'D': 1, 'H': 24, 'M': 12, 'ME': 12, 'Q': 4, 'QE': 4, 'S': 3600, 'T': 1440, 'W': 1, 'h': 24, 'min': 1440, 's': 3600}) int [source]#
Return the seasonality of a given frequency:
>>> get_seasonality("2h") 12
- gluonts.time_feature.hour_of_day(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Hour of day encoded as value between [-0.5, 0.5]
- gluonts.time_feature.hour_of_day_index(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Hour of day encoded as zero-based index, between 0 and 23.
- gluonts.time_feature.minute_of_hour(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Minute of hour encoded as value between [-0.5, 0.5]
- gluonts.time_feature.minute_of_hour_index(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Minute of hour encoded as zero-based index, between 0 and 59.
- gluonts.time_feature.month_of_year(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Month of year encoded as value between [-0.5, 0.5]
- gluonts.time_feature.month_of_year_index(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Month of year encoded as zero-based index, between 0 and 11.
- gluonts.time_feature.second_of_minute(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Second of minute encoded as value between [-0.5, 0.5]
- gluonts.time_feature.second_of_minute_index(index: pandas.core.indexes.period.PeriodIndex) numpy.ndarray [source]#
Second of minute encoded as zero-based index, between 0 and 59.
- gluonts.time_feature.time_features_from_frequency_str(freq_str: str) List[Callable[[pandas.core.indexes.period.PeriodIndex], numpy.ndarray]] [source]#
Returns a list of time features that will be appropriate for the given frequency string.
- Parameters
freq_str – Frequency string of the form [multiple][granularity] such as “12H”, “5min”, “1D” etc.