Sub topic 2
Three clocks: event time, ingestion time, and prediction time
This chapter assumes basic supervised machine learning, SQL joins, pandas DataFrames, and timestamps with time zones. You should already know that a feature is an input to a model, a label is the outcome to predict, and a training row represents one prediction case.
A training row is valid only when every feature could have been known at the moment the prediction would have been made. That rule requires three different clocks:
- Event time is when something happened in the real world.
- Ingestion time is when the event or feature reached your data system.
- Prediction time is when the model is expected to produce a prediction.
These times can differ. Confusing them creates temporal leakage, which means training data contains information from the future relative to the prediction.
A single event can have three times
Suppose a customer makes a purchase at 10:00. The source system sends the record at 10:07. Your churn model makes a prediction at 10:05.
| Timestamp | Meaning | Can a model at 10:05 use it? |
|---|---|---|
| 10:00 | The purchase happened: event time | Usually yes, if the feature pipeline had received it |
| 10:07 | The purchase arrived in the feature system: ingestion time | No |
| 10:05 | The model prediction moment: prediction time | This is the cutoff |
Event time describes the world. Ingestion time describes what your system knew and when it knew it. Prediction time defines the information boundary.
A feature may be valid by event time but unavailable by ingestion time. For a strict simulation of production, filter on both clocks:
import pandas as pd
events = pd.DataFrame({
"customer_id": ["c1", "c1"],
"event_ts": pd.to_datetime(["2026-01-10 10:00Z", "2026-01-10 10:03Z"]),
"ingested_ts": pd.to_datetime(["2026-01-10 10:07Z", "2026-01-10 10:04Z"]),
"purchase_amount": [80.0, 25.0],
})
prediction_ts = pd.Timestamp("2026-01-10 10:05Z")
available = events[
(events["event_ts"] <= prediction_ts)
& (events["ingested_ts"] <= prediction_ts)
]
print(available)The 10:00 purchase is excluded because it arrived at 10:07. The 10:03 purchase is available because both its event and ingestion occurred before 10:05.
How the clocks interact
The prediction timestamp belongs to the label row. It is the time at which the model would have acted, not necessarily the time when the label became known. For example, a churn label might become known 30 days after a prediction.
A feature history should retain both event and ingestion timestamps. When constructing a training row, select records satisfying:
event_ts <= prediction_tsingested_ts <= prediction_ts
Then select the newest eligible feature according to the feature's event time. If two records describe the same event, ingestion time can break the tie.
Practical rules
- Store timestamps in UTC, and convert display times only at the edges of your system.
- Name columns explicitly, such as
event_ts,ingested_ts, andprediction_ts. - Do not use a table containing only the latest feature value for historical training.
- Record the time when labels become available separately from prediction time.
- Decide whether your training set models the real system's delayed data or an idealized event-time system. Use the same policy in validation and serving.
Exercise
An event occurred at 09:55, was ingested at 10:10, and the prediction time is 10:05. May the training row use this event?
Show answer
No. Its event time is early enough, but its ingestion time is after the prediction time, so the model could not have known about it.