Zurück zu den Modellen
Transformer

FourierFeatures

Fourier Features for time series seasonality.

Fourier Series terms can be used as explanatory variables for the cases of multiple seasonal periods and or complex / long seasonal periods [1], [2]. For every seasonal period, \(sp\) and fourier term \(k\) pair there are 2 fourier terms sin_sp_k and cos_sp_k:

  • sin_sp_k = \(sin(\frac{2 \pi k t}{sp})\)

  • cos_sp_k = \(cos(\frac{2 \pi k t}{sp})\)

Where \(t\) is the elapsed time since the beginning of the seasonal period and \(sp\) the total time of the seasonal period.

The transformed output is a series that contains all requested Fourier terms.

Warning: the output will contain only the Fourier terms under default settings, and discard the original columns of the input data, to avoid multiplication of the original data in a pipeline or FeatureUnion. To keep the original columns, set keep_original_columns=True.

Names of the columns are generated as follows: additional columns with the naming convention stated above (sin_sp_k and cos_sp_k). The numbers of Fourier terms \(K\) in the fourier_terms_list determines the number of Fourier terms that will be used for each seasonal period, i.e., Fourier terms \(k = 1\dots K\) (integers), cos and sine, will be generated for the seasonality \(sp\) at the same list index. For example, consider sp_list = [12, “Y”] and fourier_terms_list = [2, 1]. This says that we compute 2 (2 cos, 2 sine) Fourier terms for seasonality 12 periods, and 1 Fourier term (1 cos and 1 sine) for seasonality 1 year. The transformed series will then have columns with the following names: “cos_12_1”, “sin_12_1”, “cos_12_2”, “sin_12_2”, “cos_Y_1”, “sin_Y_1”

The implementation is based on the fourier function from the R forecast package [3]

Schnellstart

python
from sktime.transformations.fourier import FourierFeatures

estimator = FourierFeatures(sp_list: list [float ], fourier_terms_list: list [int ], freq: str | None=None, keep_original_columns: bool | None=False)

Parameter(4)

sp_listList[float and/or str]

List of seasonal periods. Can be defined with the following options:

fourier_terms_listList[int]

List of number of fourier terms (\(K\)) per corresponding (\(sp\)); each \(K\) matches to one \(sp\) of the sp_list. For example, if sp_list = [7, “Y”] and fourier_terms_list = [3, 9], the seasonality of 7 timesteps will have 3 sin_sp_k and 3 cos_sp_k fourier terms and the yearly seasonality “Y” will have 9 sin_sp_k and 9 cos_sp_k fourier terms.

freqstr, optional, default = None

Only used when X has a pd.DatetimeIndex without a specified frequency. Specifies the frequency of the index of your data. The string should match a pandas offset alias:

https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases

keep_original_columnsboolean, optional, default=False

Keep original columns in X passed to .transform()

Beispiele

>>> from sktime.transformations.fourier import FourierFeatures
>>> from sktime.datasets import load_airline
>>> y = load_airline ()
>>> transformer = FourierFeatures (sp_list = [12, "Y" ], fourier_terms_list = [4, 1 ])
>>> y_hat = transformer. fit_transform (y)

Referenzen

[1]

Hyndsight - Forecasting with long seasonal periods: https://robjhyndman.com/hyndsight/longseasonality/

[2]

Hyndman, R.J., & Athanasopoulos, G. (2021) Forecasting: principles and practice, 3rd edition, OTexts: Melbourne, Australia. OTexts.com/fpp3. Accessed on August 14th 2022.