Stop 11 · Time Series AnalysisTopics · 1/7

Time Series Components (Trend, Seasonality, Noise)

Part of the Data Science Roadmap

In short

Sales, website traffic and electricity demand all wiggle over time. Splitting a series into trend, seasonality and noise tells you which wiggles you can predict and which you can't.

Any time series can be thought of as a mix of trend (long-term direction), seasonality (repeating patterns tied to a calendar), and noise (unexplained randomness) — decomposing these helps you model each part appropriately.

The mascot pushes an ice-cream cart under a bright sun with a small rain cloud drifting in.

Think of it like this

The ice-cream cart's year

An ice-cream cart sells a bit more each year as the area grows: that's trend. It sells far more every summer and less every monsoon: seasonality. Some random rainy Tuesday in May, sales dip for no reason anyone could plan for: noise.

Watch it happen

Ten months of sales, three ingredients

10
0
11
1
14
2
11
3
12
4
13
5
16
6
13
7
14
8
15
9

1/5Monthly sales for a small shop. It looks bumpy, but there's structure inside.

The big ideas

What you need to know

Trend

The long-term direction: growth, decline or flat. It can change direction over the years.

Seasonality

Repeats on a fixed calendar: daily, weekly, yearly. Diwali sales, Monday traffic, summer AC demand.

Cycles are different

Business cycles rise and fall without a fixed period. Don't confuse them with seasonality.

Noise stays random

If the leftover residuals still show a pattern, your model has missed something.

See it in code

Walk through the code

python
1import numpy as np2import pandas as pd3from statsmodels.tsa.seasonal import seasonal_decompose4 5idx = pd.date_range("2022-01-01", periods=36, freq="MS")6trend = np.linspace(100, 160, 36)7season = 15 * np.sin(2 * np.pi * idx.month / 12)8noise = np.random.default_rng(0).normal(0, 4, 36)9sales = pd.Series(trend + season + noise, index=idx)10 11parts = seasonal_decompose(sales, model="additive", period=12)12parts.plot()

1/436 monthly dates, one per month start.

Build a fake series from known parts, then let statsmodels pull them apart again. The plot shows all four panels.

Save yourself the pain

Common mistakes

Oops

Using an additive model when seasonal swings grow as the series grows.

Do this instead

Use model='multiplicative', or log-transform the series first, when peaks get bigger over time.

Oops

Setting period to a value that doesn't match the data's frequency.

Do this instead

Monthly data with a yearly cycle needs period=12. Daily data with a weekly cycle needs period=7.

Your mission

Decompose real data

~25 min

Quick check

AC sales jump every April to June, year after year. Which component is that?

Go deeper

  1. 1Plot a real time series and visually identify trend and seasonal patterns.
  2. 2Use a decomposition function (e.g. in statsmodels) to separate these components programmatically.
  3. 3Learn to distinguish genuine seasonality from a one-off event that looks similar.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge