Holt-Winters Exponential Smoothing
Background
Holt's linear smoothing (the level + trend variant of exponential smoothing) is the canonical lightweight forecaster for series with a roughly-linear trend and no seasonality. It maintains two state variables — level and trend — each as a weighted average of the new observation and the previous extrapolation. Used as a baseline forecaster in production capacity planning, ETA prediction, and time-series anomaly detection.
Problem statement
Implement holt(series, alpha, beta, horizon). Initialise , . For :
Forecast steps ahead is .
Input
series— array-like of floats, the observed time series ( values).alpha— smoothing factor for the level, in .beta— smoothing factor for the trend, in .horizon—int >= 1, number of future steps to forecast.
Output
Returns a tuple (level, trend, forecast):
level— final (Pythonfloat).trend— final (Pythonfloat).forecast—np.ndarrayof lengthhorizon.
Examples
Example 1 — constant series
Input: series=[5.0, 5.0, ..., 5.0], alpha=0.5, beta=0.3, horizon=3
Output: level=5.0, trend≈0.0, forecast=[5.0, 5.0, 5.0]
Example 2 — linear series recovers the slope
Input: series=[0, 1, 2, ..., 19], alpha=0.5, beta=0.5, horizon=3
Output: trend ≈ 1.0
Constraints
seriesmust have observations.alphaandbetamust lie in .horizon >= 1.
Notes
- Adding seasonality. Holt-Winters' triple-exponential variant adds a per-season component ; this implementation is the level+trend version.
- Picking . Production setups grid-search over a held-out window or use AIC/BIC; defaults of are reasonable for monthly data.
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: constant series forecast
- •Sample: two-point series final level and trend
- •Example: linear ramp forecast