The Counts and Their Holes
One row per camera and minute, a day that follows the prayers, and four kinds of holes to fill.
The table
The data are two files from the Madinah Ethical AI Competition on Kaggle. Thirteen cameras in Madinah each report, once a minute, how many people they see. Stacked, the files give one row per camera and minute:
import os
import numpy as np
import pandas as pd
import crowd
d = crowd.load() # train.csv and test.csv: one row per camera and minute
show = ["recording", "day", "weekday", "unit", "minute_of_day", "people", "kind"]
print(pd.concat([d[d.people.notna()].head(3), d[d.people.isna()].head(3)])[show].to_string()) recording day weekday unit minute_of_day people kind
0 20260904_1105 2026-09-04 Fri cam_B 676 13.103 NaN
1 20260904_1105 2026-09-04 Fri cam_B 677 17.157 NaN
2 20260904_1105 2026-09-04 Fri cam_B 678 23.348 NaN
13447 20260918_1100 2026-09-18 Fri cam_I 844 NaN forecast
13448 20260918_1100 2026-09-18 Fri cam_I 845 NaN forecast
13449 20260918_1100 2026-09-18 Fri cam_I 846 NaN forecast| column | meaning |
|---|---|
recording | one stretch of filming, named by its date and starting time |
day, weekday | the date; every recording falls on a Friday or a Saturday |
unit | the camera, cam_A to cam_M |
minute_of_day | minutes after midnight: 676 is 11:16 |
people | the count; NaN where the value is a hole |
kind | for a hole, which kind of hole it is |
crowd.load() only reads the two files and stacks them. The file crowd.py holds this and a few other helpers that are about the data and not about the model.
Six days of filming
hhmm = lambda m: f"{m // 60:02d}:{m % 60:02d}"
rec = d.groupby(["recording", "weekday"]).agg(
start=("minute_of_day", lambda m: hhmm(m.min())),
end=("minute_of_day", lambda m: hhmm(m.max())),
cameras=("unit", "nunique"),
counts=("people", "count"),
holes=("people", lambda p: p.isna().sum()))
print(rec) start end cameras counts holes
recording weekday
20260904_1105 Fri 11:05 14:30 7 1111 0
20260905_0426 Sat 04:26 08:00 7 1032 0
20260905_1124 Sat 11:24 13:37 7 824 0
20260905_1900 Sat 19:00 21:44 7 955 0
20260911_1100 Fri 11:00 21:14 8 4726 0
20260912_1100 Sat 11:00 21:14 8 4795 0
20260918_1100 Fri 11:00 21:14 13 1927 2334
20260919_1100 Sat 11:00 21:14 13 2227 2123- Two complete days: Friday 11 and Saturday 12 September 2026, from 11:00 to 21:14, with eight cameras (A to H).
- Two days with holes: Friday 18 and Saturday 19 September, with all thirteen cameras. About half of their rows are holes.
- Four short fragments on 4 and 5 September, with seven cameras.
What a day looks like

Two things in this picture shape the whole model.
The day follows the prayers. The call to prayer is the adhan; four of the five daily adhans fall inside the recording: dhuhr (noon), asr (afternoon), maghrib (sunset) and isha (night). The count falls in the quarter of an hour after each adhan, when people go in to pray, and surges about half an hour after it, when they come out.
The cameras differ in size, not in kind.
full = d[d.day.isin(["2026-09-11", "2026-09-12"])] # the two complete days
size = full.groupby("unit").people.agg(["min", "median", "max"]).round(0).astype(int)
print(size.T)unit cam_A cam_B cam_C cam_D cam_E cam_F cam_G cam_H
min 44 3 3 3 56 20 1 3
median 189 23 20 28 235 126 7 14
max 704 77 125 82 999 385 33 59Camera E sees 235 people at its median and camera G sees 7, a factor of more than 30. A surge that doubles the count adds 200 people to one camera and 7 to the other. On the log scale the two surges are the same: doubling adds log 2 = 0.69 to both. So the model describes the logarithm of the count. There, effects that multiply the count become terms that add up, and one term can serve cameras of every size.
Four kinds of holes
On 18 and 19 September the organisers removed values in four ways:
print(d[d.people.isna()].groupby(["day", "kind"]).size().unstack())kind forecast hidden hidden-future missing
day
2026-09-18 1230 564 322 218
2026-09-19 1430 285 162 246| kind | what is missing | what is still known |
|---|---|---|
| forecast | the 15 minutes after a cutoff, for a camera that is on | every camera up to the cutoff |
| hidden | every row of one camera on that day | the other cameras on that day, and this camera on other days |
| hidden-future | the 15 minutes after a cutoff, for a hidden camera | the other cameras up to the cutoff, and this camera on other days |
| missing | a gap of a few minutes | the camera before and after the gap, and the other cameras during it |
Each of the two days has 11 cutoffs. After a cutoff the table is blank for 30 minutes for every camera; the first 15 of them are the holes to fill.

Holes with known truth
The values behind the holes of 18 and 19 September are not public. A model that fills them cannot be checked there. So we make the same holes one week earlier, where every value is known:
- Friday 11 September gets the pattern of Friday 18: cameras B and G hidden.
- Saturday 12 September gets the pattern of Saturday 19: camera D hidden.
- Each cutoff and each gap keeps its distance from the nearest adhan, and is then placed 30 minutes later.
Why 30 minutes later. A forecast can only replay what the model has seen on other days at the same minutes. The two later days are blank for 30 minutes after each of their cutoffs. With our cutoffs at those same minutes, every long day would be blank exactly where the model has to forecast. Moved by 30 minutes, each minute to forecast is one that the later day shows. That matches real use, where the earlier days are complete.
d = d[d.recording != "20260905_0426"] # the fragment at dawn is left out
d, plan = crowd.rehearsal(d) # adds obs, role and rnow
print(crowd.holes(d).groupby(["day", "kind"]).size().unstack())
print()
print("rows", len(d), "| the model may use", int(d.obs.sum()), "| to predict", int((~d.obs).sum()))
os.makedirs("work", exist_ok=True) # the parts save their files here
d.to_pickle("work/table.pkl")kind forecast hidden hidden-future missing
day
2026-09-11 855 622 298 164
2026-09-12 1017 314 148 187
rows 21022 | the model may use 10637 | to predict 10385crowd.rehearsal() adds three columns: obs says whether the model may use the value, role is the kind of hole we made, and rnow is its cutoff. From here on the model sees a count only where obs is true. The values behind our holes are kept aside and used in Parts 6 and 7 to check the predictions.
The fragment at dawn on 5 September is left out: it is far from the hours that have holes.
The code of this part, with the output it printed: 01_data.ipynb. It reads crowd.py and the files the earlier parts saved in work/.