statsmodels.tsa.holtwinters.ExponentialSmoothing#
- class statsmodels.tsa.holtwinters.ExponentialSmoothing(endog, trend=None, damped_trend=False, seasonal=None, *, seasonal_periods=None, initialization_method='estimated', initial_level=None, initial_trend=None, initial_seasonal=None, use_boxcox=False, bounds=None, dates=None, freq=None, missing='none')[source]#
Holt Winters’ Exponential Smoothing
- Parameters:
- endogarray_like
The time series to model.
- trend{“add”, “mul”, “additive”, “multiplicative”}
orNone,optional Type of trend component.
- damped_trendbool,
optional Should the trend component be damped.
- seasonal{“add”, “mul”, “additive”, “multiplicative”}
orNone,optional Type of seasonal component.
- seasonal_periods
int,optional The number of periods in a complete seasonal cycle, e.g., 4 for quarterly data or 7 for daily data with a weekly cycle.
- initialization_method{“estimated”, “heuristic”, “legacy-heuristic”, “known”},
optional Method used to initialize the recursions:
“estimated” estimates the initial values together with the other parameters, starting from the “heuristic” values, or from simpler ones if there are fewer than
10 + 2 * (seasonal_periods // 2)observations.“heuristic” computes the initial values from the data with a heuristic and holds them fixed.
“legacy-heuristic” holds them fixed at the values that statsmodels 0.11 and earlier used.
“known” uses initial_level, and initial_trend and initial_seasonal if the model has these components. They must then be given.
Default is “estimated”.
- initial_level
float,optional The initial level component. Required if the initialization method is “known”; setting it with any other method raises a ValueError. To fix some initial values and estimate the others, use
initialization_method="estimated"andfix_params.- initial_trend
float,optional The initial trend component. Required if the initialization method is “known” and the model has a trend; setting it with any other method raises a ValueError. To fix some initial values and estimate the others, use
initialization_method="estimated"andfix_params.- initial_seasonalarray_like,
optional The initial seasonal component. An array of length seasonal_periods or length
seasonal_periods - 1(in which case the last initial value is computed to make the average effect zero). Required if the initialization method is “known” and the model has a seasonal component; setting it with any other method raises a ValueError. Useinitialization_method="estimated"andfix_paramsto fix some initial values and estimate the other parameters.Changed in version 0.16.0: An array of length
seasonal_periods - 1is completed with the value that makes the average effect zero: minus the sum of the others for an additive seasonal component, and seasonal_periods minus their sum, so that the mean is 1, for a multiplicative one. It raised before. Withseasonal_periods=2, a single value is still used for both seasons, with a FutureWarning; after statsmodels 0.18 it will be completed too.- use_boxcox{
True,False, ‘log’,float},optional Should the Box-Cox transform be applied to the data first? If True, lambda is estimated by maximum likelihood. If ‘log’ then apply the log. If float then use the value as lambda. False and None apply no transform. An int is used as a bool: 0 applies no transform and any other int estimates lambda. Pass a float, such as 1.0, to fix lambda.
Changed in version 0.16.0: With an int use_boxcox, the initial values are computed from the same transform as the fit. They were computed with the int as a fixed lambda, while fitting and forecasting used it as a bool.
- bounds
dictofstrtotupleoffloat,optional A dictionary containing bounds for the parameters in the model, including the initial values when they are estimated. The keys of the dictionary are the variable names, e.g., smoothing_level or initial_trend. The initial seasonal variables are labeled initial_seasonal.<j> for j=0,…,m-1 where m is the number of periods in a full season. The bounds of the smoothing and damping parameters must lie in [0, 1]. For the initial values, use None to indicate a non-binding constraint, e.g., (0, None) constrains a parameter to be non-negative.
- datesarray_like
ofdatetime,optional An array-like object of datetime objects. If a Pandas object is given for endog, it is assumed to have a DateIndex.
- freq
str,optional The frequency of the time-series. A Pandas offset or ‘B’, ‘D’, ‘W’, ‘M’, ‘A’, or ‘Q’. This is optional if dates are given.
- missing
str,optional Available options are ‘none’, ‘drop’, and ‘raise’. If ‘none’, no nan checking is done. If ‘drop’, any observations with nans are dropped. If ‘raise’, an error is raised. Default is ‘none’.
Changed in version 0.16.0: With ‘drop’, the initial values, the Box-Cox transformation, the parameter estimates and
simulateuse the data with the nans dropped. They previously used the data including the nans, which made the estimates wrong, and a model with a multiplicative component raised.
- Attributes:
endog_namesNames of endogenous variables
exog_namesThe names of the exogenous variables.
Notes
This is a full implementation of the holt winters exponential smoothing as per [1]. This includes all the unstable methods as well as the stable methods. The implementation of the library covers the functionality of the R library as much as possible whilst still being Pythonic.
See the notebook Exponential Smoothing for an overview.
References
[1]Hyndman, Rob J., and George Athanasopoulos. Forecasting: principles and practice. OTexts, 2014.
Methods
fit([smoothing_level, smoothing_trend, ...])Fit the model
fix_params(values)Temporarily fix parameters for estimation
from_formula(formula, data[, subset, drop_cols])Create a Model from a formula and dataframe
hessian(params)The Hessian matrix of the model
information(params)Fisher information matrix of model
initial_values([initial_level, ...])Compute initial values used in the exponential smoothing recursions
Initialize (possibly re-initialize) a Model instance
loglike(params)Log-likelihood of model
predict(params[, start, end])In-sample and out-of-sample prediction
score(params)Score vector of model
Properties
Names of endogenous variables
The names of the exogenous variables.