Decomposition: Trend, Seasonality, Noise
Tear a series apart before you try to extend it
Decomposition separates a series into trend, seasonal and residual parts. It's the diagnostic every forecaster runs first — and the simplest reliable forecasting tool when you model the components properly.
What you will learn
- Separate trend, seasonal and residual components
- Choose additive vs multiplicative decomposition
- Use STL and moving averages in practice
What is this?
Decomposition models a series y_t as components: y_t = trend_t + seasonal_t + residual_t (additive) or y_t = trend_t × seasonal_t × residual_t (multiplicative). Trend is a moving central tendency; seasonal is the fixed-period oscillation; residuals remain after both are removed. Tools like STL (Seasonal-Trend decomposition using Loess) estimate all three robustly and excel at exposing both forecastable structure and data pathologies.
Why do you need it?
- Forecasting trend separately from seasonality makes each model trivial and robust.
- Decomposition is the first diagnostic — it surfaces drift, breaks and periodic artifacts visually.
- Residuals tell you what's left to model: white noise means you've extracted the structure.
- Multiplicative vs additive tells you whether seasonal amplitude grows with level (revenue) or not.
Mental model
Separating a photo into exposure, subject and backdrop
Decomposition
You can edit the subject (trend) without touching the backdrop (seasonality), and decide whether the 'brightness scaling' is additive (dim room) or multiplicative (snow glare). Truck-though models that mix components are like fighting three photographers at once.
How it works
- Compute the trend with a (possibly centered/rolling) moving average or Loess smoother.
- Detrend: subtract (additive) or divide (multiplicative) trend from the series.
- Average the detrended series within each season position to get the seasonal component.
- Residuals = original − trend − seasonal (additive) or original / (trend × seasonal).
- STL generalizes this with iterative robust smoothing for outliers and handles arbitrary seasonal periods.
Additive decomposition into three plots.
Examples
Decompose with statsmodels
python3 -c "import numpy as npfrom statsmodels.tsa.seasonal import seasonal_decomposet = np.arange(120)y = 50 + 0.3*t + 5*np.sin(2*np.pi*t/12) + np.random.normal(0, 1, 120)res = seasonal_decompose(y, model='additive', period=12)print('trend | seasonal | resid numpy shapes:')print('trend', np.round(res.trend[:4], 1))print('seasonal first 12', np.round(res.seasonal[:12], 2))" 2>/dev/null || echo "statsmodels not installed"seasonal_decompose returns trend, seasonal and resid arrays aligned to the input — pulling the period-12 sinusoid cleanly out of the noise.
In production
- A retail planner decomposes daily orders, then models purely the residual with an ML model for 'what the season didn't explain'.
- An anomaly-detection team flags outliers in the residual component — unusual noise, not a changed baseline.
- A forecast pipeline switches from additive to multiplicative after charts show seasonal spread growing with sales level.
Best practices
- Choose the period from knowledge — 7 for weekly, 12 monthly — and confirm visually.
- Check the residual plot is roughly stationary white noise; if it has shape, decompose again.
- Use STL for robustness to outliers and multiple seasonalities (intraday + weekly).
- Store the components in your pipeline so the forecast's three parts are auditable.
Common mistakes
- Treating long-term drift in the moving average as 'the forecast' without extending it.
- Using additive decomposition on multiplicative-growth metrics (revenue, page views) — seasonal amplitude explodes.
- Decomposing a series with structural breaks; the trend smoother smears the break across neighbors.
- Forgetting calendar edges: weekend/holiday effects are not pure 7-day seasonality.
Common issues
Seasonal component looks jagged, not periodicWrong period or missing calendar (holidays in a weekly pattern)
Set period from domain knowledge and add holiday/regressor terms.
Residuals still trendingTrend smoother too short for the true drift
Lengthen the trend window or use STL with a larger trend component.
Debugging tips
- Plots are your test: if residuals show a streak of same-sign runs, the components missed structure.
- Compare residual variance pre- and post-decomposition; weak drops mean the components carry almost no signal.
- When STL's seasonal component looks wiggly, increase the seasonal smoother's window.
- Broken into pieces? Re-fit the model to the residual after fixing the trend term — often the bug is a stale trend.
Interview checkpoint
Hands-on lab
- Run additive/multiplicative decomposition
- Fit a simple trend + seasonal forecast from components
- Compare component-based forecast vs a naive baseline
Decompose a Series and Rebuild the Forecast
30 min · intermediate
Quick quiz
A revenue series' seasonal spikes grow bigger as revenue grows. Prefer:
White-noise residuals mean decomposition extracted all the model-able structure.