0123450.511.52petal length (cm) →width (cm)scorew10w20b01s = w1*L + w2*W + b2guess = 1 if s > 0 else -13if guess != y:4 w1 += y * L5 w2 += y * W6 b += ySETOSAVERSICOLOR??
Plum circle: setosa · mint square: versicolor · blue ?: no label yetTeal block: the model, with weights w1, w2, bias b and the latest scoreLine on the map: the decision boundary, where the score is 0At the back, a map of six real iris flowers by petal length and petal width: setosa (plum circles) and versicolor (mint squares). Beside it, the model holds two weights and a bias, and shows each flower's score. Training sends a flower into the model; when its guess is wrong, the weights change and the decision boundary swings. After three fixes the line separates the two classes, and unseen flowers are sorted into the bin of the side they fall on. The eight flowers are real rows of Fisher's 1936 iris measurements (UCI rows 1, 3, 6, 7, 51, 54, 55 and 58). The full data set has 150 flowers of three species.

The task

  1. Linear regression predicts a number. Classification predicts a category, called a class. Our task: is an iris flower a setosa or a versicolor? With just two classes, this is binary classification.

The training loop

Using the model

What happens

;; step 1/9 · task
regression      predicts a number   (a price, a time)
classification  predicts a class    (spam or not, a digit)

our classes:  setosa      (y = -1)
              versicolor  (y = +1)
two classes = binary classification

The learner is the perceptron (Rosenblatt, 1958). On data that a straight line can separate, it is guaranteed to stop; it stops at the first line that works, not the best one. Many classifiers, such as logistic regression, turn the score into a probability with the sigmoid function 1 / (1 + e^−score): a score of 0 becomes 0.5, so "score above 0" and "probability above 0.5" draw the same line.