Baseline Heuristics
A baseline heuristic is a trivial rule kept alongside a model so that the model’s score means something. Always predict the majority class. Predict the mean. Predict that tomorrow looks like today. Recommend whatever is most popular. None of them learn anything, and that is the point.
The usual framing is that a model which cannot beat the baseline is not useful. True, and incomplete โ it leaves out which baseline and which metric, and those two choices do most of the work.
The same comparison, four verdicts
import numpy as np
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, f1_score, roc_auc_score
from sklearn.model_selection import train_test_split
X, y = make_classification(n_samples=20000, n_features=10, n_informative=5,
weights=[0.93], flip_y=0.02, random_state=0)
xtr, xte, ytr, yte = train_test_split(X, y, test_size=0.4, stratify=y, random_state=0)
"""Four references. The first three look at no features at all."""
def score(name, hard, soft):
print(f" {name:<28} accuracy {accuracy_score(yte, hard):.4f} F1 {f1_score(yte, hard, zero_division=0):.4f}"
f" AUROC {roc_auc_score(yte, soft):.4f} AP {average_precision_score(yte, soft):.4f}")
for name, strategy in (("always the majority class", "most_frequent"),
("guess at the base rate", "stratified"),
("uniform coin flip", "uniform")):
d = DummyClassifier(strategy=strategy, random_state=0).fit(xtr, ytr)
score(name, d.predict(xte), d.predict_proba(xte)[:, 1])
model = LogisticRegression(max_iter=3000).fit(xtr, ytr)
score("logistic regression", model.predict(xte), model.predict_proba(xte)[:, 1])
print(f"\n positives are {yte.mean():.4f} of the test set")
# always the majority class accuracy 0.9204 F1 0.0000 AUROC 0.5000 AP 0.0796
# guess at the base rate accuracy 0.8538 F1 0.0859 AUROC 0.5032 AP 0.0801
# uniform coin flip accuracy 0.4970 F1 0.1409 AUROC 0.5000 AP 0.0796
# logistic regression accuracy 0.9654 F1 0.7389 AUROC 0.8977 AP 0.7717
#
# positives are 0.0796 of the test set
Positives are 7.96% of this test set, so the majority-class rule is right 92.04% of the time. Against it, a working model scores 0.9654 โ an improvement of four and a half points, which in a status report reads as marginal.
The same two rows on F1 are 0.0000 and 0.7389. On average precision they are 0.0796 and 0.7717. The model has not changed between those readings; the question being asked has.
So the baseline’s job is not only to set a floor but to expose what the metric is measuring. A metric on which a rule that ignores every feature scores 0.9204 is a metric that is mostly reporting the class balance, and an improvement over it should be read that way.
The baselines also disagree with each other. The uniform coin flip is the worst on accuracy at 0.4970 and the best of the three on F1 at 0.1409, because predicting the positive class half the time catches half the positives. Picking “the baseline” without saying which one leaves room to pick the flattering comparison later.
Which baselines to keep
- The trivial statistical one. Majority class for classification, the mean or median for regression. It answers “is there any signal here at all.”
- The rule already in production. If the business currently flags customers who have not logged in for sixty days, that rule is the real competitor. Beating the majority class while losing to the existing heuristic is not a result worth shipping.
- A single-feature model. Logistic regression on the one variable a domain expert would have used. If the full model barely beats it, the extra features and the extra complexity are not earning their operational cost.
- For series with an order, the naive forecast โ and the three others in simple baseline methods, since which of them is hard to beat tells you what kind of series you have.
One correction to a common claim: baselines do not detect overfitting. A memorizing model can beat every baseline on training data and lose to all of them on new data โ that is what a held-out split is for. What a baseline detects is a model that learned nothing, and a problem that was easier than anyone admitted.
Turning it into a requirement
The useful form is a sentence written before the modeling starts: “the model must reach at least 1.5 times the recall of the sixty-day rule at the same precision.” That names the baseline, the metric, the margin and the operating point, and it can be checked rather than argued about.
Quantify uncertainty in the improvement. Use paired predictions and a method appropriate to the sampling design. There is no universal two-point noise threshold: on 300 positives, six cases recovered only by one model and none only by the other give a two-point recall difference with a two-sided exact paired-test p-value of 0.03125. Dependence, repeated comparisons and practical value still need to be assessed.
References
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
