Blockwise.
Back to learning
Model guide

Dummy baselines

Start with a deliberately simple answer that ignores the inputs. A more complex model must justify its extra work against this reference.

Start with an example

If training deliveries average 25 minutes, a mean DummyRegressor predicts 25 for every route. A most-frequent DummyClassifier always predicts the most common training class.

How it learns

An input feature is a measurement about an example. The target is its known answer: a number for regression, or a category for classification. Training means learning from examples whose answers are already known.

  1. Summarize only the known training answers. For a numerical prediction, one strategy uses their mean: add the answers and divide by their count. For a class prediction, one strategy always chooses the most common class.
  2. Give this same reference answer to every input. Compare other models on the same separate examples that were not used for training; otherwise the comparison is unfair.

Try it yourself

The example above gives the idea. The experiment below uses a separate, made-up dataset with unitless measurements so you can focus on how the model works. Read the graph guide first, then change one thing at a time.

1. Understand what you are looking at

Start with a reference model that gives everyone the same numerical prediction. This graph uses regression: strategy 0 predicts the mean, and strategy 1 predicts the median.

Across: the horizontal axis
The input measurement x, from 0 to 10. In a delivery task, an input could be distance; here it has no unit.
Up: the vertical axis
The target: the numerical answer being predicted. In a delivery task, it could be time; here the target has no unit.

Each dark dot pairs one input with its observed target. The green line gives the model's predicted target at each input. A vertical gap from a dot to the line is a prediction error.

How to read one result: Start at x on the bottom axis and follow the vertical dashed line to the outlined diamond on the curve. Read its height on the left: that is the predicted target for this input.

2. Predict, change, observe

  1. Keep Baseline strategy at 0. Predict whether moving Input to inspect (x) from 2 to 8 will change the estimated target, then try it.
  2. Switch Baseline strategy to 1. The height can change because the median is the middle of the sorted answers, while the mean adds all answers and divides by their count.
Interactive Dummy baselines illustrationEach dark dot pairs one input with its observed target. The green line gives the model's predicted target at each input. A vertical gap from a dot to the line is a prediction error.02.557.5100246810Target valueInput feature (x)
  • Observations
  • Model prediction
  • Inspected result (diamond)
Prediction at x = 6.0: 4.504

Mean squared training error: 2.470

Mean squared training error averages the squared vertical gaps from the observed dots to the line. Smaller means a closer fit to these training examples, not necessarily better predictions on new examples.

3. Explain it in your own words

Why is the line horizontal even though the observed dots have different heights?

Compare your reasoning

The baseline ignores the input and summarizes the training answers with one number. It cannot adapt its prediction to x. If unsure, move only Input to inspect (x) and notice that the dashed inspection line moves while the prediction height stays fixed.

Ready to continue when you can explain the result and why it changes. If the explanation is still unclear, reset and repeat the two steps above with one control at a time.

What this experiment simplifies

Switch between a mean/class-prior baseline (0) and a median/majority baseline (1). A baseline ignores the input feature.

These are small teaching implementations, not scikit-learn runs. Training error on these examples does not estimate performance on new data.

View the plotted examples
Input feature (x)Observed target
0.302.78
0.922.97
1.544.17
2.164.08
2.784.33
3.403.24
4.023.41
4.642.87
5.263.37
5.883.16
6.504.58
7.125.27
7.746.6
8.366.59
8.987.51
9.607.14

The math, one step at a time

Read the symbols after the idea makes sense. You do not need to memorize the formula.

y^=1n∑iyi,c^=arg⁡max⁡c∑i1[yi=c]\hat y=\frac{1}{n}\sum_i y_i,\qquad \hat c=\underset{c}{\arg\max}\sum_i\mathbf{1}[y_i=c]Read it like thisThe numerical baseline predicts the average training answer for every input. The class baseline predicts whichever class occurs most often in training.What the symbols meann,  in,\;in is the number of training examples and i selects one example. Dividing their total by n gives their average.yi,  y^iy_i,\;\hat y_iy is an observed answer; y with a hat is a prediction. A small lower i selects example number i. Their difference is one prediction error.c,  c^c,\;\hat cc is one possible class, such as ordinary or urgent. c with a hat is the class the model chooses.==Equals: the expressions on both sides have the same value.ab\frac{a}{b}A fraction means divide the entire top by the entire bottom. For example, 6 over 3 means 6 divided by 3, which is 2. The bottom cannot be zero.∑\sumCapital sigma: add one term for every indicated item. The symbol below says which item to count; limits such as j = 1 to p mean start at 1 and stop at p. For example, adding 2, 4, and 6 gives 12.arg⁡max⁡c\underset{c}{\arg\max}Arg max: return the class with the largest score, rather than the score itself. If scores for A and B are 0.2 and 0.8, choose B.1[condition]\mathbf{1}[\text{condition}]Indicator: use 1 when the condition in brackets is true, and 0 otherwise. Adding these values counts how often it is true.

n counts training rows. These are two specific strategies; dummy estimators also provide other configurable strategies.

What to watch for

  • The model cannot personalize a prediction using input measurements.
  • Beating a weak baseline alone does not establish that a model is good enough for the task.

Further reading

The official documentation goes further when you are ready.