Knowledge Sprint SeriesMT24 Learning

Phase 9 · Sprint 27/90 · Classical Machine LearningHolte · Brodersen · Ferrari Dacrema · Hyndman

Baselines First

A score means nothing until I know what doing nothing would have scored.

In short. What a baseline is, why accuracy lies on imbalanced data, how the chosen score steers the model, and weak baselines in published work.

Sprint 27 of 90 infographic: Baselines First. A score means nothing until I know what doing nothing would have scored. The full text of the image is on this page.
Full resolution2160 × 2700 PNGPhase summary

The part of the image you are reading lights up. Tap a part to jump to its text.

Fig. 1 in words

Two floors · iris from Sprint 26 · handwritten digits · same data as code 05

  1. 1 Iris · Sprint 26 split

    • learn: versicolor 40 · virginica 30
    • test: versicolor 10 · virginica 20
    • green: versicolor · purple: virginica · flowers
    • test accuracy · 30 flowers, on a scale from 0 to 1:
    • ① 0.333 · always versicolor
    • 0.5 · a coin, expected
    • 0.900 · the cut, Sprint 26
  2. 2 Digits · is it a 9? · 540 test images, 54 nines

    • Always “no” · the majority: accuracy 0.900 · balanced accuracy 0.500
    • Pixel 38 > 12 · picked by accuracy: 0.894 · 0.505 ③
    • Pixel 29 > 11 · picked by balanced: 0.759 · 0.809 ④
    • Logistic · all 64 pixels: 0.983 · 0.941
    • a small grid beside each pixel rule marks its pixel in red
    • dotted line at 0.5: chance · balanced · dashed line at 0.900: always “no” ②
    • grey bars: accuracy · purple bars: balanced accuracy · scale 0 to 1

01 What a Floor Is Setup

  • A baseline answers without reading the input: majority class, mean, last value
  • DummyClassifier “makes predictions that ignore the input features” (scikit-learn)
  • A model's claim is its gap above that floor

Holte (1993): on most datasets studied, the best one-attribute rule was as accurate as most learners.

02 Accuracy Lies Imbalance

  • 54 of 540 test digits are 9s: “always no” scores 0.900
  • Balanced accuracy averages the recall of each class: “always no” gets 0.500 (Brodersen et al. 2010)

Recall is the share of a class the rule finds: 0 of 54 nines here. I read all four counts.

03 The Score Steers Loss

  • By accuracy: pixel 38 says “yes” 5 times and finds 1 nine
  • By balanced accuracy: pixel 29 finds 47 of 54 and flags 123 others
  • So the score decides what ERM learns

Logistic regression on all 64 pixels: 0.983 and 0.941. It clears both floors.

04 Weak Baselines Evidence

  • Of 18 neural recommenders, 7 could be reproduced with reasonable effort; 6 of those were often beaten by simple heuristics (Ferrari Dacrema et al. 2019)
  • A method is only as new as the strongest baseline it beat

So I tune the baseline as hard as the model.

05 Try It Yourself PYTHON 3.13.15

sprint27_baselines_first.py

import numpy as np
from sklearn import datasets, dummy, metrics
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
_, y = datasets.load_iris(return_X_y=True)  # Sprint 26
y = y[y > 0][np.random.default_rng(26).permutation(100)]
tr, te = np.bincount(y[:70])[1:], np.bincount(y[70:])[1:]
print(tr, te, f"{te[tr.argmax()] / 30:.3f}")  # majority

D, d = datasets.load_digits(return_X_y=True)
y9 = (d == 9) * 1                      # is it a 9?
a, b, ya, yb = train_test_split(D, y9, test_size=0.3,
                       stratify=y9, random_state=27)
acc = lambda t, p: (t == p).mean()
bal = metrics.balanced_accuracy_score  # mean recall
no = dummy.DummyClassifier(strategy="most_frequent")
p = {"no": no.fit(a, ya).predict(b)}
for score in (acc, bal):               # 1R-style rule
    fc = [(f, c) for f in range(64) for c in range(17)]
    f, c = max(fc, key=lambda k:
               score(ya, (a[:, k[0]] > k[1]) * 1))
    p[f"px{f}>{c}"] = (b[:, f] > c) * 1
lr = LogisticRegression(max_iter=5000)
p["logistic"] = lr.fit(a, ya).predict(b)
print(len(yb), "test images,", yb.sum(), "nines")
for k, q in p.items():
    print(f"{k:9}{acc(yb, q):.3f}", f"{bal(yb, q):.3f}",
          q.sum())

Output, as printed on the image

[40 30] [10 20] 0.333
540 test images, 54 nines
no       0.900 0.500 0
px38>12  0.894 0.505 5
px29>11  0.759 0.809 170
logistic 0.983 0.941 51

Run it. sprint27_baselines_first.py · versions, data and steps

Check: 486/540 = 0.900 · (482+1)/540 = 0.894 · (47/54 + 363/486)/2 = 0.809 · 10/30 = 0.333. scikit-learn 1.9.1

06 General Notes Practice

  • Fit the baseline on the learn set only
  • Stratify the split to keep the class shares
  • Numbers: R² measures against the mean. Forecasts: MASE divides by the naive forecast's error (Hyndman & Koehler 2006)

In Sprint 26's split the learn-set majority was the test-set minority.

07 Mini Project Hands-on

  • Rerun with random_state 1 to 5
  • Ask “is it a 1?”, then “is it an 8?”
  • Stratify the iris split; recompute the floor
  • Diabetes data: DummyRegressor vs LinearRegression, scored by R²

With random_state 27, the learn-set mean scores R² = −0.016 on test; linear regression 0.451.

R Trusted Sources

  1. Holte (1993). Very Simple Classification Rules Perform Well on Most Commonly Used Datasets. Mach. Learn. 11(1), 63–90
  2. Brodersen, Ong, Stephan & Buhmann (2010). The Balanced Accuracy and Its Posterior Distribution. ICPR, 3121–3124
  3. Ferrari Dacrema, Cremonesi & Jannach (2019). Are We Really Making Much Progress? A Worrying Analysis of Recent Neural Recommendation Approaches. RecSys
  4. Hyndman & Koehler (2006). Another Look at Measures of Forecast Accuracy. Int. J. Forecast. 22(4), 679–688
  5. Alpaydin & Kaynak (1998). Optical Recognition of Handwritten Digits. UCI ML Repository
  6. scikit-learn docs: DummyClassifier · balanced_accuracy_score · r2_score

Cite this phase

Tahri, M. (2026). MT24 Learning — Knowledge Sprint Series, Phase 9: Classical Machine Learning (Version 1.0) [Educational resource]. Zenodo. https://doi.org/10.5281/zenodo.23240712

Version DOI 10.5281/zenodo.23240712 · all versions 10.5281/zenodo.23240711 · first published 4 October 2026