download

Great offline AUC, poor online. Could a feature join leak?

Machine learning~12 minReviewed 29 Oct 2026Free · No sign-in

Question

A fraud model scores payments. One feature is chargebacks: how many disputed payments the user has had so far. A table keeps the history: a new row with the day each time the count changes.

To build the training data, the team joined each labelled payment to the user's latest row. Offline, this feature alone gives an AUC of 1.0. Online, the model is much weaker.

What went wrong? Write the correct join, and compare the feature's AUC both ways.

"CODE · PYTHON"
# user -> [(day the count starts, chargebacks so far)]
history = {"u1": [(1, 1), (14, 3)], "u2": [(1, 0)], "u3": [(2, 1), (17, 2)],
           "u4": [(3, 1)], "u5": [(1, 0), (12, 2)], "u6": [(4, 0)]}
rows = [("u1", 10, 1), ("u2", 10, 0), ("u3", 11, 1),  # user, day, fraud?
        ("u4", 11, 0), ("u5", 9, 1), ("u6", 9, 0)]

# the join the team used: the latest row of each user
latest = [history[user][-1][1] for user, day, _ in rows]
Show hints (3)
  1. "LOOK AT U1"

    u1 paid on day 10 and the payment was fraud. The latest row says 3 chargebacks, from day 14. How many did u1 have on day 10?

  2. "THE EXTRA CHARGEBACKS"

    Fraud leads to disputes some days later. So what do the chargebacks after the payment day really tell the model?

  3. "AS OF THE PAYMENT"

    For each payment, keep only the history rows with day <= payment day, then take the last one. That is the value the system knew at the time.

Show checked explanation

Yes. The join took each user's latest count, so it includes chargebacks that came after the payment, often caused by that very fraud. The feature leaks the label. Join each payment to the value as of the payment time instead. Here the feature's AUC falls from 1.0 to 0.67, which is all it can give online.

"SOLUTION · PYTHON"
# user -> [(day the count starts, chargebacks so far)]
history = {"u1": [(1, 1), (14, 3)], "u2": [(1, 0)], "u3": [(2, 1), (17, 2)],
           "u4": [(3, 1)], "u5": [(1, 0), (12, 2)], "u6": [(4, 0)]}
rows = [("u1", 10, 1), ("u2", 10, 0), ("u3", 11, 1),  # user, day, fraud?
        ("u4", 11, 0), ("u5", 9, 1), ("u6", 9, 0)]
labels = [fraud for _, _, fraud in rows]


def auc(scores):  # chance a fraud row outscores a normal one, ties half
    pairs = [(s, t) for s, a in zip(scores, labels)
             for t, b in zip(scores, labels) if a > b]
    return sum((s > t) + (s == t) / 2 for s, t in pairs) / len(pairs)


latest = [history[user][-1][1] for user, day, _ in rows]
as_of = [[c for start, c in history[user] if start <= day][-1]
         for user, day, _ in rows]
print("latest:", latest, f"AUC {auc(latest):.2f}")
print("as of: ", as_of, f"AUC {auc(as_of):.2f}")
"OUTPUT"
latest: [3, 0, 2, 1, 2, 0] AUC 1.00
as of:  [1, 0, 1, 1, 0, 0] AUC 0.67

Code run on CPython 3.12 against the example above. Checked by an editor other than the author.

Walkthrough

The latest row is today's value, not the payment day's. For u1 the latest count is 3, but on day 10 it was 1. The two extra chargebacks came on day 14, after the payment. They are most likely disputes about this very fraud. The feature carries the label back in time.

userfraud?latestas of payment day
u1yes31
u2no00
u3yes21
u4no11
u5yes20
u6no00

AUC is the chance that a random fraud row scores higher than a random normal row, with ties counting half. With the latest values, every fraud row (2 or 3) beats every normal row (0 or 1): AUC 1.0. As of the payment day, fraud rows have 1, 1, 0 and normal rows 0, 1, 0: AUC 0.67. When a payment arrives online, the future rows don't exist yet. So 0.67 is the honest number.

A point-in-time join (or as-of join) takes, for each training row, the last value known at prediction time.

A time-based train/test split doesn't save you. The leak is inside each row, so train and test are both inflated.

Be most careful with features that the outcome itself changes: chargebacks, refunds, a "blocked" status, or the last login date in a churn model. For each feature, ask: could the system have known this value at prediction time?

Common mistakes

  • Checking only the label for leaks. Here the label is clean. The leak comes through a feature that the outcome changes later.
  • Comparing dates when events have times. A chargeback later on the payment day is still the future for that payment. Compare full timestamps.
  • Overwriting the feature table in place. Without history rows you can't rebuild past values. Keep every change with its time, or log features when you serve them.
  • Ignoring a feature that looks too good. An AUC of 1.0 from one feature is a red flag. Check when its values were written.

Follow-up questions

  • "A chargeback happened on day 8 but reached the table on day 12. Which day counts?" Day 12, if serving reads this table. On payment day 10 the system could not see it yet. Keep two times per row: when the event happened and when it became available. Join on availability. Event time still decides windows like "the last 30 days".
  • "How would you catch this before launch?" Log the feature values the service uses. Rebuild them for the same requests with your offline join and compare. If they differ, you train on data the model never sees online.

What a strong answer covers

Spots that the join used values written after the prediction, so the outcome leaked into a feature. Fixes it with a point-in-time join. Knows event time from availability time, and checks suspiciously strong features first.

Open in interactive practice deck →

Original OfferVibe question. Topic idea from Inside the Machine Learning Interview (Peng Shao, 2023); text, examples and code are our own.
© 2026 OfferVibe · Text CC BY-NC-SA 4.0 · code MITFree to share and adapt with credit, not for commercial use. Code samples are free for any use.