π’ The situation
The SuperMegaRetail design doc is approved. Lena:
"Now we fill it with engineering substance. Four sections the book calls the 'early stage': metrics and losses, the dataset, the validation schema, the baselines. Each with a justification of why exactly this way. Remember: a mistake at this stage costs months, because everything downstream is built on these decisions."
π― Your task
- Build a hierarchy of metrics: from the loss to the business metric.
- Design the dataset and answer "how much data is enough".
- Choose the validation schema (including the non-trivial ones: nested, adversarial).
- Build the baseline ladder and understand why the constant baseline matters.
π Theory
The hierarchy of metrics
One metric does not describe a system. In a mature design doc the metrics form a pyramid β from what the gradient optimizes to what the CFO sees:
The pyramid's rules:
- The loss β the metric: the loss must be differentiable and "friendly" to the metric. If under-forecasting hurts the business more β take a quantile loss, not MSE.
- Consistency metrics: the stability of the forecast between runs and versions β the business hates it when Wednesday's order changes by 40% after the nightly recompute.
- The offline β online link is verified by experiments: if an offline gain doesn't move the online metric β the pyramid is torn, and fixing it matters more than improving the model.
The dataset: how much data is enough?
The doc's data sections: sources, ETL, filtering, labeling, metadata.
- The sample-wise learning curve is the main tool for answering "is the data enough": train the model on 10%, 25%, 50%, 100% of the sample and look at the quality trend. Reaching a plateau β enough data; still climbing β data is worth more than new features.
- The chicken-and-egg problem: recommendations need logs, but logs appear after launching recommendations. The solution β launch a simple version (rules/popularity) to start collecting data.
- A healthy data pipeline: idempotency, schema checks, volume alerts, reproducible snapshots.
Validation schemas: standard and non-trivial
| Schema | When |
|---|---|
| Holdout | lots of data, fast iterations |
| K-fold CV | little data, need the estimate's spread |
| Time-series (rolling) | anything with time β like our demand forecast |
| Nested CV | tuning hyperparameters and estimating quality honestly at the same time: the inner loop tunes, the outer measures |
| Adversarial validation | a "does train resemble test?" check: train a classifier to tell train from test. AUC β 0.5 β same world; AUC β 1 β the distributions differ and your validation lies |
Adversarial validation is an underrated trick: it also shows which features distinguish train from prod (the classifier's top features) β those are the future sources of drift.
The baseline ladder
- The constant baseline (mean/median for regression, the majority class for classification, random order for ranking) is a sanity check and the reference point. Spending two weeks on a model and losing to a constant built in 5 minutes is a classic β from which a day-one baseline saves you.
- When a baseline isn't needed (per the book): the cost of error is extreme (medicine β fallback is a human there), the solution is already battle-proven, or you're rebuilding a working system (the old version is the baseline).
- Complexity bias β the cognitive trap "complex = good". The baseline ladder is the organizational cure.