Baselines and controls
Be able to choose reasonable baselines and explain why results without a baseline are worthless.
Prerequisites
- EScientific method in AIrequired
Intuition
«Our model gets 91 %.» Is that good? If 90 % of the examples belong to one class, «always guess the majority» gets 90 %. Then 91 % is nearly nothing.
Baselines in ascending order:
- Chance / the majority — the floor.
- A simple rule — a keyword, a threshold, «the same as yesterday». Often surprisingly strong.
- A simple model — logistic regression on TF-IDF, k-NN on embeddings. Fast to train, hard to beat with little data.
- The standard method — the pre-trained model everybody uses, properly tuned.
- A human being — what does a trained person get on the same test set?
Your method should be reported alongside all of these. And the baseline should have been given the same love — the same time on hyperparameters, the same data — otherwise you are comparing your best day with its worst.
Code
import numpy as np
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import cross_val_score
baselines = {
"majority": DummyClassifier(strategy="most_frequent"),
"chance": DummyClassifier(strategy="stratified", random_state=0),
"tfidf+lr": make_pipeline(TfidfVectorizer(ngram_range=(1, 2), min_df=2), LogisticRegression(max_iter=1000, C=3.0)),
}
for name, m in baselines.items():
s = cross_val_score(m, texts, y, cv=5, scoring="f1_macro")
print(f"{name:10s} {s.mean():.3f} ± {s.std():.3f}")
# majority 0.31 ± 0.00
# chance 0.33 ± 0.02
# tfidf+lr 0.78 ± 0.03 ← your transformer has to beat this clearly, with the same cv
Mastery means
- Chooses reasonable baselines: the majority, chance, a simple rule, the earlier method
- Tunes the baseline honestly
- Explains why results without a baseline are worthless
Sign in to do the exercises and build your mastery up.
Sources
- scikit-learn User Guide (BSD-3) — BSD-3-Clause
- arXiv — Are We Really Making Much Progress? (Dacrema m.fl.) — arXiv (open access; licence per article)