Baselines: start simple

Why every model must beat a trivial baseline, and how to build one.

Lesson 5 of 6610 minBeginner

You will learn to

  • Build a majority-class and a mean baseline
  • Use a baseline to judge whether ML adds value
  • Avoid comparing against straw men

Before this lesson

Intuition

Before you hire an expensive expert, you want to know what a beginner would do on the same job. If the beginner does almost as well, the expert is not worth the money. A baseline is that beginner: a trivially simple model that sets the level every real model must clear.

Baselines matter for three reasons. They tell you whether the problem is hard (if a one-line rule already works well, you may not need machine learning). They protect you from fooling yourself with a number that sounds good but is easy to reach. And they give stakeholders a meaningful comparison: "20% better than what we do today" is clearer than any score.

The two standard baselines need no learning at all:

  • Majority class (classification). Always predict the most common class in the training data.
  • Mean (regression). Always predict the average of the training targets.

Other honest baselines come from the way things work today: "same as last week" for forecasts, or the rule that your team already applies by hand. Use them when they exist, because they are the true competition.

Picture it

Score (higher is better)Model A0.31Model B0.40Model C0.52Baseline 0.30
An illustrative leaderboard. The dashed line is the baseline. Model A is barely above it; only Model C clears it by a margin that is likely to matter.

A model that does not clear the line by a margin that matters is not worth deploying, however sophisticated it is. The size of "a margin that matters" comes from the decision the model supports, which is why framing comes first.

The math

For a classification problem with classes 1,…,K1, \dots, K, let πk\pi_k be the share of class kk in the data. The majority-class baseline always predicts the largest class, so its accuracy is:

accbase=max⁡kπk\text{acc}_{\text{base}} = \max_k \pi_k

For regression, the mean baseline predicts yˉ\bar{y}, the average target. Its mean squared error is the variance of the target:

MSEbase=1n∑i=1n(yi−yˉ)2\text{MSE}_{\text{base}} = \frac{1}{n}\sum_{i=1}^{n}(y_i - \bar{y})^2

The usual way to express "how much better than the baseline" is the coefficient of determination, R squared:

R2=1−MSEmodelMSEbaseR^2 = 1 - \frac{\text{MSE}_{\text{model}}}{\text{MSE}_{\text{base}}}

R squared is 0 for the mean baseline, 1 for a perfect model, and negative for a model worse than the baseline. In general, any "skill score" has this shape: one minus the model's error divided by the baseline's error.

Worked example

Classification. A company has 1,000 customers, and 80 of them churn. The majority-class baseline always predicts "stays". Its accuracy is 920/1000=92%920/1000 = 92\%, and it finds none of the 80 churners (recall 0).

Now take a real model that flags 70 customers, of whom 40 really churn and 30 do not. The counts are: 40 true positives, 30 false positives, 40 missed churners and 890 correct "stays". Its accuracy is (40+890)/1000=93%(40 + 890)/1000 = 93\%. That is one point above the baseline, which looks tiny. But it also finds 40/80=50%40/80 = 50\% of the churners with a precision of 40/70=57%40/70 = 57\%, where the baseline finds none. For this problem, accuracy was the wrong yardstick and the baseline exposed it. (Illustrative numbers.)

Regression. Six values of a target: 10, 12, 14, 18, 22 and 24. The mean is 100/6=16.67100/6 = 16.67. The squared deviations are 44.44, 21.78, 7.11, 1.78, 28.44 and 53.78, which add up to 157.33, so the baseline MSE is 157.33/6=26.22157.33/6 = 26.22 and its RMSE is 5.12.

A model with MSE 9 (an RMSE of 3.0) has:

R2=1−926.22=0.657R^2 = 1 - \frac{9}{26.22} = 0.657

So the model removes about 66% of the error that the mean baseline makes. A model with MSE 25 would give 1−25/26.22=0.0471 - 25/26.22 = 0.047: technically better, but hardly worth a deployment.

How mlflow does it

When you train several algorithms together (a compare run) for a classification or regression pipeline, mlflow adds a dummy reference model to the run. It is called Baseline, and it uses the most frequent class for classification and the mean of the target for regression. You can see this on the run page:

  • On the Leaderboard (the Trials card), the baseline shows a Baseline badge with the hint "Dummy reference model, never ranked".
  • It is never ranked, so it cannot appear as the best model. It also cannot be exported, deployed, promoted or used as a source for blend and stack models.
  • The Model card summary skips the baseline row and describes the best real model.

Clustering, anomaly detection and time series forecasting runs do not add a baseline. For those, build your own comparison, for example "same as last week" for a forecast.

The baseline is a reference point, not a model to ship. Read the best model's score next to it, and ask whether the difference matters for your decision.

Common mistakes

  • Reading accuracy without the majority-class rate. On imbalanced data a high accuracy can be the baseline in disguise. Compare with the baseline, and look at recall and precision of the rare class.
  • Using a straw man. Comparing a tuned model with a deliberately poor alternative inflates the gain. Use honest baselines: the majority class, the mean, last period's value, or today's process.
  • Skipping the human baseline. If people already make this decision with a rule of thumb, that rule is the real competition. Measure it, even roughly.
  • Declaring victory on a tiny gain. A model that beats the baseline by a small margin may not beat it after the noise of cross-validation. Look at the spread between folds before you celebrate.
  • Forgetting that baselines differ by metric. The majority-class baseline scores well on accuracy and zero on recall. Choose a metric that reflects the decision, then compare on that metric.
  • Building the complex model first. Run the baseline before anything else. If it is already good enough, you saved weeks of work.

Try it in mlflow

Find the baseline on a leaderboard

  1. Open Runs and pick a finished classification or regression run that compared several algorithms.
  2. On the Leaderboard, find the row marked Baseline (a dummy reference model).
  3. Compare the best model with the baseline on the ranking metric: by how much does it win, and is that difference worth the added complexity?
Open in mlflow

Read in the docs

Check your understanding

  1. 1. In a dataset where 92% of customers do not churn, a model that always answers 'will not churn' is built. What accuracy does it get, and what does this tell you?
  2. 2. What does a mean baseline predict in a regression problem, and what R squared does it get on the data used to compute the mean?
  3. 3. Which comparison is a straw man?