cat /en/a-simulated-store/
MDN-119:22
SERIES Inside Ordito · Chapter 2

A simulated store

· Artificial Intelligence · 4 min read

Ordito’s data do not come from a real company: a program generated them. Before using them it is worth generating a small piece yourself, a single store for one year. This makes clear something that holds for all data: behind every table there is a mechanism that produced it, and machine learning tries to reconstruct it.

A predictable part and a random one

Our store issues an average of 60 receipts a day, multiplied by a weight that depends on the day of the week: 1.65 on Saturdays, 0.6 on Sundays. This is the predictable part.

Then there is chance. If we expect 99 receipts on a Saturday, one Saturday we will issue 92, another 107. The number of customers who come in, when each decides on their own, follows the Poisson distribution: whole numbers that fluctuate around the expected value λ, with a typical fluctuation of about √λ.

In the lab, change the average receipts, the spend and the seed, and look at the store’s year and at the distribution of its Saturdays.

DEMO A simulated store · about this demo · full screen ↗

Three experiments

Chance has a size. With 60 average receipts, Saturday expects 99, and the square root of 99 is about 10. About two Saturdays out of three fall between 89 and 109. Change the seed: the individual days change, the shape stays.

Small stores, big noise. Bring the average receipts down to 15. The fluctuation decreases in value but grows in proportion, because √λ / λ gets larger. This is why small stores are harder to predict, as we will see in chapter 4.

The predictable part. Remove the weight of the day: the weekly wave disappears and only chance remains. Add a December that is 30% stronger, as in exercise 3 of the chapter: these are the regularities that a forecasting model will have to learn.

The same experiment in Python

The chapter’s code, with seed 42. The browser’s generator is not NumPy’s, so the lab’s numbers do not match these one by one.

import numpy as np
import pandas as pd

rng = np.random.default_rng(42)
giorni = pd.date_range("2025-01-01", "2025-12-31", freq="D")
peso_giorno = np.array([0.8, 0.82, 0.88, 0.95, 1.1, 1.65, 0.6])   # Monday to Sunday
attesi = 60 * peso_giorno[giorni.dayofweek]       # the predictable part
scontrini = rng.poisson(attesi)                   # the random part
incasso = scontrini * rng.normal(95, 8, size=len(giorni))

sabati = scontrini[giorni.dayofweek == 5]
print(round(incasso.sum()), sabati.mean().round(1), sabati.std().round(1))   # mean close to 99, fluctuation close to 10

In the book

This lab accompanies chapter 2, “The tools”: Google Colab, Python, NumPy, pandas and matplotlib, just enough for the whole book. The chapter closes with the exploration of Ordito’s real data, born in exactly this way, with many more ingredients.

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