ML & Deep Learning Foundations·Question 35 of 55Intermediate

What goes wrong when you validate a model on time-ordered data, and how do you do it properly?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Random k-fold on time-ordered data is leakage, full stop. It trains on the future to predict the past, scores beautifully, and dies in production.

Full worked answer with diagram

Random k-fold on time-ordered data is leakage, full stop. It trains on the future to predict the past, scores beautifully, and dies in production.

Use walk-forward (rolling-origin) validation: train on [0, t), validate on [t, t+h), roll forward, repeat. Multiple folds, so you see variance across regimes rather than one lucky window. Expanding window if old regimes still apply; sliding window if they do not.

The subtler leaks are where interviews are actually won:

  • Non-causal aggregations. Computing rolling means, target encodings or scaler statistics over the whole series before splitting. Every aggregation must use only data up to t.
  • Label window overlapping the feature window. Predicting "churn in the next 30 days" with features that include day t+5 activity.
  • Data that exists in your warehouse but did not exist then. Late-arriving records, backfilled corrections, restated figures. Your training snapshot is retrospective; serving is not. This one is the killer, and point-in-time correct joins are the fix.
  • No embargo. Leave a gap between train and validation equal to the label horizon. Without it, autocorrelation makes rows either side of the boundary near-duplicates.

Two things I would insist on reporting:

Baselines. Always compare against naive persistence (y_hat_t = y_{t-1}) and seasonal naive. A large fraction of impressive-looking forecasting models do not beat them, and any interviewer who has shipped forecasting knows it.

Metrics per horizon, not averaged. A model can be excellent at h=1 and worthless at h=30, and the average hides exactly the thing the business cares about.

Finally, treat distribution shift as the default rather than a pathology. Retrain cadence is a design parameter, not an afterthought. A model validated on 2024 data facing a 2026 regime change is not overfitting, it is a different problem, and conflating the two sends you optimising regularization when you should be rebuilding the pipeline.

Worth sketching. The embargo gap and the "up to t only" constraint are the two things candidates leave out, and a drawing makes their absence obvious.

flowchart LR
    A["Train on 0 to t"] -->|"embargo equal to<br/>the label horizon"| B["Validate t to t plus h"]
    B --> C["Roll the origin forward"]
    C --> A
    B --> D["Report per horizon,<br/>not averaged"]
    D --> E["Beat naive persistence<br/>and seasonal naive first"]
    F["Every aggregation uses<br/>data up to t only"] --> A

What a good answer covers

  • Random k-fold on time-ordered data is leakage, full stop
  • It trains on the future to predict the past, scores beautifully, and dies in production
  • Use walk-forward (rolling-origin) validation: train on [0, t), validate on [t, t+h), roll forward, repeat
  • Multiple folds, so you see variance across regimes rather than one lucky window
  • Expanding window if old regimes still apply; sliding window if they do not

Key terms: walk-forward (rolling-origin) validation · Non-causal aggregations · No embargo · Baselines · Metrics per horizon, not averaged

Interviewer follow-ups to expect

  1. Your walk-forward folds show wildly different scores. What does that tell you and what do you report to stakeholders?

  2. How do you build a training set when a key feature's values get restated 3 days after the fact?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep