Sub topic 9
Point-in-Time Correct Joins and Avoiding Label Leakage
Assume you know Python, pandas DataFrames, basic machine learning terms, and the difference between training and inference. This chapter focuses on how Feast selects feature values for historical training rows.
Why the timestamp matters
A training row represents what was known at a particular time. Its features must come from that time or earlier. A point-in-time correct join selects the latest feature value available before each entity row's timestamp.
Suppose a model predicts whether a driver accepts a trip:
| driver_id | prediction time | label | valid feature value |
|---|---|---|---|
| 1001 | 12:00 | 1 | acceptance rate from 11:55 |
| 1001 | 12:00 | 1 | not acceptance rate from 12:05 |
The 12:05 value is unavailable when the prediction is made. Including it creates label leakage, which happens when training data contains information that would not be available at prediction time. Leakage makes evaluation look better than real production performance.
A feature source therefore needs an event timestamp. The timestamp describes when the feature value was true or became available. The entity DataFrame also needs an event_timestamp column that describes the prediction time for each row.
How Feast performs the historical join
Feast's get_historical_features uses the entity rows and the registered feature definitions. For each entity key, it finds feature values whose timestamps are no later than that row's event_timestamp. It then selects the appropriate latest value, subject to the feature view's time-to-live, or TTL.
from datetime import datetime
import pandas as pd
from feast import FeatureStore
store = FeatureStore(repo_path=".")
entity_df = pd.DataFrame(
{
"driver_id": [1001, 1001],
"event_timestamp": [
datetime(2025, 1, 1, 12, 0),
datetime(2025, 1, 1, 13, 0),
],
"accepted": [1, 0],
}
)
training_df = store.get_historical_features(
entity_df=entity_df,
features=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:acc_rate",
],
).to_df()
print(training_df)The accepted column is the label. Feast treats the other entity columns as input context and joins feature values to each row's timestamp. The resulting DataFrame can be passed to a training pipeline after separating labels from features.
Common leakage mistakes
- Using the time when a record was processed instead of when the underlying event occurred.
- Omitting
event_timestampfrom the entity DataFrame. - Computing an aggregate over all history, including events after the prediction time.
- Joining features by entity key only and ignoring time.
- Treating a feature that arrives late as available at its event time without checking pipeline delays.
- Using a feature view with a TTL that is longer than the period in which the feature remains useful.
A point-in-time join prevents future timestamps from entering a row. It cannot correct a source whose timestamps are wrong or an aggregate that was calculated with future data before Feast received it.
Checking the result
Inspect several rows manually, especially rows near feature updates. For each training row, verify that every feature's source timestamp is no later than the entity timestamp. Compare training-time feature definitions with the definitions used during online inference. The same feature name should represent the same calculation and meaning in both paths.
Exercise
A prediction row has event_timestamp 10:00. The feature source contains values at 09:50 and 10:10. Which value should the historical retrieval use, assuming both are within the TTL?
Show answer
It should use the 09:50 value. The 10:10 value is future information and would cause label leakage.