Lion Cipher Lab

Catch training-serving skew in a phishing model's feature pipeline, before it ships

Why it matters

A phishing model is trained in one place and used in another. The data scientist computes features in a notebook or batch job over historical mail. The mail gateway computes them again, live, in code someone else wrote from a design doc. If those two pieces of code disagree, even slightly, the model in production is scoring numbers it never saw in training. This is TRAINING-SERVING SKEW. Google's Rules of Machine Learning names it as a common production failure, and the ML Test Score paper calls the test for it 'perhaps the most important and least implemented'. Nothing crashes. Accuracy on…

What you'll learn

Steps in this lab

  1. The words first: features, pipelines, and training-serving skew
  2. Set up: a terminal, Python, numpy and scikit-learn
  3. Generate a synthetic mailbox
  4. Two pipelines, one feature list, seven differences
  5. Measure BEFORE: same model, same emails, two pipelines
  6. Fix 1: a feature parity test on a golden set
  7. Honest negative 1: a parity test only covers its golden set
  8. Fix 2: one shared feature function for training and serving
  9. Honest negative 2: shared code still skews when the input arrives differently
  10. Fix 3: log serving features and compare their distributions to training
  11. Honest negative 3: a skew that keeps the distribution, and the row-level check that catches it
  12. Do it better: the layered setup, and when each layer is worth it

Open the full interactive lab →