Khansa, home
Work with me

Jump to

Pages

Projects

Links

Lesson 1 of 8, about 10 minutes

What is a time series? Trend, season and noise explained

A time series is a list of numbers measured again and again over time, in order. Daily sales, hourly temperature, monthly rent, weekly website visits. The order matters, because yesterday tells you something about today.

By the end: Understand what a time series is and spot its three building blocks.

Try it: build a series

Move the sliders. The pink line is your series. It is made of the three parts below it.

Three parts hide inside almost every series

Trend is the slow direction. A cafe that gets more popular has sales that climb over the year.

Seasonality is a pattern that repeats on a fixed calendar. Weekends are busy, December is busy, summer is slow. The gap between repeats is called the period: 7 for days of a week, 12 for months of a year.

Noise is everything else: the rainy Tuesday, the one-off event, plain luck. You cannot forecast noise. You can only describe how big it usually is.

Make your own series

Run this once. It builds a year of made-up cafe sales with a growing trend, busy weekends and some noise. We reuse it in every lesson.

Python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

rng = np.random.default_rng(42)
days = pd.date_range("2024-01-01", periods=365, freq="D")
trend = np.linspace(100, 140, 365)                 # sales slowly grow
week = np.array([-8, -6, -4, 0, 6, 16, 12])[days.dayofweek]  # busy weekends
s = pd.Series(trend + week + rng.normal(0, 4, 365), index=days, name="sales")

s.plot(figsize=(9, 3), title="Daily cafe sales")
plt.show()

Time series are different from normal tables

In a normal table you can shuffle the rows and nothing changes. In a time series, shuffling destroys the story. Two rules follow from this and we use them all course long: always keep the order, and never let the model see the future.

Where you will use this

  • A shop forecasting how much stock to order next week
  • A bank planning how many staff it needs on a payday
  • A power company predicting tomorrow’s electricity demand
  • A website planning servers for a product launch

Common mistake: Do not call any list of numbers a time series. If the order and the dates do not matter, it is just a table.

Try it yourself

Open the lab above and set the noise to zero. Then add season back. Which part makes the line look wavy, and which part makes it climb?

Check yourself

A series repeats every 7 days. What is the period?

7. The period is the number of steps before the pattern repeats.

Which part can you never forecast?

Noise. You can only measure how large it usually is.