Time Series
Intermediate 14 min read Time Series

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.

seasonal decompositiontrendseasonalityadditivemultiplicativeSTL
Before we start

What you will learn

  • Separate trend, seasonal and residual components
  • Choose additive vs multiplicative decomposition
  • Use STL and moving averages in practice
Introduction

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.

Motivation

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.
Think about it

Mental model

Imagine

Separating a photo into exposure, subject and backdrop

Think of

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.

Mechanics

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.

Original
Trend
Seasonal
Residual
Forecast
Hands-on

Examples

Decompose with statsmodels

Decompose with statsmodels
python3 -c "
import numpy as np
from statsmodels.tsa.seasonal import seasonal_decompose
t = 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.

Real world

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.
Guidelines

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.
Watch out

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.
Root cause analysis

Common issues

Error
Seasonal component looks jagged, not periodic
Root cause

Wrong period or missing calendar (holidays in a weekly pattern)

Fix

Set period from domain knowledge and add holiday/regressor terms.

Error
Residuals still trending
Root cause

Trend smoother too short for the true drift

Fix

Lengthen the trend window or use STL with a larger trend component.

When things break

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.
Interviews

Interview checkpoint

Practice

Hands-on lab

Decompose a Series and Rebuild the Forecast
30 min · intermediate
In progress
Objectives
  • 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

0/4 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

A revenue series' seasonal spikes grow bigger as revenue grows. Prefer:

2

White-noise residuals mean decomposition extracted all the model-able structure.

Go deeper

Official documentation