cat /en/naive-forecasts/
MDN-123:22
SERIES Inside Ordito · Chapter 14

Naive forecasts

· Artificial Intelligence · 4 min read

Every Monday Ordito’s planning office decides how many pieces of each category to send to the stores. It needs a week-by-week sales forecast. Before any model, though, there are three forecasts that learn nothing, and that are hard to beat.

Three baseline models

The naive forecast says: next week will be like this one. The seasonal one: it will be like the same week last year. The moving average: it will be like the average of the last k weeks.

To compare them we use the WAPE, the sum of the absolute errors divided by the sum of sales. A WAPE of 0.10 means that, over everything that was sold, the forecast was wrong by 10%. It is the most widely used measure in retail, because it is not dominated either by the large categories or by the weeks in which very little is sold.

In the lab you choose a category and a method, and how many weeks ahead to forecast. The WAPE is measured on 2025.

DEMO Naive forecasts · about this demo · full screen ↗

Three experiments

Last week. One week ahead, the naive forecast is wrong by 11.5% over all categories: sales change slowly, except at the start of the sale seasons. But increase the lead time: at three months the error rises to 35%.

A year ago. The seasonal one is wrong by 16%, at any lead time. One week ahead it loses to the naive one; from two weeks upwards it wins.

The forgotten shift. In the moving average you compute the shift first, then the average. Tick “dimentica lo shift” (forget the shift): the average includes the week to be forecast, and the error drops from 0.170 to 0.118. It looks like a better model, and it is false: on Monday morning that week has not happened yet.

The same experiment in Python

import numpy as np
import pandas as pd

URL = "https://raw.githubusercontent.com/mid079/machine-learning-teoria-pratica/main/dati/"
scontrini = pd.read_parquet(URL + "scontrini.parquet", columns=["id_scontrino", "data_ora"])
righe = pd.read_parquet(URL + "righe_scontrino.parquet", columns=["id_scontrino", "id_modello", "quantita"])
articoli = pd.read_parquet(URL + "articoli.parquet", columns=["id_modello", "categoria"])
r = righe.merge(scontrini, on="id_scontrino").merge(articoli, on="id_modello")
r["settimana"] = r["data_ora"].dt.to_period("W-SUN").dt.start_time
vendite = r.pivot_table(index="settimana", columns="categoria", values="quantita", aggfunc="sum").loc["2023-01-02":"2025-12-22"]

def wape(vere, previste):
    return np.abs(vere - previste).to_numpy().sum() / vere.to_numpy().sum()

nel_2025 = vendite.index.year == 2025
for nome, previste in [("naive", vendite.shift(1)), ("seasonal", vendite.shift(52)),
                       ("mean of 4", vendite.shift(1).rolling(4).mean()),
                       ("mean of 4, without shift", vendite.rolling(4).mean())]:   # the last one cheats
    print(f"{nome:24s} WAPE {wape(vendite[nel_2025], previste[nel_2025]):.3f}")

In the book

This lab accompanies chapter 14, “Time series”: trend, seasonality and noise, the baseline models, lag features, validation over time with TimeSeriesSplit, ridge and gradient boosting, and the direct and recursive strategies for forecasting several weeks ahead.

COVER COMING SOON
mltp · 2026

Machine Learning. Teoria, matematica e pratica degli algoritmi

Michele di Nuzzo · in Italian

Every algorithm in two steps: first derive it, with the mathematics it needs and an example worked by hand, then write it from scratch in NumPy. Only at the end use it with scikit-learn.

[the book’s page] [shop links coming soon]

The “Inside Ordito” series