pmdarima.preprocessing
.FourierFeaturizer
- class pmdarima.preprocessing.FourierFeaturizer(m, k=None, prefix=None)[source][source]
Fourier terms for modeling seasonality
This transformer creates an exogenous matrix containing terms from a Fourier series, up to order
k
. It is based onR::forecast code
[1]. In practice, it permits us to fit a seasonal time series without seasonal order (i.e.,seasonal=False
) by supplying decomposed seasonal Fourier terms as an exogenous array.The advantages of this technique, per Hyndman [2]:
It allows any length seasonality
The seasonal pattern is smooth for small values of K (but more wiggly seasonality can be handled by increasing K)
The short-term dynamics are easily handled with a simple ARMA error
The disadvantage is that the seasonal periodicity of the time series is assumed to be fixed.
Functionally, this is a featurizer. This means that exogenous features are derived from
y
, as opposed to transforming an existing exog array. It also behaves slightly differently in thetransform()
stage than most other exogenous transformers in thatexog
is not a required arg, and it takes**kwargs
. See thetransform()
docstr for more info.- Parameters:
m : int
The seasonal periodicity of the endogenous vector, y.
k : int, optional (default=None)
The number of sine and cosine terms (each) to include. I.e., if
k
is 2, 4 new features will be generated.k
must not exceedm/2
, which is the default value if not set. The value ofk
can be selected by minimizing the AIC.prefix : str or None, optional (default=None)
The feature prefix
Notes
Helpful for long seasonal periods (large
m
) whereseasonal=True
seems to take a very long time to fit a model.
References
Examples
>>> import pandas as pd >>> from pmdarima.preprocessing import FourierFeaturizer >>> from pmdarima.datasets import load_wineind >>> y = load_wineind() >>> trans = FourierFeaturizer(12, 4) >>> y_prime, X = trans.fit_transform(y) >>> X.head() FOURIER_S12-0 FOURIER_C12-0 ... FOURIER_S12-3 FOURIER_C12-3 0 0.500000 8.660254e-01 ... 8.660254e-01 -0.5 1 0.866025 5.000000e-01 ... -8.660255e-01 -0.5 2 1.000000 -4.371139e-08 ... 1.748456e-07 1.0 3 0.866025 -5.000001e-01 ... 8.660253e-01 -0.5 4 0.500000 -8.660254e-01 ... -8.660255e-01 -0.5
Methods
fit
(y[, X])Fit the transformer
fit_transform
(y[, X])Fit and transform the arrays
get_metadata_routing
()Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
set_output
(*[, transform])Set output container.
set_params
(**params)Set the parameters of this estimator.
set_transform_request
(*[, n_periods])Request metadata passed to the
transform
method.transform
(y[, X, n_periods])Create Fourier term features
update_and_transform
(y[, X])Update the params and return the transformed arrays