AlgoViz

Predictive ML features and feedback

hard 7 min

A predictive model learns from historical examples, but at serving time it sees only information that has arrived by the decision.

Video lesson · Chapter 1 of 4

The fraud clue that arrived tomorrow

0:00 / 4:15

Theory

Read or listen first. About 2 min.

What it is

A predictive model learns from historical examples, but at serving time it sees only information that has arrived by the decision. Construct each training example using an entity key, prediction time and features that would have been available then. Late outcomes supply labels later. An ordinary join to the latest account row can accidentally teach the model about tomorrow.

Why it exists

Maintain an offline store for historical reconstruction and an online store for low-latency feature lookup. Consistent definitions help, but ingestion lag, late correction, missing values and different transformations can still produce skew. Validate by logging permitted serving features and replaying the same timestamps. A release also needs a simple baseline, calibration, a threshold tied to error cost and an outcome that will eventually be observable.

Could the fraud model know this at purchase time?

Timestamped events → Historical join (versioned features). Timestamped events → Feature service (live updates). Historical join → Feedback monitor (training baseline). Feature service → Feedback monitor (served predictions)
Timestamped events → Historical join (versioned features). Timestamped events → Feature service (live updates). Historical join → Feedback monitor (training baseline). Feature service → Feedback monitor (served predictions)

Inside this chapter

Chapter sources
Event time and availability time
A transaction may occur at 09:55 and arrive at 10:04. For a decision at 10:00, an offline join must respect both the chosen event definition and actual availability. Split validation by time and keep the label horizon outside the feature window.

Every feature value has two timestamps: when the event happened and when the system actually knew about it. A point-in-time join for a prediction at time t takes, for each feature, the latest value whose availability time is at or before t. Ignoring availability lets late-arriving data leak into training, so offline accuracy looks better than anything the live system can achieve. Validate with time-based splits, never random ones.

Example. A chargeback recorded two days later belongs in the target column. Joining it into the feature vector makes offline fraud detection implausibly easy.

Another example. A delivery-time model uses "driver assigned" as a feature. Historically the assignment row was often written after the estimate was shown to the customer, so the model learned from information it would not have live.

Which rows may the 10:00 decision use?

RecordEvent timeAvailable atUsable as feature?
Balance update09:5809:58yes
Card transaction09:5510:04no, arrived late
Chargeback10:00 purchasetwo days laterno, label only
Join on availability time as well as event time.
Calibrated decisions under imbalance
Calibrate predicted probabilities on representative held-out examples. Tune the operating threshold using the relative cost of false approvals and false declines. Accuracy can be high for a model that never flags rare fraud.

With rare positives, accuracy is dominated by the majority class, so it says little. Calibration means a score of 0.1 really corresponds to about one in ten positives among similar cases; check it with reliability plots on held-out recent data and per cohort. Once scores are calibrated, the threshold becomes a business decision based on the cost of each error type and on review capacity.

Example. If a cohort receives risk 0.1, roughly one in ten should be positive over enough comparable cases. A policy can still send that cohort to review rather than reject.

Another example. A churn model's scores are uncalibrated, so a 0.3 means a 10% chance in reality. Retention offers sent at a 0.3 cut-off reach three times more customers than the budget planned for.

Accuracy on a rare event

ModelFlagsFraud caught (of 10 in 1,000)Accuracy
Never flag0099.0%
Calibrated, threshold 0.0540896.6%
Illustrative counts. The useful model has lower accuracy because it trades false alarms for catches.
Ranking and exposure feedback
Candidate generation narrows the catalog, a ranker scores candidates, and business rules select what users see. Click labels exist mainly for exposed items. Log impressions and position, handle cold start and compare changes with randomized exposure where suitable.

Recommendation systems learn from the clicks their own past rankings produced. Items shown at the top get clicks partly because of position, and items never shown get no signal at all. Log impressions with position and the policy that chose them, correct for position bias where possible, and keep a small randomised exploration slice so the data contains evidence about items the current model would not choose.

Example. A newly listed item has no clicks because it was never displayed. Treating that as strong evidence of irrelevance compounds the feedback loop.

Another example. A job board's new listings sink because they start with no applications. A 5% exploration slot that randomly promotes fresh listings gives the ranker enough impressions to judge them.

Ranking pipeline and its feedback loop
  1. 1Candidate generationcatalogue to 500 items
  2. 2Rankerscores the 500
  3. 3Business rulesfilters, diversity
  4. 4Shown to usertop 10 with positions
  5. 5Click logslabels only for shown items
Repeat: back to Candidate generation

Unshown items never earn clicks, so the next model learns less about them.

Cold start and exposure bias in ranking
A new item has no interaction history. Generate candidates from content or a prior and record which items were shown, their position, and the assignment policy. Clicks reflect exposure as well as relevance. Compare a time-split baseline and use appropriately randomized traffic to assess changes.

For a new item, use content features (text, category, price) or a prior from similar items to place it into candidate lists, then let controlled exploration gather real impressions. When evaluating a ranking change, compare against a time-split baseline and, where it is acceptable to the business, randomised traffic, because offline evaluation on logged clicks favours whatever the old ranker already showed.

Example. An item at rank one accumulated 80 clicks and an unseen item none. Logging eligible candidates and sampled exposures lets reviewers distinguish missing opportunities from observed rejection.

Another example. A podcast app adds a new episode with 0 plays. Its embedding sits close to a popular series, so it enters candidate lists for that series' listeners, and its first 1,000 impressions decide its later ranking.

No clicks: rejected or never seen?

Logged impressions and positions make this distinction possible.
Calibrated predictions and error costs
Estimate how often an event occurs among examples assigned similar probabilities and monitor that relationship by cohort. Choose a decision threshold using measured costs, capacity and delayed labels. High accuracy on a rare event can coexist with zero detections.

If blocking a good order costs C_FP and accepting a fraudulent one costs C_FN, blocking is worthwhile when p x C_FN exceeds (1 - p) x C_FP, which rearranges to the threshold above. It only works when p is calibrated. In practice review capacity, customer experience and shifting fraud rates move the operating point, so monitor calibration by cohort once delayed labels arrive.

Example. If blocking a legitimate order costs 5andacceptingfraudcosts5 and accepting fraud costs 95, the simplified risk-neutral break-even probability is 5/(5+95) = 0.05. Review queues and changing fraud rates can shift the operating point.

Another example. If a manual review costs 2 and catches fraud reliably, a third option appears: approve below about 0.02, review between about 0.02 and 0.6, and block above 0.6. The bands come from the same cost arithmetic, assuming review is accurate.

Break-even threshold from error costs

p∗=CFPCFP+CFN=55+95=0.05p^{*}=\frac{C_{\rm FP}}{C_{\rm FP}+C_{\rm FN}}=\frac{5}{5+95}=0.05
Block when calibrated risk exceeds 0.05 under this simplified risk-neutral model. Costs from the example.

How it works

Step through the idea, or press Play.

Step 1 of 4

Timestamped events. Purchase at 10:00

Understand it

Worked example

Could the fraud model know this at purchase time?

  1. 1

    Purchase at 10:00

    The ledger records event and arrival times. A later fraud report labels this transaction after the prediction has already been served.

  2. 2

    Select the 09:58 available balance

    Join each decision to the most recent eligible feature version. Keep the later chargeback solely as a label.

  3. 3

    Replay the same entity and time

    Compare the logged serving vector to the reconstructed vector and inspect freshness, defaults and transformation versions.

  4. 4

    Score after the label window closes

    Estimate precision, recall, calibration and business costs by cohort. A shift in inputs is an investigation signal, not proof of worse accuracy.

Follow the handoffs

Maintain an offline store for historical reconstruction and an online store for low-latency feature lookup. Consistent definitions help, but ingestion lag, late correction, missing values and different transformations can still produce skew. Validate by logging permitted serving features and replaying the same timestamps. A release also needs a simple baseline, calibration, a threshold tied to error cost and an outcome that will eventually be observable.

Training join versus serving lookup

Replaying the same entity and time in both stores should yield the same vector.

Point-in-time join

  • Uses the 09:58 balance available before 10:00
  • Chargeback stays in the label column
  • Offline score is reproducible live

Join to latest row

  • Uses balances updated after the purchase
  • Can pull in post-fraud account changes
  • Offline score is unreachable in production

Summary

The whole topic in one minute.

The serving system did not have that information at decision time. Including it creates leakage and an offline score that cannot be reproduced.

Maintain an offline store for historical reconstruction and an online store for low-latency feature lookup. Consistent definitions help, but ingestion lag, late correction, missing values and different transformations can still produce skew. Validate by logging permitted serving features and replaying the same timestamps. A release also needs a simple baseline, calibration, a threshold tied to error cost and an outcome that will eventually be observable.

Sources