Point-in-Time Feature Lookups Without Leakage

MLOpsEasy+10 XP+10

Point-in-Time Feature Lookups Without Leakage

To build a training example for something that happened last Tuesday, you need the feature values as they were last Tuesday — not as they are now. Grab today's values and your model trains on information that didn't exist at prediction time, scores brilliantly in testing, and collapses in production. That's label leakage, and it is the single most common way an ML project quietly fails.

A feature store prevents it with point-in-time correct lookups.

Task: write point_in_time_lookup(feature_log, requests) returning one value per request.

  • feature_log is a list of [entity, timestamp, value] entries, in no particular order.
  • requests is a list of [entity, as_of] pairs.
  • For each request, find that entity's most recent log entry whose timestamp is less than or equal to as_of, and return its value.
  • An entry exactly at as_of counts — it was already known at that moment.
  • Anything after as_of must be ignored, however tempting. That's the whole point.
  • If the entity has no qualifying entry — unknown entity, or every entry is in the future — return None for that request.
  • Return one result per request, in the same order.

The discipline this encodes is what makes training data honest: a model that was going to run on Tuesday's information gets trained on Tuesday's information, so the score you measure offline is the score you'll actually get.

Examples

feature_log = [['u1', 5, 100], ['u1', 10, 200], ['u2', 7, 50]]
requests = [['u1', 7], ['u1', 10], ['u2', 6], ['u3', 99]]
returns [100, 200, None, None]
feature_log = [['a', 10, 1.5]]
requests = [['a', 9]]
returns [None]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run