Skip to content
Français

Trend, season and noise

  • Lesson 4
  • 35 min
  • Module 2: Read a time series

Where we are

We have opened the data and drawn one product. The line goes up and down, and it is hard to say why. In this lesson, we split a series into a slow trend, a season that repeats and the rest, so that we can see each part on its own.

Plays from YouTube. Nothing loads from YouTube until you press play. Privacy

What you will be able to do

Split a time series into a slow trend, seasons that repeat and the rest, and read each part on its own. A forecast needs each part, and the parts are hard to see in the raw line.

NotebookDo this lesson in a notebookColab · Kaggle · GitHub

The notebook has every code cell, task and check of this lesson. It builds the tiny series, decomposes Larkfield’s daily orders and the parasol, and shows the failure case. Its setup cells install pandas and statsforecast and download the practice data, so it needs no local setup. About 35 minutes.

Colab and Kaggle open your own copy. They need a free Google or Kaggle account. Stuck? See the solution notebook.

Before you startWhat to know and to have readyAbout 35 minutes

What you need to know

  • The Larkfield tables and the setup notebook, from Meet the Larkfield data.
  • What a time series is: values measured one after another, at equal steps of time (one value a day, or one an hour).
  • The variance of a set of numbers: the mean of the squared distances from their average, a measure of spread. Describe a dataset in the mathematics course explains it.

What you need on your computer

Nothing for the notebook route: it runs in Colab or Kaggle. For a local route, save the notebook in the folder larkfield that you made in Meet the Larkfield data, and choose the kernel .venv. The notebook reuses the data in larkfield-forecasting.

Tested with Python 3.12, pandas 2.3.3, statsforecast 2.1.1 and statsmodels 0.15.0 on macOS. Windows and Colab were not tested.

Think of a small café near an office. Its owner counts the cups of coffee that she sells every day. Three things move that number. First, the café becomes better known, so more people come each year. Second, the office workers come on weekdays, and the café is quiet at the weekend. Third, iced coffee sells in summer, so the totals change with the time of year.

On top of this, every day has its own surprise: a rainy Tuesday, a broken machine. The owner sees one number per day, but it is the three patterns and the surprise added together.

The problem: one line hides several patterns

Section titled “The problem: one line hides several patterns”

Here is Larkfield’s version of the café: the number of orders per day, all three sales channels added up, for two years.

Larkfield's daily orders for 728 days. The line rises every spring, falls in winter, and has a spike every late November.
Text description of the chart

A line chart of 728 daily values from 1 April 2024 to 29 March 2026. The first day has 550 orders and the last day 786. The line rises in spring and summer and falls in autumn and winter, in both years. It has a tall spike in late November of each year (Black Friday). The highest value is 1,372 orders on Saturday 5 July 2025, in a heat-wave week. One day, 19 October 2025, is missing in the data. Here it is filled with the mean of the same weekday one week before and one week after.

Try to answer three questions from this chart. Does Larkfield grow from one year to the next? Which weekday is the busiest? How much of the summer rise is the season? The line cannot answer them. The weekly ups and downs are too small to see, and the growth hides inside the seasons.

A forecaster needs each answer. Kenji, the stock planner, needs the growth to order more each year. Grace, the support lead, needs the weekly shape to put more agents on the busy days. A forecast that copies last summer, with no growth, orders too little.

So we do what the café owner does in her head. We split the series into parts and look at each part alone.

  • The trend is the slow change of the level over months and years. For the café, it is “more people know us”.
  • A season is a pattern that repeats with a fixed length. The café has a weekly season (busy weekdays) and a yearly season (iced coffee in summer). In forecasting, “season” means any repeating cycle, not only spring or summer.
  • The remainder (also called the noise) is what is left: the surprises.

We write it as a sum: value = trend + weekly season + yearly season + remainder. Splitting a series into these parts is called a decomposition.

A tiny example: build a series from its parts

Section titled “A tiny example: build a series from its parts”

Start from the parts and build the values. A shop sells 100 units on day 1. The trend adds 2 units every day. The weekly season adds 30 units on Saturdays and 20 on Sundays, and nothing on weekdays. Day 1 is a Monday, so days 6, 7, 13 and 14 are the weekend. The remainder is a small number between −4 and +3.

Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Trend 100 102 104 106 108 110 112 114 116 118 120 122 124 126
Season 0 0 0 0 0 30 20 0 0 0 0 0 30 20
Remainder 1 −2 0 3 −1 2 −4 0 2 −1 1 −2 −3 2
Value 101 100 104 109 107 142 128 114 118 117 121 120 151 148

Read day 13, a Saturday: 124 + 30 − 3 = 151. Every value is its column added up.

  • Trend
  • Trend + season
  • Value (with the remainder)
The tiny series built from its parts: a straight trend, the weekend bumps of the season on top, and the remainder that moves each dot a little.
Text description of the chart

Three lines over 14 days. The trend is a straight line from 100 on day 1 to 126 on day 14. The trend plus the season follows the trend on weekdays. It jumps up by 30 on days 6 and 13 (Saturdays) and by 20 on days 7 and 14 (Sundays). The values are dots that sit close to the second line, at most 4 units away: these small distances are the remainder. Day 13 has the highest value, 151.

A decomposition method does the opposite. It gets only the bottom row, the values, and it estimates the three rows above. It finds the trend with a moving local average, a mean of the nearby days, so the weekly bumps cancel out. Then it finds each season as the typical distance from that trend on each weekday, or on each day of the year. The rest is the remainder.

The classic method is STL, short for “Seasonal and Trend decomposition using Loess”. Loess is a kind of local average. STL takes one season. MSTL, “multiple STL”, repeats the STL steps for several seasons, one after the other. Larkfield has two seasons, a week of 7 days and a year of 365 days, so we use MSTL.

In the notebook, statsforecast’s MSTL takes the season lengths as a list. The model it fits keeps the parts in a table.

from statsforecast import StatsForecast
from statsforecast.models import MSTL
df = pd.DataFrame({"unique_id": "orders", "ds": orders.index, "y": orders.to_numpy()})
sf = StatsForecast(models=[MSTL(season_length=[7, 365])], freq="D")
sf.fit(df)
parts = sf.fitted_[0, 0].model_ # columns: data, trend, seasonal7, seasonal365, remainder
share = {c: round(float(100 * parts[c].var() / parts["data"].var()), 1)
for c in ["trend", "seasonal7", "seasonal365", "remainder"]}
print("share of the variance, %:", share)
print("trend: first", round(parts["trend"].iloc[0]), "last", round(parts["trend"].iloc[-1]))
share of the variance, %: {'trend': 6.7, 'seasonal7': 6.3, 'seasonal365': 87.2, 'remainder': 16.8}
trend: first 612 last 759

The first line says how much of the ups and downs each part explains. It is each part’s variance as a share of the variance of the data. The yearly season explains the most, 87.2%. The shares do not add up to exactly 100%, because the parts are estimates and they overlap a little. The second line says that the trend grows from 612 to 759 orders a day in two years. The next charts show each part.

  • Orders per day
  • Trend
  • Trend + yearly season
The trend (a slow rise from 612 to 759 orders a day) and the trend plus the yearly season, which follows the data through the year.
Text description of the chart

The chart shows the daily orders as a thin grey line, with two smooth lines on top. The trend rises slowly and almost straight, from 612 orders a day in April 2024 to 759 in March 2026. The trend plus the yearly season is a wave that follows the grey line: high from May to August, low from November to February. At its highest (7 July 2025), the yearly season adds 460 orders a day. At its lowest (25 December 2024), it removes 481.

Now we can answer the first question. Yes, Larkfield grows: about 24% in two years (612 to 759). The yearly season is the garden: furniture, parasols and barbecues sell from spring to late summer.

The weekly season is one number per weekday: how far that weekday is above or below the week’s level.

  • Weekly season
  • The week's level (0)
The weekly season of Larkfield's orders: Saturday, Sunday and Monday are busy, Wednesday is the quietest day.
Text description of the chart

Seven points, Monday to Sunday, on an axis from −50 to +50 orders, with a dashed line at 0. Monday +28.4, Tuesday −17.6, Wednesday −39.0, Thursday −26.1, Friday −11.4, Saturday +35.4 and Sunday +29.8. The seven values add up to about 0, because a season describes the distance from the week’s level.

This answers the second question: Saturday is the busiest day, 35 orders above the week’s level, and Wednesday the quietest, 39 below. The weekly season explains only 6.3% of the variance, but it comes back every week, so it matters for every daily forecast.

The remainder: what the trend and the two seasons do not explain. Most days are within 100 orders; the largest values are around Black Friday.
Text description of the chart

A line around zero for 728 days. Most days are between −100 and +100 orders. The largest value is +278 orders on 28 November 2025, Black Friday. The lowest is −279 orders on 28 November 2024, the day before Black Friday 2024. The next largest are on 2 December and on 2 August of both years, with opposite signs. Cyber Monday was on 2 December 2024 and on 1 December 2025.

The remainder is not only noise. Look at its two largest values. On Friday 28 November 2025, Black Friday, it is +278 orders. On 28 November 2024 it is −279. That day was a Thursday, the day before Black Friday 2024. Why does it miss so badly?

The yearly season learns one shape per date of the year. Black Friday was on 29 November in 2024 and on 28 November in 2025. The season sees two spikes on two dates and shares them between both years. So it puts half a spike on 28 November 2024, where no spike happened, and half a spike too little on Black Friday 2025. A holiday that moves in the calendar does not fit a season of fixed length. Calendars, holidays and events handles it.

The orders add up many products, and one product can be very different. In the notebook’s Your turn, you decompose the parasol (P025, the three regions added up) in the same way.

  • Parasols sold per day
  • Trend + yearly season
The parasol's daily sales with its trend plus yearly season. The yearly season explains 69.5% of the variance: a seasonal product.
Text description of the chart

The parasol sells almost nothing from October to March and up to 48 a day in summer. The smooth line of the trend plus the yearly season rises in spring and falls in September, in both years. It is a little lower in summer 2025 (35 a day at its highest) than in summer 2024 (37). The summer of 2025 was cold. For the parasol, the yearly season explains 69.5% of the variance and the remainder 19.1%. The weekly season explains 4.2% and the trend 1.8%.

For the parasol, the yearly season is almost the whole story: 69.5% of the variance. The trend explains only 1.8%. But this shape rests on only two summers, and the summer of 2025 was cold, a situation we planted. The season is an average of one normal summer and one cold one.

Decompose a series before you forecast it. The parts tell you which forecaster can work. A series with a strong weekly season needs a method that knows the week. A series with a strong trend needs a method that does not stay flat. Later modules choose methods with this information.

A decomposition is not a forecast. It describes the past. It also has costs and limits:

  • It needs full seasons. A yearly season from two years rests on two examples. You can see it in the remainder: on 2 August 2024 it is +194, and on 2 August 2025 it is −195. For each date, the season is close to the mean of the two years, so the two remainders mirror each other. The failure case below shows a second problem.
  • It assumes the parts add up. If the season grows with the level (a busy summer twice the size of a quiet one), a sum fits badly. A logarithm of the values can turn that into a sum.
  • Moving holidays end up in the remainder, or they smear across the wrong dates, as Black Friday did.

Common mistake

Two years are not enough for every tool

Symptom: Tomás, the AI engineer, runs the same decomposition with another well-known library, statsmodels. He gets no error. In the notebook’s section 5:

from statsmodels.tsa.seasonal import MSTL as SM_MSTL
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
result = SM_MSTL(orders, periods=[7, 365]).fit()
kept = [result.seasonal.name] if isinstance(result.seasonal, pd.Series) else list(result.seasonal.columns)
print("seasons that statsmodels kept:", kept)
print("its warning:", [str(w.message) for w in caught if "period" in str(w.message)][:1])
seasons that statsmodels kept: ['seasonal']
its warning: ['A period(s) is larger than half the length of time series. Removing these period(s).']

statsmodels kept one season, the week, and quietly removed the year. The warning is easy to miss, and many notebooks hide warnings. Then the yearly wave must go somewhere. It goes into the trend:

  • statsforecast trend
  • statsmodels trend
Two 'trends' of the same orders. Without the yearly season, the statsmodels trend swings with the seasons, from 402 to 1,140 orders a day.
Text description of the chart

Two lines over 728 days. The statsforecast trend is almost straight, from 612 to 759 orders a day (its lowest value 612, its highest 759). The statsmodels trend, with the yearly season removed, is a wave. It goes from 402 orders a day in winter to 1,140 in summer.

Cause: statsmodels needs more than two full periods of a season to estimate it. Our history has 728 days, and two years are 730 days, so 365 is more than half the length. statsforecast estimates the yearly season from what it has.

Fix: use statsforecast’s MSTL for Larkfield, as this course does. In any tool, check that every season you asked for is in the output. Print the column names of the parts.

Consequence in forecasting: a “trend” that swings with the seasons is wrong in both directions. In summer, it says the shop is growing fast; in winter, that it is shrinking. A forecast built on it orders too much stock at the end of summer and too little in spring. And even with statsforecast, a yearly season from two years rests on two examples. Read it with care, and say so when you use it.

Guided practice: decompose the orders in the notebook

Section titled “Guided practice: decompose the orders in the notebook”
  1. Open the notebook from the box Do this lesson in a notebook at the top of this page.
  2. Run the setup cells and the helper cell. The data cell ends with Ready: 403758 rows of daily sales.
  3. In section 1, predict the value of day 13. Then run the cell. You see day 13 with value 151.
  4. In section 2, run the cell that reads the orders. You see 728 days, first 550 last 786 max 1372 on 2025-07-05.
  5. In section 3, predict which part changes the orders most. Then run the MSTL cell. You see the shares and trend: first 612 last 759.
  6. Run the weekly cell. You see Saturday 35.4 and Wednesday -39.0.
  7. In section 5, run the statsmodels cell. You see seasons that statsmodels kept: ['seasonal'].

Change one thing: the series. Decompose the parasol’s daily sales with the same MSTL(season_length=[7, 365]). Use load_sales(["P025"]): it already has the columns unique_id, ds and y. Before you run it, predict: will the yearly season’s share be larger or smaller than for all orders? Put the share of seasonal365 in %, rounded to 1 decimal, in parasol_yearly.

Show the answer
p = load_sales(["P025"])[["unique_id", "ds", "y"]]
sp = StatsForecast(models=[MSTL(season_length=[7, 365])], freq="D")
sp.fit(p)
pp = sp.fitted_[0, 0].model_
parasol_yearly = round(float(100 * pp["seasonal365"].var() / pp["data"].var()), 1)
print(parasol_yearly)
69.5

The share is smaller than for all orders (87.2%), and that may surprise you. The parasol is more seasonal than the shop, but it is also noisier. One product sells a few units a day, and chance moves a small count a lot, so its remainder is larger (19.1%). The yearly season is still by far its largest part.

Check your understanding

Name the four parts of Larkfield's daily orders in this lesson, and give one number for each from the decomposition.

Show the answer
  • Trend: the slow change of the level. It grows from 612 to 759 orders a day in two years, and it explains 6.7% of the variance.
  • Weekly season: the shape of the week. Saturday is 35.4 orders above the week’s level, Wednesday 39.0 below. It explains 6.3%.
  • Yearly season: the shape of the year (the garden season). It is the largest part, 87.2% of the variance, from −481 orders at Christmas to +460 in July.
  • Remainder: the rest. It explains 16.8%. Its largest values are around Black Friday, a holiday that moves in the calendar.

Check your understanding

Predict and explain: a colleague decomposes the orders with statsmodels' MSTL and the periods 7 and 365. She reports that Larkfield 'grew from 402 to 1,140 orders a day'. What went wrong, and how do you check it?

Show the answer

statsmodels needs more than two full periods to estimate a season. With 728 days, it removed the 365-day period, with only a warning. The yearly wave then went into the trend, which now swings from 402 in winter to 1,140 in summer. That is the season, not growth. Check the output: the seasonal part has only one column, seasonal, not two. The fix is a tool that estimates the yearly season from two years (statsforecast’s MSTL), and a check of the column names every time.

Check your understanding

The remainder of the orders is −279 on 28 November 2024 and +278 on 28 November 2025. Explain both numbers in plain words.

Show the answer

The yearly season learns one value per date of the year. Black Friday was on 29 November in 2024 and on 28 November in 2025. The season sees two spikes on two neighbouring dates and shares them. It puts part of a spike on 28 November 2024, where there was none, so the remainder there is very negative. On Black Friday 2025, the season has only part of the spike, so the remainder is very positive. A holiday that moves in the calendar does not fit a season of fixed length: it needs its own feature.

Recap

  • A time series is a sum of parts: a slow trend, one or more seasons that repeat with a fixed length, and a remainder. A decomposition such as STL estimates the parts from the values. MSTL handles several seasons.
  • Larkfield’s orders: the yearly season explains 87.2% of the variance, the trend 6.7%, the weekly season 6.3% and the remainder 16.8%. The trend grows from 612 to 759 orders a day; Saturday is the busiest day.
  • The parasol is seasonal (yearly season 69.5%), and its season rests on two summers, one of them cold.
  • statsmodels’ MSTL removes a yearly season with 728 days and puts the wave into the trend. Check that every season you asked for is in the output.
  • Moving holidays such as Black Friday end up in the remainder.

You can now see the parts of a series. But we have not yet measured how much one day tells us about the next. Next, you measure the memory of a series with lags and autocorrelation.

Next: Yesterday predicts today