pmdarima.preprocessing
.FourierFeaturizer¶
-
class
pmdarima.preprocessing.
FourierFeaturizer
(m, k=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.Notes
- Helpful for long seasonal periods (large
m
) whereseasonal=True
seems to take a very long time to fit a model.
References
[R63] https://github.com/robjhyndman/forecast/blob/master/R/season.R [R64] https://robjhyndman.com/hyndsight/longseasonality/ Methods
fit
(y[, exogenous])Fit the transformer fit_transform
(y[, exogenous])Fit and transform the arrays get_params
([deep])Get parameters for this estimator. set_params
(**params)Set the parameters of this estimator. transform
(y[, exogenous, n_periods])Create Fourier term features update_and_transform
(y, exogenous, **kwargs)Update the params and return the transformed arrays -
fit
(y, exogenous=None)[source][source]¶ Fit the transformer
Computes the periods of all the Fourier terms. The values of
y
are not actually used; only the periodicity is used when computing Fourier terms.Parameters: y : array-like or None, shape=(n_samples,)
The endogenous (time-series) array.
exogenous : array-like or None, shape=(n_samples, n_features), optional
The exogenous array of additional covariates. If specified, the Fourier terms will be column-bound on the right side of the matrix. Otherwise, the Fourier terms will be returned as the new exogenous array.
-
fit_transform
(y, exogenous=None, **transform_kwargs)[source]¶ Fit and transform the arrays
Parameters: y : array-like or None, shape=(n_samples,)
The endogenous (time-series) array.
exogenous : array-like or None, shape=(n_samples, n_features), optional
The exogenous array of additional covariates.
**transform_kwargs : keyword args
Keyword arguments required by the transform function.
-
get_params
(deep=True)[source]¶ Get parameters for this estimator.
Parameters: deep : boolean, optional
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns: params : mapping of string to any
Parameter names mapped to their values.
-
set_params
(**params)[source]¶ 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.Returns: self
-
transform
(y, exogenous=None, n_periods=0, **_)[source][source]¶ Create Fourier term features
When an ARIMA is fit with an exogenous array, it must be forecasted with one also. Since at
predict
time in a pipeline we won’t havey
(and we may not yet have anexog
array), we have to know how far into the future for which to compute Fourier terms (hencen_periods
).This method will compute the Fourier features for a given frequency and
k
term. Note that they
values are not used to compute these, so this does not pose a risk of data leakage.Parameters: y : array-like or None, shape=(n_samples,)
The endogenous (time-series) array. This is unused and technically optional for the Fourier terms, since it uses the pre-computed
n
to calculate the seasonal Fourier terms.exogenous : array-like or None, shape=(n_samples, n_features), optional
The exogenous array of additional covariates. If specified, the Fourier terms will be column-bound on the right side of the matrix. Otherwise, the Fourier terms will be returned as the new exogenous array.
n_periods : int, optional (default=0)
The number of periods in the future to forecast. If
n_periods
is 0, will compute the Fourier features for the training set.n_periods
corresponds to the number of samples that will be returned.
-
update_and_transform
(y, exogenous, **kwargs)[source][source]¶ Update the params and return the transformed arrays
Since no parameters really get updated in the Fourier featurizer, all we do is compose forecasts for
n_periods=len(y)
and then updaten_
.Parameters: y : array-like or None, shape=(n_samples,)
The endogenous (time-series) array.
exogenous : array-like or None, shape=(n_samples, n_features)
The exogenous array of additional covariates.
**kwargs : keyword args
Keyword arguments required by the transform function.