05 · Models and training

Building a baseline

8 min read

A baseline is the simplest decision rule that could do the job, written down and measured before any learned model is tried. It is the yardstick every later model is compared against, and it decides whether the extra cost of a cleverer model is worth paying. Building it is also the first time data flows through the whole system, so it exposes broken data before a complicated model can hide it.

An everyday example

A town wants to hire a weather forecaster. Before paying anyone, the mayor writes down the cheapest rule she can think of, which is that tomorrow will be the same as today. Assume that in this town the rule is right, within a couple of degrees, on about seven days in ten, and that it costs nothing to run.

Any forecaster the town interviews now has a number to beat. A candidate with expensive instruments who is right on seven and a half days in ten has bought the town half a day a week for a salary, and the mayor can decide whether that is worth paying. The learned model is the forecaster, the same-as-today rule is the baseline, and the comparison only counts when both are scored on the same days.

A forecaster works alone, while a model sits inside a system that collects data, prepares inputs and delivers answers, and that is where the analogy stops matching. The baseline is the first thing to run through all of those pipes, and that second job, testing the plumbing, has no counterpart in the weather story, so it gets its own section below.

Choose a reference that fits the task

The reference should match the task and, where possible, the way the decision is made today. For a recommendation system the reference is the list of the most popular items the person is allowed to see. For a delivery time estimate it is the average time this route took in the past. Comparing a learned model against that rule shows whether the extra information the model uses improves a decision the business cares about.

A model that always predicts the most common category is the weakest baseline, and it is useful as a sanity check when one class is rare. If two percent of payments are fraud, a rule that calls every payment honest is 98 percent accurate and catches nothing, which is why accuracy alone is a poor yardstick on rare events. Where humans make the decision today, measure them instead. If a review team already checks payments, record how many they clear in an hour and how often they are wrong, because that is the number the model has to beat.

Keep a reference for every comparisonCompare results, Same test examples. Baseline, Simple reference. New candidate, Proposed change. Both models are scored on the same test examples before they are compared.Keep a reference for every comparisonBaselineSimple referenceNew candidateProposed changeCompare resultsSame test examples
Both models are scored on the same test examples before they are compared.On a narrow screen, scroll the figure sideways to see every step.
Choose a reference that fits the task
TaskStarting pointWhat it helps test
RecommendationsMost popular eligible itemsWhether knowing the person adds anything
SpamA few rules plus a simple classifierLabel quality and the cost of false alarms
Delivery timeAverage past time for the routeWhether live traffic improves the estimate

Use the baseline to test the pipeline

Train the simple model on a proper split of the data, keeping the examples it is judged on apart from the ones it learns from, run the same input preparation when it answers live requests, and record what it predicted and what then happened. Doing this forces decisions about data formats, version numbers, missing inputs, response time and measurement before a complicated model arrives and hides them. A baseline that takes a week to wire up has told you where the week went, and the learned model will need the same pipes.

The baseline also reads the data for you. If a plain linear model, which adds up weighted inputs, cannot learn a signal that anyone can see in a spreadsheet, the labels, the joins or the transformations are broken somewhere. The opposite result is a warning too. A baseline that is nearly perfect has usually been handed the answer through a leaked input, which is a value that was recorded after the outcome it is meant to predict. A small model makes both problems easy to find because its few inputs can be inspected one by one.

The baseline is the first thing through every pipeCollect data, Logs and labels. Prepare inputs, Same code twice. Simple model, Inspect each input. Measure, Predictions and outcomes. Every box has to work before the last one produces a number.The baseline is the first thing through every pipeCollect dataLogs and labelsPrepare inputsSame code twiceSimple modelInspect each inputMeasurePredictions andoutcomes
Every box has to work before the last one produces a number.On a narrow screen, scroll the figure sideways to see every step.

Upgrade to solve an observed limitation

Suppose a logistic regression spam model, which weighs each word and phrase on its own, handles the common phrases but misses the combination of a brand-new sender and a message full of links. A tree model, which sorts examples with a series of yes-or-no questions and can learn such combinations, is a reasonable next experiment. State the limitation the new model is meant to fix before naming the model, because the limitation is the hypothesis and the model is one way to test it.

Compare the two on the same examples and at the same operating point, which is the cutoff where the system starts to act. Suppose the rules baseline flags 1,000 payments a day and 300 of them turn out to be fraud, so three in ten flagged payments are fraud. A candidate model that also flags 1,000 payments but finds 450 cases has caught 150 more frauds a day at the same review workload. If instead it finds 450 cases by flagging 2,000 payments, the gain came from doubling the review team, which is a different decision with a different cost.

The comparison also has to include response time, memory, training cost and the work of maintaining any new inputs. Keep the baseline running after the new model wins, because it remains an understandable reference on the same task and, once tested in that role, a safe thing to fall back on when the new model fails.

Two ways to catch 150 more frauds a dayCandidate model, 450 frauds found. Same 1,000 flags, A better model. 2,000 flags, A bigger review team. Only the top branch is a model improvement.Two ways to catch 150 more frauds a dayCandidate model450 frauds foundSame 1,000 flagsA better model2,000 flagsA bigger review team
Only the top branch is a model improvement.On a narrow screen, scroll the figure sideways to see every step.

Where people get confused

Newcomers tend to treat the baseline as a lesser answer to be apologised for. Interviewers hear it the other way round, because a candidate who names a yardstick has shown how every later claim will be measured. The baseline is the first result, and the model is the second.

Beating random guessing is also believed to mean something. On rare events random guessing and the always-honest rule are both easy to beat. The only comparison that matters is against the decision the business makes today, whether that is a rule, a review team or nothing at all.

Dropping the baseline once a better model ships is the confusion that shows up months later. Without it, the next comparison has no fixed reference, and a slow decline in data quality can hide behind two models that both got worse together.

In the interview

In a 45-minute design round the baseline takes about two minutes, inside the ten minutes given to modelling. Bring it up with one sentence that names the reference and promises that every model you propose will be measured against it on the same data, then move to the model that fixes the baseline’s first failure.

If the interviewer wants to hear the sophisticated model first, name it and promise the baseline comparison in the evaluation phase, because that comparison is what the follow-ups come back to when it is missing.

Interview questions

The interviewer asks for a sophisticated recommendation system. Does starting with popularity look too simple?

I would say that popularity is my reference and my answer for people with no history, and then describe the personalized model I would measure against it. The baseline is how I show that personalization is worth its cost, so it belongs in the design rather than apologised for.

Then I would name where popularity fails, such as a catalogue of two million items where the top 100 cover a tiny share of what people watch, and tie the personalized model to that failure. If it lifts clicks per person by a few percent over popularity on the same users, the extra serving cost has a number to argue against.

How would you know that your baseline is too strong?

A baseline that is nearly perfect on a hard problem is a warning rather than a win. If a plain linear model separates fraud from honest payments with almost no errors, I would assume one of its inputs was recorded after the outcome, such as a chargeback flag that only exists once the fraud is known.

I would check when each input became available relative to the moment of prediction, remove anything from the future, and expect the score to fall to something believable before trusting any model on that data.

The business already runs a rules engine for fraud. Do you still need a baseline?

The rules engine is the baseline, and the first job is to measure it. I would record how many payments it flags a day, how many of those are fraud and how many frauds it misses, on the same weeks I will test the model on.

If the rules flag 1,000 payments a day and 300 are fraud, a model has to find more fraud at the same 1,000 flags, or the same fraud at fewer flags, to be worth the pipeline it needs. Beating the rules is the claim, so the rules have to be measured first.

What to practice next

Design these systems on the canvas and get your design graded.

These problems build the three baselines from this topic by hand, so you can see what the always-most-common rule, a popularity list and a simple average predictor get right and wrong before any learned model is involved.