datarekha

Trend, seasonality & decomposition

Learn to separate the long-term trend, repeating seasonal pattern, and random noise in any time series — and see why that split is the first step in almost every forecasting workflow.

8 min read Beginner Time Series Lesson 2 of 14

What you'll learn

  • The four classic components: trend, seasonality, cycle, and residual
  • Additive vs multiplicative models — and how to tell which fits your data
  • How a centered moving average reveals the trend, and what remains after you subtract it

Before you start

Every time series you will ever work with is secretly the sum (or product) of a few simpler stories layered on top of each other. Before you choose a forecasting model, you need to know which stories are present and how large they are. That is what decomposition is for.

The four components

A time series can be broken into four pieces:

Trend is the long-run direction of the series — the overall drift upward, downward, or flat across the full period you are observing. If your annual revenue has grown every year for a decade, that upward slope is the trend.

Seasonality is a pattern that repeats at a fixed, known period. Weekly retail footfall peaks on Saturday and troughs on Tuesday, every week. Christmas-quarter sales spike every Q4. The key word is fixed: you know exactly when the next peak arrives because it is calendar-driven.

Cycle refers to longer, slower swings that are not tied to a fixed calendar period — think multi-year business cycles or housing booms. Cycles are real, but they are harder to model because their length varies. At the Beginner stage, most decomposition tools lump cycles into the trend component, so we will follow that convention here and focus on trend, seasonality, and residual.

Residual (also called irregular or noise) is whatever is left after the trend and seasonal components are accounted for. A good decomposition leaves residuals that look like white noise — no remaining pattern. If your residuals still have structure, you have not captured all the signal yet.

Why decompose at all?

Two reasons matter immediately:

  1. Understand your data. Plotting the four components separately tells you whether growth is accelerating, whether seasonality is getting stronger over time, and whether a particular month was genuinely exceptional or just the usual December bump.

  2. Choose the right model. A series with strong, stable seasonality calls for a SARIMA or Exponential Smoothing model later in your workflow. A series whose seasonal component is tiny compared to its trend calls for something different. You cannot make that call confidently without decomposing first.

Additive vs multiplicative

This is the first modelling decision you will make, and getting it wrong costs you.

Additive model: y = Trend + Seasonal + Residual

The seasonal swing is a fixed amount added on top of the trend. If December always adds 500 units regardless of whether the underlying trend is at 2000 or 8000 units, the series is additive.

Multiplicative model: y = Trend × Seasonal × Residual

The seasonal swing is a proportion of the trend level. If December always adds roughly 25 percent on top of whatever the baseline is, the series is multiplicative. As the business grows, the December spike grows with it.

How to tell the difference: look at the raw series. If the amplitude of the seasonal wiggle stays roughly constant as the level rises, use additive. If the wiggle grows visibly larger as the level rises, use multiplicative.

Diagram: what decomposition looks like

ObservedTrendSeasonalResidualTime →

The same synthetic series viewed as its four components. The observed signal is the sum of the three below it.

Hands-on: detrending with a centered moving average

The oldest and most interpretable way to estimate the trend is a centered moving average (CMA). You average each point with its neighbors symmetrically, so the seasonal peaks and troughs cancel out, leaving only the smooth long-run direction.

Subtracting the CMA from the original series then reveals the seasonal component plus residual. Run the playground below, read the comments, and watch the detrended signal emerge.

What you should see: the red CMA line follows the blue observed series at a distance, smoothing away the wiggles. The green detrended panel oscillates around zero — that regular wave is the seasonal pattern, and the slight irregularity in it is the noise. The orange panel shows the true seasonal component for comparison; the green should match it closely.

Using statsmodels for full decomposition

The manual CMA gives you the intuition. In practice, statsmodels wraps the same logic (and improvements like STL) in one function call.

import pandas as pd
from statsmodels.tsa.seasonal import seasonal_decompose

# y is a pandas Series with a DatetimeIndex
result = seasonal_decompose(y, model='additive', period=12)

result.plot()

result.trend, result.seasonal, and result.resid are each a Series you can inspect individually. Pass model='multiplicative' if your seasonal amplitude grows with the level.

What comes next

Once you know the shape of your components you can make better modelling choices. A strong, stable seasonal component with a clear trend points toward SARIMA or Holt-Winters Exponential Smoothing — both of which you will meet in the next lessons. A series whose residuals after decomposition still look structured means you have more signal to capture, and that is where stationarity testing (covered in the next lesson) comes in.


Quick check

0/3
Q1A retail chain's weekly sales chart shows that the December spike is roughly 500 units above the trend every year, regardless of whether the trend is at 2,000 or 10,000 units. Which model is most appropriate?
Q2You compute a centered moving average with window = 12 on a monthly series. Compared to the original 60-point series, the CMA output is shorter. Why?
Q3A startup's monthly app downloads have grown 10x over two years, and the December spike now looks about 10x bigger than it did in year one. You apply an additive decomposition. What will the residuals most likely show?

Practice this in an interview

All questions
What are trend, seasonality, and residual in time series decomposition, and how do you extract them?

Decomposition separates a series into a trend component (long-run direction), a seasonal component (periodic, fixed-period pattern), and a residual (everything left over). Additive decomposition sums the three; multiplicative decomposition multiplies them, which is appropriate when seasonal swings grow with the level.

Why can't you shuffle a time series before splitting into train and test sets?

Shuffling destroys temporal order, so the model trains on future data and is evaluated on the past — a direct information leak. Time series observations are serially correlated, meaning past values predict future ones, and any random split obliterates that structure entirely.

What is exponential smoothing, and how does Holt-Winters extend it to handle trend and seasonality?

Simple exponential smoothing computes a weighted average of all past observations where weights decay geometrically, controlled by a single smoothing parameter alpha. Holt's method adds a trend component with a second parameter beta; Holt-Winters (ETS) adds a seasonal component with a third parameter gamma, making it a strong baseline for series with both trend and seasonality.

When would you choose Prophet over ARIMA for a forecasting problem?

Prophet is a curve-fitting model that decomposes the series into trend, seasonality, and holidays; it handles missing data, multiple seasonalities, and non-uniform time grids with minimal tuning and is accessible to non-statisticians. ARIMA is a statistical model based on autocorrelation structure; it is more appropriate when the series is short, noise is small, and you need principled uncertainty intervals from an explicit stochastic process.

Sign in to track your progress

Completed lessons, your XP, level, and streak save to your account — it's free and takes a few seconds.

Explore further

Related lessons

Skip to content