This repo is a hands-on practice project for smoothing and forecasting time series using:
- Simple baseline: mean (simple average)
- Moving Average (MA) smoothing
- Exponentially Weighted Moving Average (EWMA) (custom weighted version)
- Single Exponential Smoothing (SES) via
statsmodels - Double Exponential Smoothing (Holt) via
statsmodels - Triple Exponential Smoothing (Holt–Winters) via
statsmodels
The main work lives in the notebook:
smoothing.ipynb
- Generates synthetic time series (stationary noise, trend, seasonality, and combinations).
- Visualizes raw vs. smoothed series.
- Splits a series into train/test (last 5 points in one example).
- Forecasts the test window using multiple smoothing methods.
- Evaluates models using Sum of Squared Error (named
msein the notebook).
Forecast every future value using the historical mean:
The notebook function mse(observations, estimates) computes sum of squared errors (SSE):
Note: Standard MSE usually means average squared error: $$ \text{MSE} = \frac{1}{n}\sum_{t=1}^{n}(y_t - \hat{y}_t)^2 $$
If you want true MSE, divide the current output by n.
For window size (k), the moving average at time (t) is:
In the notebook:
- A fast rolling sum is computed using cumulative sums.
- With
forecast=True, the function pads the beginning with zeros for alignment.
The notebook’s ewma() uses fixed weights on the last 3 observations:
Let weights be: $$ w = (w_1, w_2, w_3) = (0.160, 0.294, 0.543) $$
Then for (t \ge 3):
This is a finite weighted moving average (not the classic recursive EMA form).
Classic recursive EMA (common definition) is: $$ S_t = \alpha y_t + (1-\alpha)S_{t-1} $$
SES is useful when the series has no trend and no seasonality.
Recursive form: $$ S_t = \alpha y_t + (1-\alpha)S_{t-1} $$
Forecast: $$ \hat{y}_{t+h} = S_t $$
Holt adds a trend component.
Adds seasonality (additive form)
Running the notebook produces:
- Plots of raw series vs smoothed series
- Forecast plots over the test window
- A small summary table comparing error across methods (baseline vs SES vs Holt vs Holt–Winters)
This comparison highlights a key lesson:
- If the data has trend, SES will typically underperform Holt.
- If the data has seasonality, Holt–Winters should outperform non-seasonal methods.
Python packages used:
numpypandasmatplotlibseabornstatsmodels