R/parsnip-exp_smoothing_reg.R
exponential_smoothing.Rdexponential_smoothing() is a way to generate a specification of an ETS model
before fitting and allows the model to be created using
different packages. Currently the only package is Rlgt.
exponential_smoothing( mode = "regression", seasonality = NULL, second_seasonality = NULL, seasonality_type = NULL, method = NULL, error_method = NULL )
| mode | A single character string for the type of model. The only possible value for this model is "regression". |
|---|---|
| seasonality | This specification of seasonality will be overridden by frequency of y, if y is of ts or msts class. 1 by default, i.e. no seasonality. |
| second_seasonality | Second seasonality. |
| seasonality_type | Either "multiplicative" (default) or "generalized". The latter seasonality generalizes additive and multiplicative seasonality types. |
| method | "HW", "seasAvg", "HW_sAvg". Here, "HW" follows Holt-Winters approach. "seasAvg" calculates level as a smoothed average of the last seasonality number of points (or seasonality2 of them for the dual seasonality model), and HW_sAvg is an weighted average of HW and seasAvg methods. |
| error_method | Function providing size of the error. Either "std" (monotonically, but slower than proportionally, growing with the series values) or "innov" (proportional to a smoothed abs size of innovations, i.e. surprises) |
A model spec
The data given to the function are not saved and are only used
to determine the mode of the model. For exponential_smoothing(), the
mode will always be "regression".
The model can be created using the fit() function using the
following engines:
"stan" (default) - Connects to Rlgt::rlgt()
Main Arguments
The main arguments (tuning parameters) for the model are:
seasonality: Seasonality.
second_seasonality: Second seasonality.
seasonality_type: Either "multiplicative" (default) or "generalized".
method: "HW", "seasAvg", "HW_sAvg"
error_method: Either "std" or "innov"
These arguments are converted to their specific names at the time that the model is fit.
Other options and argument can be
set using set_engine().
If parameters need to be modified, update() can be used
in lieu of recreating the object from scratch.
stan (default engine)
The engine uses Rlgt::rlgt().
Parameter Notes:
xreg - This is supplied via the parsnip / bayesmodels fit() interface
(so don't provide this manually). See Fit Details (below).
Date and Date-Time Variable
It's a requirement to have a date or date-time variable as a predictor.
The fit() interface accepts date and date-time features and handles them internally.
Univariate (No xregs, Exogenous Regressors):
For univariate analysis, you must include a date or date-time feature. Simply use:
Formula Interface: fit(y ~ date) will ignore xreg's.
Multivariate (xregs, Exogenous Regressors)
The xreg parameter is populated using the fit() function:
Only factor, ordered factor, and numeric data will be used as xregs.
Date and Date-time variables are not used as xregs
character data should be converted to factor.
Xreg Example: Suppose you have 3 features:
y (target)
date (time stamp),
month.lbl (labeled month as a ordered factor).
The month.lbl is an exogenous regressor that can be passed to the expotential_smoothing() using
fit():
fit(y ~ date + month.lbl) will pass month.lbl on as an exogenous regressor.
Note that date or date-time class values are excluded from xreg.
if (FALSE) { library(dplyr) library(parsnip) library(rsample) library(timetk) library(modeltime) library(bayesmodels) # Data m750 <- m4_monthly %>% filter(id == "M750") m750 # Split Data 80/20 splits <- rsample::initial_time_split(m750, prop = 0.8) # ---- ARIMA ---- # Model Spec model_spec <- exponential_smoothing() %>% set_engine("stan") # Fit Spec model_fit <- model_spec %>% fit(log(value) ~ date + month(date), data = training(splits)) model_fit }