Sub topic 11
Point-in-time correctness for time-dependent features
This chapter assumes you can build a feature table with a primary key and a time series column, define a FeatureLookup, and create a training set. If not, review those chapters first.
The leakage problem
Some features change over time, such as a user's order count or last login. A labeled event happens at a specific moment. If you join that event to the latest feature values, the model sees information from after the event. This is label leakage. The model scores well in training and then performs worse in production, where only past data exists.
Point-in-time lookup fixes this. For each labeled row, it returns the most recent feature values with a timestamp at or before the event's timestamp.
How it works
You need two things:
- A feature table with a time series column, declared when you create it. The column is part of the primary key.
- A
timestamp_lookup_keyin theFeatureLookup. It names the column in your labeled DataFrame that holds the event time.
from databricks.feature_engineering import FeatureEngineeringClient, FeatureLookup
fe = FeatureEngineeringClient()
fe.create_table(
name="main.ml.user_activity_features",
primary_keys=["user_id", "feature_ts"],
timeseries_columns=["feature_ts"],
df=activity_features_df,
)
lookup = FeatureLookup(
table_name="main.ml.user_activity_features",
lookup_key="user_id",
timestamp_lookup_key="event_ts",
)
training_set = fe.create_training_set(
df=labeled_events_df, # user_id, event_ts, label
feature_lookups=[lookup],
label="label",
)Here activity_features_df and labeled_events_df are DataFrames you have already built. The feature table holds several rows per user, one for each feature_ts. The lookup matches on user_id, then picks the row with the latest feature_ts that is not after event_ts.
Worked example
Suppose user 7 has these feature rows:
| feature_ts | order_count |
|---|---|
| 2026-01-01 | 2 |
| 2026-02-01 | 5 |
| 2026-03-01 | 9 |
A labeled event for user 7 occurs at 2026-02-15. The point-in-time lookup returns the 2026-02-01 row, so order_count is 5. A plain join on user_id would produce three rows or an arbitrary one, and could include the value 9, which was not known at the time.
Common errors
- Time series column missing from the table. If you did not pass
timeseries_columnsat creation, the table cannot be used with a timestamp lookup key. - Wrong column in the label data.
timestamp_lookup_keymust name a column in the labeled DataFrame, not in the feature table. - Feature timestamps that record when computation ran. A value computed on March 2 about February activity should carry a timestamp that reflects when it became available. Otherwise the lookup still leaks.
- Event timestamps in a different time zone or type. Make both columns the same timestamp type and zone.
- Sparse snapshots. If no feature row exists at or before the event, the features are null. Handle these rows deliberately instead of dropping them silently.
Exercise
A feature table has rows for user 3 at 2026-05-01 and 2026-06-01. A labeled event for user 3 occurs at 2026-05-20. Which row does a point-in-time lookup return, and why?
Show answer
The 2026-05-01 row. It is the latest row with a timestamp at or before the event time. The 2026-06-01 row is later than the event, so using it would leak future information.