cat /en/the-line-of-the-five-stores/
MDN-120:40
SERIES Inside Ordito · Chapter 1

The line of the five stores

· Artificial Intelligence · 4 min read

Ordito, the clothing chain in the book, wants to open a new store in a city centre. How much will it take? To answer, we have five stores already open, their floor area and their 2025 revenue. It is the smallest problem in the book, and it already contains the whole of machine learning.

A rule and its error

A simple rule is a straight line: predicted revenue = b + w · area. The number w says how much more is taken for each square metre, b is the starting point. Each pair (b, w) is a different model.

To choose between two models you have to measure how wrong they are. The error for a store is the difference between the true revenue and the predicted one. The MAE is the mean of the errors in absolute value; the RMSE is the square root of the mean of the squares, and gives more weight to large errors.

In the lab, move b and w and watch the errors store by store, in red on the chart and in the bars on the right.

DEMO The line of the five stores · about this demo · full screen ↗

Three experiments

The mean. With w = 0 the line is flat and predicts 898.8 for everyone, the mean of the revenues. It is off by 169.4 on average. It is the simplest possible model, and the benchmark that every model has to beat.

Two rules compared. The rule 300 + 2.2 · x is off by 44.88 on average, the rule 250 + 2.5 · x by 47. They are two similar lines, but the steeper one pays more on the stores in the middle, Genoa and Bologna. Switch on “mostra i quadrati degli errori” (show the squares of the errors): the RMSE is the mean of the areas of those squares, under a square root.

The store that doesn’t fit. Add Lecce: 263 square metres and only 487 in revenue. Any reasonable line overestimates it by about 400. The model knows only what the data tell it, and something is missing from the data: for example, the income of the area.

The same experiment in Python

import numpy as np

x = np.array([165, 185, 268, 327, 413])      # floor area in m²
y = np.array([668, 749, 856, 944, 1277])     # 2025 revenue, thousands of euros

for nome, b, w in [("mean", y.mean(), 0), ("300 + 2.2x", 300, 2.2), ("250 + 2.5x", 250, 2.5)]:
    errori = y - (b + w * x)                 # true minus predicted
    print(f"{nome:12s} MAE {np.abs(errori).mean():6.2f}   RMSE {np.sqrt((errori ** 2).mean()):6.2f}")
print("Lecce:", 300 + 2.2 * 263, "against a true 487")

In the book

This lab accompanies chapter 1, “What is machine learning”. The chapter starts from these five stores to define model, error, training and test, and presents the Ordito questions that the rest of the book answers: regression, classification, clustering, anomalies, time series.

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