FourierFeatures
FourierFeatures
- class FourierFeatures(sp_list: list[float], fourier_terms_list: list[int], freq: str | None = None, keep_original_columns: bool | None = False)[source]
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, setkeep_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]
- Parameters:
- sp_listList[float and/or str]
List of seasonal periods. Can be defined with the following options:
- float : Periodicity defined as number of timesteps since the beginning of the data seen in
fit. - string : Periodicity defined as a column name in X that contains the \(t/sp\) values.
- string : Periodicity defined as a pandas period alias: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#period-aliases
- 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()
- Attributes:
is_fittedWhether
fithas been called.
References
[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.
Examples
>>> 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)
Methods
check_is_fitted([method_name])Check if the estimator has been fitted.
clone()Obtain a clone of the object with same hyper-parameters and config.
clone_tags(estimator[, tag_names])Clone tags from another object as dynamic override.
create_test_instance([parameter_set])Construct an instance of the class, using first test parameter set.
create_test_instances_and_names([parameter_set])Create list of all test instances and a list of names for them.
fit(X[, y])Fit transformer to X, optionally to y.
fit_transform(X[, y])Fit to data, then transform it.
get_class_tag(tag_name[, tag_value_default])Get class tag value from class, with tag level inheritance from parents.
get_class_tags()Get class tags from class, with tag level inheritance from parent classes.
get_config()Get config flags for self.
get_fitted_params([deep])Get fitted parameters.
get_param_defaults()Get object's parameter defaults.
get_param_names([sort])Get object's parameter names.
get_params([deep])Get a dict of parameters values for this object.
get_tag(tag_name[, tag_value_default, ...])Get tag value from instance, with tag level inheritance and overrides.
get_tags()Get tags from instance, with tag level inheritance and overrides.
get_test_params([parameter_set])Return testing parameter settings for the estimator.
inverse_transform(X[, y])Inverse transform X and return an inverse transformed version.
is_composite()Check if the object is composed of other BaseObjects.
load_from_path(serial)Load object from file location.
load_from_serial(serial)Load object from serialized memory container.
reset()Reset the object to a clean post-init state.
save([path, serialization_format])Save serialized self to bytes-like object or to (.zip) file.
set_config(**config_dict)Set config flags to given values.
set_params(**params)Set the parameters of this object.
set_random_state([random_state, deep, ...])Set random_state pseudo-random seed parameters for self.
set_tags(**tag_dict)Set instance level tag overrides to given values.
transform(X[, y])Transform X and return a transformed version.
update(X[, y, update_params])Update transformer with X, optionally y.

