A simulated store
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.
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.
The “Inside Ordito” series
- Chapter 1 The line of the five stores
- Chapter 2 A simulated store
- Chapter 3 Where the leak hides
- Chapter 4 The valley of the five stores
- Chapter 5 The threshold
- Chapter 6 Why was it returned?
- Chapter 7 Build a tree
- Chapter 8 Boosting step by step
- Chapter 9 The margin
- Workshop A Price is place
- Chapter 10 Shapley by hand
- Chapter 11 Rotate the cloud
- Chapter 12 Groups and dense areas
- Chapter 13 Isolating a point
- Chapter 14 Naive forecasts
- Workshop B A year in production
- Chapter 15 The ink stain
- Chapter 16 Backpropagation