Knowledge Sprint SeriesMT24 Learning

Phase 9 · Sprint 26/90 · Classical Machine LearningFisher · Vapnik · Mitchell · Wolpert

Supervised Learning: From Examples to a Rule

Remembering every example is easy. Learning is answering the one I have not seen.

In short. Training pairs and a rule, choosing the rule with the fewest mistakes, seen against unseen data, and why no rule works without assumptions.

Sprint 26 of 90 infographic: Supervised Learning: From Examples to a Rule. Remembering every example is easy. Learning is answering the one I have not seen. 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

100 iris flowers · 70 learned, 30 held out · same data as code 05

  1. 1 Petal length · petal width

    • petal length (cm), 3 to 7 · petal width (cm), 1.0 to 2.5
    • filled dots: learned from · 70 · hollow dots: held out · 30
    • green: versicolor · purple: virginica
    • red ring: missed by the cut
    • dashed line: width > 1.6 → virginica · below it: otherwise → versicolor
    • ① a dashed circle round a green and a purple dot at the same spot · ② the dashed line of the cut
  2. 2 30 new: right · wrong · no answer

    • Memorise · lookup table · learn 1 / 70 · 1 wrong ③ · a row of mostly empty squares: no answer
    • answers only flowers it has already seen
    • Nearest neighbour · learn 1 / 70 · 3 wrong
    • assumes close flowers share a species
    • One cut · chosen by ERM · learn 3 / 70 · 3 wrong ④
    • assumes one measurement and one threshold

01 Pairs In, Rule Out Setup

  • Training data: pairs of measurements x and right answers y
  • The learner returns a rule h for a new x
  • Predict a class: classification. Predict a number: regression

Fisher (1936) analysed iris data collected by Anderson (1935): 50 flowers per species, four measurements in cm.

02 Fewest Mistakes Wins ERM

  • Loss: 0 if the answer is right, 1 if wrong
  • Empirical risk: mean loss on my examples; true risk: on new cases (Vapnik 1991)
  • ERM keeps the rule in my class with the lowest empirical risk

The true risk is never observed. Flowers held out before learning estimate it.

03 Seen vs. Unseen Overfit

  • The lookup misses 1 training flower yet answers only 6 of 30 new ones
  • A memoriser can err 0 on its examples and 1/2 on new ones (Shalev-Shwartz & Ben-David)
  • Test error, not training error, grades learning

Fewer training errors did not buy fewer test errors: 1 and 3 in training, 3 and 3 on test.

04 No Free Lunch Induction

  • Each rule in Fig. 1 carries an assumption
  • With no assumption a learner can only memorise (Mitchell 1997, ch. 2)
  • Over all targets, any two learners win equally often off the training set (Wolpert 1996)

Choosing the class of rules is the assumption. I write it down (Sprint 11).

05 Try It Yourself PYTHON 3.13.15

sprint26_supervised_learning_from_examples_to_a_rule.py

import numpy as np
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)
X, y = X[y > 0][:, 2:], y[y > 0] - 1
# petal length, width in cm; 1 = virginica
i = np.random.default_rng(26).permutation(100)
tr, te = i[:70], i[70:]      # learn / hold out

def err(rule, idx):          # 0-1 loss, summed
    return sum(rule(X[j]) != y[j] for j in idx)
memo = {tuple(X[j]): y[j] for j in tr}
look = lambda x: memo.get(tuple(x))   # or None
near = lambda x: y[tr][np.argmin(
    ((X[tr] - x) ** 2).sum(1))]
cuts = [(f, c) for f in (0, 1)
        for c in np.unique(X[tr, f])]
f, c = min(cuts, key=lambda k: err(  # ERM
    lambda x: x[k[0]] > k[1], tr))
cut = lambda x: int(x[f] > c)
silent = sum(look(X[j]) is None for j in te)
print(len(cuts), "cuts; best:",
      ["length", "width"][f], ">", c)
print("look", err(look, tr), silent,
      err(look, te) - silent)
print("near", err(near, tr), err(near, te))
print("cut ", err(cut, tr), err(cut, te))

Output, as printed on the image

42 cuts; best: width > 1.6
look 1 24 1
near 1 3
cut  3 3

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

Check: 30 − 24 = 6 answered · 1/70 = 1.4% · 3/70 = 4.3% · 3/30 = 10% · numpy 2.5.3 · scikit-learn 1.9.1

06 General Notes Practice

  • Hold out the test flowers first (Sprint 20)
  • Report training and test errors as counts
  • UCI's iris copy has two wrong rows (Bezdek et al. 1999); scikit-learn's follows Fisher's paper

This random split left 10 versicolor and 20 virginica in the test set. Sprint 27 starts there.

07 Mini Project Hands-on

  • Rerun with seeds 1 to 5; log all three scores
  • Split by species: 35 + 35, then 15 + 15
  • Add both sepal measurements: how many new flowers can the lookup still answer?
  • Write each rule's assumption beside its score

With all four measurements and seed 26, the lookup answers 0 of 30.

R Trusted Sources

  1. Fisher (1936). The Use of Multiple Measurements in Taxonomic Problems. Ann. Eugen. 7(2), 179–188
  2. Anderson (1935). The Irises of the Gaspé Peninsula. Bull. Am. Iris Soc. 59, 2–5
  3. Bezdek et al. (1999). Will the Real Iris Data Please Stand Up? IEEE Trans. Fuzzy Syst. 7(3), 368–369
  4. Vapnik (1991). Principles of Risk Minimization for Learning Theory. NIPS 4, 831–838
  5. Shalev-Shwartz & Ben-David (2014). Understanding Machine Learning: From Theory to Algorithms, ch. 2. CUP
  6. Mitchell (1997). Machine Learning, ch. 2. McGraw-Hill
  7. Wolpert (1996). The Lack of A Priori Distinctions Between Learning Algorithms. Neural Comput. 8(7), 1341–1390
  8. scikit-learn docs: load_iris · An introduction to machine learning with scikit-learn

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