Foundations

Why Every Machine Learning Project Needs a Simple Baseline

Learn which baselines to build first, how to compare a model against them fairly, and how to judge whether the extra complexity earns its keep.

Key takeaways

  • A score is informative only next to the score of something simpler measured on the same data with the same metric.
  • Build at least two baselines: a trivial one that ignores the inputs and a sensible one such as the current rule or a linear model.
  • With rare classes, a model that always predicts the majority class can reach very high accuracy while catching nothing.
  • If a complex model barely beats a baseline, check whether the gain is larger than the noise in your test set.
  • Keep the baseline running after launch as a sanity check and a fallback.

A baseline is the simplest reasonable way of solving your problem, scored the same way as your model. Every project needs one because a metric on its own means nothing. An accuracy of 92 percent is excellent for one task and worthless for another, and only a comparison tells you which you have.

A baseline takes an hour or so to build. It tells you what "no skill" looks like, exposes broken evaluation code, and gives you an honest price for every layer of complexity you add later.

Start with a model that ignores the inputs

The trivial baseline looks only at the training targets. For classification, it predicts the most common class, or assigns every example the class frequencies as probabilities. For regression, it predicts one constant.

Which constant depends on your loss. Take five targets: 10, 12, 14, 20 and 44. The mean is 20 and the median is 14.

Constant prediction Mean absolute error Mean squared error
Mean (20) 9.6 155.2
Median (14) 8.4 191.2

The median wins on absolute error and the mean wins on squared error. That is a general property, so match the constant to the metric you report.

The familiar R² score has this baseline built in. It equals 1 minus the model's squared error divided by the squared error of predicting the mean. A model with mean squared error 116.4 on these five points would score 1 − 116.4/155.2 = 0.25. On new data, R² can be negative, meaning the model does worse than a constant.

The accuracy trap with rare events

Suppose 8 percent of customers cancel. A rule that says "nobody cancels" is right 92 percent of the time and finds none of the people you care about. The short script below shows the same thing on synthetic data.

from sklearn.datasets import make_classification
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, average_precision_score
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

X, y = make_classification(n_samples=5000, n_features=10,
                           weights=[0.92], random_state=0)
X_tr, X_va, y_tr, y_va = train_test_split(
    X, y, stratify=y, random_state=0)

models = {
    "majority class": DummyClassifier(strategy="prior"),
    "logistic regression": make_pipeline(
        StandardScaler(), LogisticRegression(max_iter=1000)),
}
for name, model in models.items():
    model.fit(X_tr, y_tr)
    p = model.predict_proba(X_va)[:, 1]
    print(name,
          round(accuracy_score(y_va, model.predict(X_va)), 3),
          round(average_precision_score(y_va, p), 3))

X has 5,000 rows and 10 columns. In one run the majority rule scored about 0.92 accuracy and about 0.08 average precision, which is simply the share of positives. Logistic regression reached about 0.98 and 0.9. Accuracy makes the gap look modest, while average precision shows how large it is. Your digits may differ slightly across library versions.

A ladder of baselines

Trivial baselines set the floor. Stronger ones tell you whether machine learning is worth the trouble at all.

A ladder of baselines, hardest to beat on top
Current system Whatever makes the decision now, human or software. Simple learned model Linear or logistic regression, or a shallow tree. Hand rule One or two conditions an expert would suggest. Constant guess Mean, median or majority class. Current system Whatever makes the decision now, human or software. Simple learned model Linear or logistic regression, or a shallow tree. Hand rule One or two conditions an expert would suggest. Constant guess Mean, median or majority class.

A heuristic baseline is a rule written by hand, such as "flag customers who have not logged in for 30 days." Domain experts often have one ready. Sometimes it is good enough to ship, a case explored in when a handwritten rule beats a learned model.

A simple learned model uses a handful of obvious features with default settings. The current system is the one your stakeholders will actually compare against, even if nobody has ever measured it. Measure it.

Baselines for other kinds of problems

Each task type has its own natural starting point.

Task Baseline worth building first
Time series forecast Repeat the last value, or the value one season ago
Recommendation Show the most popular items
Text classification Word counts with a linear classifier
Image classification A frozen pretrained network with a linear layer on top
Search ranking A keyword scoring function

These can be surprisingly strong. For many series, a seasonal naive forecast is hard to beat by much, and popularity captures a good share of what people click. If your elaborate model loses to either, you have learned something important early.

Human and noise references

Some problems come with a natural ceiling to set beside the floor. If two trained reviewers agree on only 90 percent of cases, a model scoring 97 percent against one reviewer's labels deserves suspicion, because it may be imitating that person's habits or exploiting a leak.

To get a human reference, give a few knowledgeable people the same inputs the model will see, nothing more, and score their answers with your metric. A reviewer who can open the full customer file is solving an easier problem than a model that sees six columns.

The reference also helps you plan. Say a constant guess gives 30 percent error, a linear model gives 14 percent and careful reviewers give 12 percent. Most of the achievable improvement has already arrived with the linear model, and the remaining two points may be expensive. If reviewers reached 2 percent instead, there would be a strong case for better features or a more capable model.

Treat human performance as a guide and no more. On tasks involving large volumes of weak statistical signals, such as predicting which of a million sessions ends in a purchase, models can reasonably do better than people.

Compare fairly

A comparison is only as good as its controls. Check each of these before you believe a gap.

  1. Same data split. Baseline and model are fitted on the same training rows and scored on the same held-out rows.
  2. Same information. Neither sees a feature that would be unavailable at prediction time.
  3. Same metric and threshold rule. If you tune the model's decision threshold, tune the baseline's too.
  4. Comparable effort. A heavily tuned network against an untouched linear model mostly measures your tuning budget.
  5. Same exclusions. If the model skips hard rows, the baseline must skip them as well.

Unequal effort is the most common flaw. Researchers and practitioners alike tend to polish the method they are excited about.

Is the gain real?

Say the baseline scores 92 percent accuracy and your model scores 93 percent on 1,000 test examples. The standard error of a single accuracy near 0.92 is √(0.92 × 0.08 / 1000) ≈ 0.0086, or about 0.9 percentage points. A one-point gap is only around one standard error.

Because both models are scored on the same examples, a paired comparison is sharper than comparing two separate intervals. Count the cases the model gets right and the baseline gets wrong, then the reverse. If those counts are 18 and 8, the net gain is 10 examples, or one point, based on just 26 disagreements. Tests for comparing two models work from exactly these counts.

Is the gain worth it?

A real improvement can still be a bad trade. Express it in units the decision cares about. Suppose 1,000 cases a day and a one-point gain: that is about 10 extra correct decisions daily. Whether that justifies a new training pipeline, a larger server bill and an on-call rotation depends on what each decision is worth.

It can help to report the share of remaining error removed. Going from 8 percent error to 7 percent removes one eighth of it, or 12.5 percent. Going from 2 percent to 1 percent is also one point, but halves the error.

Weigh other costs too: latency, the difficulty of explaining outputs, the number of data sources that can break, and how long a new teammate needs to understand the system.

When the baseline reveals a bug

Baselines are also diagnostic tools. If your model scores below the constant guess, suspect misaligned labels, a flipped class index or preprocessing applied differently at evaluation time. If a one-feature baseline scores almost perfectly, that feature may be leaking the answer.

If every method, simple and complex, lands on the same number, the inputs may not contain more signal, or the labels may be too noisy to reward improvement. Looking at the mistakes through error analysis helps you decide which.

Write the baseline down before you start

Agree on the baseline and the margin that would count as success before training anything clever. Otherwise it is easy to move the goalposts, choosing after the fact whichever comparison flatters the result.

A short written note is enough. For a hypothetical support-ticket router, it might read: the current keyword rules are the bar; the metric is the share of tickets sent to the right team on last month's held-out tickets; a new model ships only if it reduces misrouted tickets by at least a fifth without doing worse on urgent ones.

The note turns a vague hope into a decision. It also protects you when the answer is no. Reporting that a simple rule remains the best option, with the evidence, saves your team the cost of building and maintaining something that adds nothing.

Keep the baseline alive

Write the baseline into your evaluation script so that it runs with every experiment and appears in every results table. When data changes, both numbers move, and the difference between them stays interpretable.

After launch, a simple model or rule makes a useful fallback when an input feed fails. It also provides a monitoring reference: if the sophisticated model's advantage shrinks month by month, something in the data or the world has shifted, and you have a concrete reason to investigate.

Written for 4MachineLearning with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 42 articles in Foundations →

Latest news on this topic