Checking the Predictions
Are the intervals honest, how far off is the median, where does the model fail, and what did each term explain?
Two checks
For the holes we made on 11 and 12 September the true counts are known. There are 3,605 of them. Two questions are asked of every kind of hole:
- Are the intervals honest? A 95% interval should contain the truth about 95 times in 100.
- How far is the prediction off? We take the distance between the predictive median and the truth, as a share of the truth, and report its median: the typical error.
import json
import numpy as np
import pandas as pd
v = pd.read_pickle("work/part6_holes.pkl") # the holes, their truth and their predictionsv["inside"] = v.y.between(v.lo, v.hi) # is the truth inside the 95% interval?
v["error"] = (v.pred - v.y).abs() / v.y # distance of the median from the truth
print(v.groupby(["day", "kind"]).agg(holes=("y", "size"), inside=("inside", "mean"),
typical_error=("error", "median")).round(2)) holes inside typical_error
day kind
2026-09-11 forecast 855 0.97 0.13
hidden 622 0.96 0.18
hidden-future 298 0.93 0.19
missing 164 0.98 0.06
2026-09-12 forecast 1017 0.96 0.15
hidden 314 0.92 0.20
hidden-future 148 0.92 0.20
missing 187 0.97 0.10Reading the result.
- The 95% intervals contain the truth in 92% to 98% of the holes. They mean roughly what they say, for every kind of hole.
- The typical error is smallest for short gaps (about 8%), where the camera is seen on both sides.
- It is about 14% for the 15-minute forecasts.
- It is largest, 18% to 20%, where the camera is not seen at all that day. The hidden cameras are also small ones (7 to 28 people at the median), where a few people are a large share of the count.
Where it fails
An average hides the worst cases, so we look at one. At 12:55 on Saturday 12 September, camera A is at the top of the surge that follows the noon prayer:
whole = lambda col: col.round(0).astype(int)
f = v[(v.unit == "cam_A") & (v.day == "2026-09-12") & (v.now == 775)].copy() # made at 12:55
f["ahead"] = (f.minute_of_day - f.now).astype(int)
f = f[f.ahead.isin([1, 5, 10, 15])]
print(pd.DataFrame({"minutes ahead": f.ahead, "median": whole(f.pred), "from": whole(f.lo),
"to": whole(f.hi), "count": whole(f.y)}).to_string(index=False)) minutes ahead median from to count
1 408 328 508 345
5 395 271 577 281
10 349 216 563 227
15 287 168 491 196
Reading the result. The last count the model saw was 404. Its forecast for the next minute is 408, and the count was 345; after 15 minutes the forecast is 287 against a count of 196. The truth stays inside the interval, but near its lower edge all the way.
The grey lines show why. On the other two Saturdays the crowd stayed near its peak a few minutes longer before it left. The model has learned the typical day from those days. On 12 September the crowd had already begun to leave, and the model read the high count as a large crowd that would leave on the usual schedule.
This is the limit of the model, not a fault of the fit: it places every surge by the prayer clock of the days it has seen, and it has no term for a day that runs a few minutes early or late.
What each part explained
Every part saved the standard deviation of what its model left unexplained. Together they show where the variation in the table lies:
part = lambda k: json.load(open(f"work/part{k}.json"))
steps = [("nothing: the sd of the log count", part(2)["sd"])]
steps += [("2: " + name, sd) for name, sd in part(2)["left"].items()]
steps += [("3: the typical day", part(3)["prayer clock, a curve per weekday"][0])]
steps += [("4: " + name, sd) for name, (sd, waic) in part(4).items()]
steps += [("5: what is different today", part(5)["left"])]
print(pd.DataFrame(steps, columns=["after Part", "sd left"]).round(3).to_string(index=False)) after Part sd left
nothing: the sd of the log count 1.315
2: a level per camera 0.612
2: and a level per day 0.593
3: the typical day 0.423
4: a curve per camera 0.304
4: and its Friday-midday curve 0.192
4: and its level on the weekend 0.189
5: what is different today 0.145Standard deviations do not add up, but variances do. Of the variance of the log count,
- the camera levels explain 78%,
- the day levels and the typical day explain 11%,
- the camera's own shape, with Friday midday and the weekend level, explains 8%,
- what is different today explains 0.8%,
- and 1.2% is left as noise.
Most of what a camera counts is decided by which camera it is and what time of day it is. What is different today is a small part of the variance. It is also the part that matters most for the next 15 minutes.
The whole model
With every term introduced, the model can be written in one line:
| term | what it is | pyINLA model | part |
|---|---|---|---|
| ac, bd | level of the camera, of the day | iid | 2 |
| f | typical Friday and Saturday | rw2, replicate | 3 |
| gc, jc | the camera's own shape; Friday midday | iid with group AR(1); weights | 4 |
| ec,w | level of the camera on a weekend | iid | 4 |
| Z, P, U | today: all cameras, plaza, own camera | iid with group AR(1); weights | 5 |
| ε | counting noise | Gaussian with scale | 5 |
Limitations
- Two days with known truth, used during development. The structure of the model was settled while looking at these two days, and the hidden kind rests on three camera-days. The check above is not a clean out-of-sample test.
- No term for timing. As shown above, a day that runs early or late is forecast badly around its surges.
- Few days. Each weekday curve rests on two long days and some fragments. Cameras I to M are seen on one Friday and one Saturday only.
- Hyperparameters held at their most likely values. The intervals ignore the uncertainty about the hyperparameters.
- Log scale with Gaussian noise. This suits the table because no count is zero. A table with zeros would need a count likelihood such as the Poisson or the negative binomial.
What to take away
- Build the model one term at a time. Each term answered a question about the data, and what the last model left unexplained said what to ask next.
- Let the data choose. Wall clock or prayer clock, one curve or two: both versions were fitted and compared.
- Read the fit. Standard deviations say how large each source of variation is, half-lives say how long a surprise lasts, and every term is a curve or a level that can be drawn.
- A hole is an empty cell. The same fit fills a hidden camera, a gap and, with the later rows hidden, the next 15 minutes.
- Every prediction is a distribution. It gives an interval and the probability of any event of interest, and its intervals can be checked.
References
- Rue, H., Martino, S. and Chopin, N. (2009). Approximate Bayesian inference for latent Gaussian models using integrated nested Laplace approximations. Journal of the Royal Statistical Society: Series B, 71(2), 319-392.
- Simpson, D.P., Rue, H., Riebler, A., Martins, T.G. and Sørbye, S.H. (2017). Penalising model component complexity: a principled, practical approach to constructing priors. Statistical Science, 32(1), 1-28.
- Sørbye, S.H. and Rue, H. (2017). Penalised complexity priors for stationary autoregressive processes. Journal of Time Series Analysis, 38(6), 923-935.
- Watanabe, S. (2010). Asymptotic equivalence of Bayes cross validation and widely applicable information criterion in singular learning theory. Journal of Machine Learning Research, 11, 3571-3594.
- Madinah Ethical AI Competition, Kaggle, 2026. Source of the data.
The code of this part, with the output it printed: 07_checking.ipynb. It reads crowd.py and the files the earlier parts saved in work/.