A year in production
A model that lives in a notebook is of no use to anyone. Putting it into production means making it work on its own, every Monday, and noticing when something goes wrong. Workshop B does this with Ordito’s weekly sales model and replays 2025 as if the model had been switched on on 6 January.
Three tools
The first is the checks on the incoming data. A model does not distinguish wrong data from a real change: if the week’s extraction loses the stores, the model forecasts a third of the goods. For this reason the Monday script checks the data before forecasting, and stops when something does not add up.
The second is the log: every forecast kept with its date, horizon and model version, and placed beside the true sales figure when it arrives. Read month by month, it shows where the model is wrong and in which direction.
The third is the Population Stability Index, the PSI, for models whose truth arrives late, such as customer churn: it measures how much the distribution of the scores has changed compared with that of training.
Three experiments
Better no forecast. Choose Monday 6 October 2025 and “solo online” (online only) data: the total collapses to a third of the median of the eight previous weeks and the script stops. Try the other faults: the script always stops, with three different checks in all.
January and July. The worst months are those of the sale seasons, with a deviation of −12%: on the Monday before, the last known week is normal, and the model does not know that sales are about to explode. Retraining every four weeks does not help, because what is missing is a piece of information, not a younger model.
The PSI. Below 0.1 the distribution is stable, above 0.25 it has changed a lot. In 2025 the PSI of the churn model stays below 0.02 all year, and yet from January to June the model underestimates churn by about three points. The PSI sees the customers change, not the link between their habits and churn.
The same experiment in Python
The workshop’s PSI function, tried on simulated scores shifted more and more.
import numpy as np
def psi(riferimento, nuovi, fasce=10):
"""Population Stability Index: how much the distribution of the scores has changed."""
bordi = np.quantile(riferimento, np.linspace(0, 1, fasce + 1))
bordi[0], bordi[-1] = 0, 1
p = np.clip(np.histogram(riferimento, bordi)[0] / len(riferimento), 1e-4, None)
q = np.clip(np.histogram(nuovi, bordi)[0] / len(nuovi), 1e-4, None)
return np.sum((q - p) * np.log(q / p))
rng = np.random.default_rng(0)
riferimento = 1 / (1 + np.exp(-rng.normal(-1.6, 1.2, 30_000))) # “training” scores, simulated
for spostamento in [0, 0.1, 0.3, 0.6]:
nuovi = 1 / (1 + np.exp(-(rng.normal(-1.6, 1.2, 30_000) + spostamento)))
print(spostamento, round(psi(riferimento, nuovi), 3)) # below 0.1 stable, above 0.25 changed a lot
In the book
This lab accompanies Workshop B, “From the notebook to the store”: the module with the functions, the training script with the model card, the Monday script with the checks, a year replayed with three retraining policies, the churn model and the suspicious returns in production, and a checklist valid for any model.
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