MODULE 09 ยท Junior+ ยท 90 minutes

0.97 on the test set, 0.61 in production

We investigate someone else's incident: a random split of time-ordered data, a scaler fitted before the split, and a feature that does not exist at decision time.

Open this module in the simulator All 23 lessons

The first two modules are free, no card. The rest are $20/month.

๐Ÿข The situation

Thursday, 11:00. Alarm in #ml-alerts: a neighboring team's scoring model that showed ROC-AUC 0.97 on the test yields 0.61 in production โ€” worse than the old manual rules. CTO Victor demands an investigation. Lena assigns you to the incident group:

"The best way to learn validation is to investigate someone else's failure. Find where exactly they fooled themselves. Look at three things: how they split the data, what got into the features, and when the statistics were computed."

๐ŸŽฏ Your task

  1. Understand overfitting and underfitting through bias/variance.
  2. Master cross-validation and time-based validation.
  3. Build a catalog of data leaks โ€” and find the leak in this incident.

๐Ÿ“š Theory

Overfitting and underfitting

Diagnosis by the gap: train_metric โ‰ซ val_metric โ†’ overfitting. Both low โ†’ underfitting. Andrew Ng: "Look at train error and val error like a doctor at two lab tests โ€” the combination gives the diagnosis."

Overfitting cures: more data, a simpler model, regularization, early stopping. Underfitting cures: a more complex model, better features, longer training.

Diagnosis from two curves: train vs validation early stopping โ€” here train error โ†“โ†“ validation error โ†‘ learning honestly: both curves fall overfitting: memorizing the train-set noise model complexity / training epochs โ†’ error โ†’
While both curves fall โ€” the model is learning; when validation turns up while train keeps falling โ€” noise memorization began. A gap between the curves = overfitting.

Cross-validation

One train/test split is one random estimate. K-fold CV: split the data into K parts, train K times on Kโˆ’1 parts, validating on the remaining one; average. You get both the estimate and its spread.

The data leakage catalog (learn by heart)

  1. Target leakage into features: a feature is a consequence of the target ("number of collector calls" for default).
  2. Leakage through time: features/aggregates computed using the future (not point-in-time).
  3. Leakage through preprocessing: scaler/encoder/imputer fit on all data before the split.
  4. Leakage through duplicates/groups: the same customer in both train and test.
  5. Leakage through feature selection: selection done on all data, then an "honest" CV.

The symptom of all leaks is the same: a suspiciously high offline metric and a production flop.


What to remember

  • The train/val metric gap is the main overfitting indicator.
  • Temporal data is validated by time; a customer's rows are never separated across folds or train/test.
  • A metric that is too good is a reason for alarm, not joy.
  • Preprocessing only inside a Pipeline; features only point-in-time.

Next in this module: Practice: the investigation

A step-by-step walkthrough of the solution, the code and a five-question quiz.

Open the module โ†’

Nearby lessons

08 Churn v2: boosting vs the forest 10 Squeezing out 2% more quality

The whole program โ€” 23 lessons