Sub topic 4
Trivial baselines: the floor to beat
A trivial baseline is a predictor that uses no features, or almost none. It sets the lowest score that any model must beat to justify its existence. This chapter assumes you know the basics of supervised learning, common metrics (accuracy, recall, mean absolute error), and scikit-learn's fit/predict interface. It also assumes you know mean, standard deviation, and standard error. Earlier chapters covered why baselines matter, how to pick a metric, and how to split data. Here you build the first rung of the baseline ladder.
What makes a baseline trivial
A trivial baseline ignores the relationship between features and target. It learns one summary of the training labels, such as the most common class, the mean, or the median. For time series it copies the most recent observation. It has three useful properties:
- It takes seconds to build and cannot overfit in any meaningful way.
- It is fully explainable to a stakeholder in one sentence.
- Its score tells you how much of the apparent performance comes from the target's distribution alone, not from learning.
If a complex model scores only slightly above a trivial baseline, the features carry little signal, or the pipeline has a bug. If a model scores below it, something is wrong. Check for a mismatched metric, a broken split, or a preprocessing error before you tune anything.
Choosing the trivial predictor by task
The right trivial predictor depends on the task and on the metric you will use for scoring. A constant that minimizes one loss is not optimal for another.
| Task | Trivial baseline | Best for this metric |
|---|---|---|
| Classification | Most frequent class | Accuracy |
| Classification | Class priors as probabilities | Log loss, Brier score |
| Regression | Training mean | Mean squared error |
| Regression | Training median | Mean absolute error |
| Forecasting | Previous observation (naive) | Short-horizon, trending or random-walk-like series |
| Forecasting | Value one season ago (seasonal naive) | Series with a fixed cycle |
Classification baselines
The most common failure with imbalanced data is reading a high accuracy as a good result. Consider a dataset where 95% of examples belong to the negative class. A predictor that always says "negative" scores about 95% accuracy and never finds a single positive case.
from sklearn.datasets import make_classification
from sklearn.dummy import DummyClassifier
from sklearn.metrics import accuracy_score, balanced_accuracy_score
from sklearn.model_selection import train_test_split
X, y = make_classification(n_samples=2000, weights=[0.95, 0.05], random_state=0)
X_train, X_test, y_train, y_test = train_test_split(
X, y, stratify=y, random_state=0
)
baseline = DummyClassifier(strategy="most_frequent").fit(X_train, y_train)
pred = baseline.predict(X_test)
print("accuracy:", accuracy_score(y_test, pred))
print("balanced accuracy:", balanced_accuracy_score(y_test, pred))The accuracy is about 0.95, but balanced accuracy is exactly 0.5. Balanced accuracy is the average of recall over the classes, and a constant predictor always lands on 1/(number of classes). This is why you choose the metric before you call any score good.
Other DummyClassifier strategies
DummyClassifier offers more than one strategy. Each one answers a slightly different question.
| Strategy | Behavior | Use it when |
|---|---|---|
| `most_frequent` | Always predicts the majority class | You want the accuracy floor |
| `prior` | Predicts the majority class, but `predict_proba` returns class priors | You score with log loss or Brier score |
| `stratified` | Samples labels at random with training class frequencies | You want a "random guess that knows the base rate" |
| `uniform` | Samples each class with equal probability | You want a pure chance level |
| `constant` | Always predicts a class you choose | You want recall or precision for one class, for example always "positive" |
The loop below shows how these differ on the split above.
from sklearn.datasets import make_classification
from sklearn.dummy import DummyClassifier
from sklearn.metrics import accuracy_score, balanced_accuracy_score
from sklearn.model_selection import train_test_split
X, y = make_classification(n_samples=2000, weights=[0.95, 0.05], random_state=0)
X_train, X_test, y_train, y_test = train_test_split(
X, y, stratify=y, random_state=0
)
for strategy in ["most_frequent", "stratified", "uniform"]:
model = DummyClassifier(strategy=strategy, random_state=0)
model.fit(X_train, y_train)
pred = model.predict(X_test)
print(
strategy,
round(accuracy_score(y_test, pred), 3),
round(balanced_accuracy_score(y_test, pred), 3),
)The stratified baseline has an expected accuracy of about 0.95² + 0.05² = 0.905, lower than most_frequent. The uniform baseline lands near 0.5 accuracy. Randomized baselines also change from run to run, so always set random_state.
Regression baselines
For regression, the trivial baseline is a constant. Which constant is best depends on the loss. The mean minimizes squared error, and the median minimizes absolute error. The quantile strategy fits losses such as pinball loss. A trivial regressor with the mean also gives an R² near 0 on test data, which is what R² means: improvement over predicting the mean.
The next example adds a second baseline of increasing strength. A plain linear regression tells you how much of the problem a simple signal already solves.
import numpy as np
from sklearn.dummy import DummyRegressor
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import train_test_split
rng = np.random.default_rng(0)
X = rng.normal(size=(500, 3))
y = 3.0 * X[:, 0] - 2.0 * X[:, 1] + rng.normal(scale=1.0, size=500)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
for name, model in [
("median", DummyRegressor(strategy="median")),
("linear", LinearRegression()),
]:
model.fit(X_train, y_train)
mae = mean_absolute_error(y_test, model.predict(X_test))
print(name, round(mae, 3))Both models are scored with the same metric on the same held-out split. This is the habit to keep: a comparison is only meaningful when everything except the model is held fixed.
Forecasting baselines
For time series, features about the past are the whole game, so the trivial predictor uses the most recent value. This is the naive forecast: tomorrow equals today.
import numpy as np
# Daily values; the naive forecast predicts that tomorrow equals today.
y = np.array([102.0, 105.0, 103.0, 108.0, 110.0, 109.0, 113.0])
actual = y[1:]
naive_forecast = y[:-1]
mae = np.mean(np.abs(actual - naive_forecast))
print("naive MAE:", mae)This prints an MAE of about 2.83. Any forecasting model should have to beat that number on the same stretch of data.
If the series has a fixed cycle, such as a weekly pattern in daily data, use the seasonal naive forecast. It predicts the value from one full period earlier.
import numpy as np
# Three weeks of daily data with a weekly pattern.
week = np.array([100.0, 104.0, 108.0, 107.0, 112.0, 130.0, 125.0])
y = np.concatenate([week, week + 2.0, week + 4.0])
season = 7
actual = y[season:]
seasonal_naive = y[:-season]
print("seasonal naive MAE:", np.mean(np.abs(actual - seasonal_naive)))
print("naive MAE:", np.mean(np.abs(y[1:] - y[:-1])))On this series the seasonal baseline has an error of exactly 2, and the plain naive forecast is much worse. Choosing the right trivial baseline matters: comparing a seasonal model with the plain naive forecast makes the model look better than it is.
How to read the result
Once you have a trivial score, there are three possible outcomes:
- The candidate clearly beats the baseline. The model has found signal. Continue to variance and significance checks, covered in later chapters.
- The candidate roughly ties the baseline. Suspect weak features, too little data, a target that is mostly noise, or a bug. Inspect the pipeline first, not the hyperparameters.
- The candidate loses to the baseline. Suspect a bug, a mismatched metric, or a train/test distribution shift.
A single run is only a point estimate. Differences of a few thousandths of a metric point are usually noise, which is why later chapters use repeated cross-validation.
Common mistakes
- Reporting only accuracy on imbalanced data. Always print the baseline's score under the metric you will use to decide.
- Using a different split or metric for the baseline. Keep the split, preprocessing, and metric identical for baseline and candidate.
- Forgetting that the majority class may not be the class you care about. If missing a rare positive is costly, the "always negative" baseline has zero recall. Report recall or precision for that class too.
- Picking the mean when the metric is MAE. The median is the fair constant for absolute error.
- Using plain naive for a seasonal series. Pick the baseline that matches the structure of the data.
Exercise
A fraud dataset has 1% fraud. A colleague says a model with 98.5% accuracy "clearly works". What baseline would you compute first, and what would you expect it to show?
Show answer
Compute a DummyClassifier with strategy="most_frequent" (always "not fraud") on the same held-out split. It would score about 99% accuracy, which beats the colleague's 98.5%, and it has zero recall for fraud, with a balanced accuracy of 0.5. The model's accuracy is therefore worse than doing nothing. Compare the model on balanced accuracy, recall, or precision for the fraud class instead.
Exercise
You are forecasting daily store sales that peak every weekend. Your model's MAE is 40, the naive forecast's MAE is 55, and the seasonal naive forecast (season=7) has an MAE of 38. Does the model earn its place?
Show answer
No. The model beats the plain naive forecast, but the seasonal naive forecast is the right baseline for a weekly pattern, and the model does worse than it (40 vs 38). A simple rule that copies last week's value is better and cheaper, so the model needs further work or should be dropped.