Part 4 of 4 · Chapter 4 of 4

Baselines

Before you can say a model is good you need something for it to be better than. Race four models against a rule a child could write, and find out which ones lose.

Beginner11 min read

Worth reading first: Measuring a Model


Somebody tells you their model is 87% accurate. You cannot tell from that sentence whether they have done something impressive or wasted a fortnight, and neither can they. A score on its own carries no information. It only means something next to the score of something stupid.

Better than what?

Every number in this track has been a comparison in disguise. 82.5% for the forest meant something because a single tree managed 72.5%. The 98.1% in the last chapter meant nothing, and you could only tell because you knew that flagging nothing at all scored 98.1% too.

A baseline is the stupidest thing that could possibly work, built first and deliberately. Not a simpler model — a rule so trivial that beating it proves nothing, and failing to beat it proves something rather serious.

Building it first matters more than the number it produces. A baseline forces you to load the data, split it honestly, run a prediction and score it before you have written a model, which means the whole apparatus is working and debugged while there is still nothing to blame it on.

The four you should always run

Say the commoner answer. Look at which outcome is more frequent and predict it every time, ignoring all input. For a classifier this is the floor.

Guess at the right rate. Predict at random in the proportions the training data showed. This is always worse than the majority rule, and running it once is the fastest way to understand why chance is not the bar to clear.

One rule on one column. Try every feature at every cut-off, keep the single best if-statement. This is a decision stump: a decision tree that was stopped after one question. It is the baseline that will embarrass you.

Predict the last value. For anything measured over time, predict that tomorrow equals today. It is devastating on forecasting problems and beats a surprising number of published models.

The regression equivalents are the same idea with the arithmetic changed: predict the mean of the training targets, or predict the previous value. If your model cannot beat the mean, it has learned nothing at all.

The race

Four hundred students and six recorded columns, of which one has anything to do with passing. Everybody trains on the same 250 and is marked on the same 150. 46% of them passed.

best baselineAlways say the commoner a…56%Guess at the right rate47%One rule on one column87%k-Nearest Neighbours78%Decision tree, depth 476%

Try every column at every cut-off and keep the single best rule. Here that is "hours revised at or above 8.2".

baseline
predict = lambda row: row["hours revised"] >= 8.2

Racing them against the real thing

The dataset is deliberately ordinary. Six columns were recorded because recording them was easy — hours revised, hours slept, commute, siblings, height, shoe size — and exactly one of them has anything to do with passing.

The majority rule scores 56.0%. Random guessing at the right rate scores 47.3%, which is worse, as it always is. Then the one-rule baseline finds “revised at least 8.2 hours” and scores 87.3%.

Now the two real models. The five-neighbour vote gets 78.0%. The depth-4 decision tree gets 76.0%. Both lose to the if-statement, by nine and eleven points.

Neither is broken, and this is not a trick. The neighbour vote measures distance across all six scaled columns, so five-sixths of every distance it computes is noise — the exact failure from chapter eight, arriving through a different door. The tree does pick the right column first, then spends its remaining three levels splitting on shoe size and commute times, carving out little regions that fit the training set and mean nothing. It overfits into the noise the stump was too simple to reach.

When the baseline wins

It happens more than the literature suggests, and it is information rather than failure. When a trivial rule matches your model, one of four things is true.

The problem may be easy, and one column carries it — as here. Your features may not contain the answer, in which case no algorithm will find it and the work is to collect better data, not to try a bigger model. The model may be misconfigured, which is worth ruling out before the more interesting explanations. Or the extra capacity is finding noise, which is chapter six wearing a hat.

In every one of those cases the right move is the same: ship the baseline. It is faster, it is readable, it will not drift, and somebody can maintain it after you have left. Complexity has to be earned against a number, and here the number says it has not been.

Before the first model

Half an hour, and it will change what you build.

  • Write down what a majority-class or predict-the-mean rule scores. That is the floor.
  • Fit a one-rule stump. If your model does not clear it comfortably, the extra machinery is not paying for itself.
  • If anything is timestamped, score predict-the-last-value too. It is the hardest baseline to beat on real forecasting problems.
  • Quote every model score next to the best baseline, always. A score without one is not a claim anybody can check.

Key takeaways

  • A score means nothing on its own. It is only interpretable next to the score of something trivial.
  • Build the baseline first — it debugs your data loading, splitting and scoring while there is nothing else to blame.
  • Always run: the majority class, a rate-matched random guess, a one-rule stump, and predict-the-last-value for anything timestamped.
  • Here a single if-statement scored 87.3% while a five-neighbour vote managed 78.0% and a depth-4 tree 76.0%.
  • The neighbour vote lost because five of six columns were noise diluting every distance; the tree lost by overfitting into the same noise.
  • A model that cannot beat the baseline means easy problem, uninformative features, a misconfiguration, or overfitting — all four are worth knowing early.
  • When the baseline wins, ship the baseline. It is faster, readable, and somebody else can maintain it.