TL;DR
- Linear classifier without offset: . A point is classified correctly iff .
- Perceptron: start at ; whenever (a mistake), update . This is SGD with step size 1 on the linear loss .
- The distance of to the hyperplane is (signed with the label); the margin is the smallest distance of a training point: .
- Theorem 1 (Novikoff 1962): if and some separates the data with margin , the perceptron makes at most mistakes. The bound does not depend on the dimension.
- Theorem 2: trained until 0 training errors, the perceptronβs test error is at most : a fast rate , again dimension-free. The proof uses the leave-one-out principle, an early form of stability.
- Without separability there is no convergence; with the hinge-type slack one gets (Freund and Schapire 1999).
Exam relevance
- Mock exam, task 1 (2 P): run the perceptron by hand on three points in without offset, starting at , sweeping until a full sweep makes no update, counting as a mistake, and filling in a worksheet. Train it with the task below and the widget.
- Computations: distance to a hyperplane, margin of a given , the mistake bound , the generalization bound for given , , .
- Multiple choice: what the bound depends on (not on ), which loss the perceptron minimizes, rate , the role of the learning rate.
- Sheet 4, Exercise 1: margin perceptron (updates while , bound ).
Overview: 1. The perceptron algorithm, 2. The perceptron minimizes the linear loss by SGD, 3. Margin and the mistake bound, 4. Generalization error of the perceptron, 5. Outlook: the non-separable case.
The perceptron algorithm
Linear classification
Slides 3-5
(Literature: Hardt and Recht Sec. 3, Mohri Sec. 7.1, Shalev-Shwartz and Ben-David Sec. 21.4.) This lecture is a warmup: a first, simple example of how one can prove that a learning algorithm works.
Linear classifier without offset
Training points with labels . We study
without an offset parameter : the separating hyperplane passes through the origin.
Correct classification
A point is classified correctly .
The perceptron algorithm
Slide 6
Require: (x_1, y_1), ..., (x_n, y_n)
1: w_0 β 0
2: t β 1
3: N β n
4: while t β€ N do
5: if y_t β¨w_{t-1}, x_tβ© β€ 0 then β· x_t is wrongly classified
6: w_t β w_{t-1} + y_t x_t β· update w
7: else β· x_t is correctly classified
8: w_t β w_{t-1} β· keep current w
9: end if
10: t β t + 1
11: end while
As written, the algorithm makes one pass through the points. To reach 0 training errors, one cycles through the data again and again until a full pass (a βsweepβ) makes no update. This is the version used in the mistake bound and in the exam.
Ties count as mistakes
The condition is , with "". At the start , so : the first point always triggers an update. With "" the algorithm would never leave .
Task: the perceptron by hand
Exam-style task: the perceptron by hand (4 P)
Points in , no offset: with , with , with . Start with , sweep in the order and repeat until a full sweep makes no update. Count as a mistake; on a mistake set .
(a) (2 P, easy) Carry out the run: for each step give , whether it is a mistake, and afterwards.
(b) (1 P, harder) separates the data. Compute , the margin of and the mistake bound. Is your run consistent with it?
(c) (1 P, transfer) Run the update with instead. How many mistakes are made, and what is the final ?
Solution
(a) (2 P: 1 P for the first two sweeps, 1 P for sweeps 3 and 4 and the stop)
sweep point mistake? after 1 yes 1 yes 1 no 2 yes 2 yes 2 no 3 yes 3 no 3 no 4 all no stop 5 mistakes, final . Watch the ties: in sweeps 2 and 3, counts as a mistake.
(b) . With : , so . Bound β. (1 P)
(c) With , every is exactly times the of the run with , so all signs are the same: again 5 mistakes, final . The learning rate does not matter for the perceptron started at 0. (1 P)
Perceptron performs linear loss minimization
The linear loss
Slides 7-9
0-1 loss and linear loss
The βnaturalβ loss for classification is the 0-1 loss: if and 1 otherwise. To quantify βhow wrongβ the function is, one can use the linear loss
Linear loss minimization by SGD
Slides 10-12
Goal: find the linear classifier that minimizes the empirical risk
with the linear loss. How would we solve this, and how is it related to the perceptron?
Gradient descent and stochastic gradient descent
Minimize over (loss differentiable in ).
- Gradient descent: start with some , compute , update with step size (learning rate) .
- Stochastic gradient descent (SGD): start with some , pick a random , compute only and update .
Perceptron runs SGD with the linear loss
Slides 13-14
Gradient of the linear loss
An SGD step with is on a mistake and no change otherwise: exactly the perceptron update.
So the perceptron performs a simplified version of SGD (step size , one pass through the training points, in order). At the loss has a kink; the case βotherwiseβ takes there, which is why ties trigger an update.
By itself this doesnβt mean a lot. Two questions remain: (1) does it really converge to an ERM classifier that minimizes the training loss? (2) what about the test error?
Mistake bound for the perceptron
Distance of a point to a hyperplane
Slides 15-17
We want to prove: if the training points are βwell separableβ, the number of updates needed to find a classifier with 0 training error is bounded. First we make βwell separableβ precise.
Distance to the hyperplane
Let be the hyperplane with normal vector , a point with , the closest point to and the distance. Then , and since :
If , then . For a correctly classified labeled point both cases are
The margin of a separating hyperplane
Slide 18
Margin
For training points and a linear classifier that separates them, the margin is the smallest distance of a training point to the hyperplane :
Mini example
, . The point with has distance . The point with has distance . The margin of on these two points is . Scaling does not change distances or the margin.
Theorem 1: the perceptron mistake bound
Slides 19-23
Theorem 1 (perceptron mistake bound, Novikoff 1962)
Let with for all . Assume there is a separating hyperplane induced by with margin on the training points. Then the number of mistakes of the perceptron is at most
In particular, after at most updates the perceptron has found a linear classifier with 0 training errors.
Intuition
Every mistake pushes a bit towards (the projection onto grows by at least ), but the length of grows slowly (its square by at most ). After mistakes the projection is while the length is . A projection can never be longer than the vector, so , i.e. .
Proof of Theorem 1
Step 1: upper bound on . Suppose the algorithm misclassifies , so . With the update rule and :
Let be the indices where a mistake happened and . Summing over : . Without a mistake there is no update, so the sum can be taken over all steps, and it telescopes to :
Step 2: lower bound on . By the margin assumption, for all . Summing over the mistakes and using Cauchy-Schwarz:
(for mistakes , then the telescoping sum again).
Step 3: combine. and give , so .
Trap
On slide 20 the condition used in step 1 is written as "". What the proof needs is the mistake condition , which makes the cross term non-positive.
Discussing the bound
Slide 24
- The bound does not depend on the dimension .
- Implicit in the proof: SGD does not pick just any ERM minimizer, it picks a special one with nice guarantees. This is implicit regularization of SGD, which comes back in Lecture 8.
- The bound only holds under the assumption on the data (a margin). Margins pop up in many places in ML: SVMs, boosting (Lecture 6).
- The theorem only covers the separable case. In the non-separable case (or with margin 0) no bound exists.
- Learning rate in : see the assignment (and part (c) of the task above).
- The bound only considers training errors. What about generalization?
Task: margin and mistake bound
Exam-style task: margin and mistake bound (4 P)
Training data: and with label , and with label . Two candidate normal vectors: and .
(a) (1 P, easy) Compute the margin of and of on the data.
(b) (1.5 P, harder) Compute and the best mistake bound you can derive from or .
(c) (1.5 P, transfer) A new point with label is added. Is the data still separated by ? What happens to the bound, and why can a single point make it much worse?
Solution
(a) , : , so . , : , so . (1 P)
(b) . The larger margin gives the better bound: mistakes. (With : .) (1.5 P)
(c) : still separated, but the distance is only , so drops to . Also grows to . The bound becomes . The bound depends on the worst point twice: through the largest norm and through the smallest distance. (1.5 P)
Generalization error of the perceptron
Assumption: the distribution is linearly separable
Slides 25-26
To prove a generalization bound we make a strong assumption:
- A deterministic function produces the true labels, .
- The sets and are linearly separable: some hyperplane with parameters has them on different sides.
Theorem 2: bounding the test error
Slide 27
Theorem 2 (generalization error of the perceptron)
Let on be perfectly separable by a hyperplane and i.i.d. from . Let be the perceptron trained on until it makes no mistakes on . Let be the radius of the ball containing all points of , and the largest margin any hyperplane achieves on . Then the probability that the classifier trained on errs on the new point is
Discussion: scaling with and
Slides 28-29
- The generalization error does not depend on the dimension of the space. That is cool.
- Suppose the distribution lives in a ball of radius and a hyperplane separates all points of with margin . Then for all sets : and , so
Fast rate
The generalization error (0-1 loss) decreases with rate . In learning theory this is called a fast rate. (Typical rates in Lecture 3 are .)
Trap
Slide 29 writes the ratio without squares, . Theorem 2 has ; the squares matter in computations (halving the margin quadruples the bound).
Proof: the leave-one-out argument
Slides 30-33
Proof of Theorem 2
Idea: leave-one-out. Consider the augmented sample with for training and for testing, and the leave-one-out sets . Since the data is i.i.d., it makes no difference (in expectation) whether we train on and test on , or train on and test on . Let be the weight vector after training on to error 0.
Step 1.
(the same expectation for every ).
Step 2: the sum. Run the perceptron on the whole sequence from scratch. By the mistake bound it makes mistakes, at the indices (over all its cycles). If , the point never triggered an update, so removing it does not change the run: equals the final vector on , which classifies correctly. So only indices in can contribute:
Step 3. Plugging into :
The leave-one-out principle and stability
Slides 34-35
Leave-one-out principle
The average leave-one-out error on a sample of size is an unbiased estimate of the average generalization error for samples of size . (Proof: Holin p. 69/70, Lemma 4.1.)
The proof technique also hints at a principle we discuss in detail later: stability (Lecture 4). Stability asks how much the result of a learning algorithm changes if we remove one training point or replace it by a different one. With this technique one can prove very strong generalization bounds.
Task: the generalization bound
Exam-style task: generalization bound (4 P)
The data lies in a ball of radius , and a hyperplane separates the whole input space with margin . The perceptron is trained on points until it makes no training errors.
(a) (1 P, easy) Bound the test error for .
(b) (1.5 P, harder) How many training points guarantee a test error of at most ?
(c) (1.5 P, transfer) The same problem is embedded in instead of (extra coordinates are 0), and separately the margin is halved. How do the answers of (b) change?
Solution
(a) , i.e. . (1 P)
(b) . (1.5 P)
(c) The dimension does not appear in the bound: still . Halving the margin multiplies by 4, so one needs , i.e. . (1.5 P)
Outlook: what if the data is not linearly separable?
Slide 36
Then one can prove more general versions of the theorem.
Mistake bound in the non-separable case (Freund and Schapire 1999)
Given a margin , define the hinge-type loss of a point and the total slack
Then the number of updates of the perceptron is bounded by
(proof in the Mohri book). The generalization bound in this case is more complicated and only scales as .
For separable data with margin under , all , so and the bound is Theorem 1 again.
Summary
| Result | Statement | Depends on |
|---|---|---|
| Perceptron update | on : | SGD, , linear loss |
| Distance, margin | , | invariant to scaling |
| Theorem 1 (mistake bound) | and , not or | |
| Theorem 2 (test error) | rate , dimension-free | |
| Non-separable | slack ; test error only |
Self-Test
Question cards (11)
Write down the perceptron algorithm. When is a point a mistake, and what is the update?
Answer
; for each point in turn: if , set , else keep . Cycle through the data until a full sweep makes no update.
Why is the perceptron SGD, and on which loss?
Answer
The linear loss has gradient on misclassified points and 0 on correct ones. An SGD step with is on a mistake: the perceptron update.
Derive the distance of a point to the hyperplane .
Answer
Write with on the hyperplane. Taking the inner product with and using gives , so ; signed with the label, .
Define the margin of a separating hyperplane.
Answer
The smallest distance of a training point to the hyperplane: . It is invariant to rescaling .
State Theorem 1 with all assumptions.
Answer
If for all and some separates the training points with margin , the perceptron makes at most mistakes; after at most that many updates it has 0 training error (Novikoff 1962).
Sketch the three steps of the proof of the mistake bound.
Answer
(1) Each mistake increases by at most (the cross term is ), so . (2) Each mistake increases by at least , and by Cauchy-Schwarz . (3) .
What does the mistake bound not depend on, and why is that remarkable?
Answer
It does not depend on the dimension (nor on ). High-dimensional data is fine as long as the geometry (, ) is good.
State Theorem 2 and the rate it gives.
Answer
For a separable distribution and the perceptron trained on to 0 errors: . With and : , a fast rate .
What is the leave-one-out principle, and how is it used in the proof of Theorem 2?
Answer
The average leave-one-out error on points is an unbiased estimate of the expected test error for training points. In the proof, a point that never triggered an update can be left out without changing the output, so the leave-one-out errors are bounded by the number of mistakes on .
What changes if the data is not linearly separable?
Answer
The perceptron does not converge and Theorem 1 has no meaning. With the slack and , the number of updates is at most ; the generalization bound only scales as .
Does the learning rate change the behaviour of the perceptron started at ?
Answer
No. By induction , so all signs and all updates are the same, and the number of mistakes is the same.
Multiple Choice
Multiple choice (7)
The perceptron is SGD with step size 1 on which loss?
the hinge loss
the linear loss
the squared loss
the 0-1 loss
Explanation
Its gradient on mistakes gives the update . The hinge loss would also update on correctly classified points with margin below 1 (that is the margin perceptron idea of Sheet 4). The 0-1 loss has gradient 0 almost everywhere.
The mistake bound of Theorem 1 depends on
the dimension and the number of points
only the radius of the data and the margin
the learning rate and
, and the order in which the points are visited
Explanation
The bound holds for any order and any dimension. The actual number of mistakes may depend on the order, the bound does not.
, point with label . The distance of to the hyperplane is
Explanation
. forgets to divide by , forgets the label, is the distance to the origin.
Under the assumptions of Theorem 2 (separable with margin , radius ), the test error of the perceptron decays like
Explanation
: a fast rate, independent of . is the rate in the non-separable case.
The perceptron is started at with update , . Compared to ,
it makes about 5 times fewer mistakes
it makes about 5 times more mistakes
it makes exactly the same mistakes; is 5 times larger
it may not converge any more
Explanation
All iterates are scaled by , and the sign of does not change under positive scaling.
Why must count as a mistake in the perceptron?
because the linear loss is positive at 0
because otherwise the algorithm would never leave
because points on the hyperplane have margin
because the mistake bound requires
Explanation
At every point has . With a strict condition no update would ever happen. (The linear loss is 0 at 0; the update comes from the βotherwiseβ case of its gradient.)
Which statement about the leave-one-out principle is true?
The training error on points is an unbiased estimate of the test error.
The average leave-one-out error on points is an unbiased estimate of the expected test error after training on points.
Leave-one-out only works for linear classifiers.
Leave-one-out requires the data to be separable.
Explanation
This is the general insight of slide 34; it holds for any algorithm and any i.i.d. data. The training error is biased (optimistic), as Lecture 1.2 showed.
References
All sources cited on the slides, in slide order (6 entries)
Slide Source Key point 3 Hardt and Recht, Patterns, Predictions, and Actions, Sec. 3 (online) the perceptron 3, 36 Mohri, Rostamizadeh and Talwalkar, Foundations of Machine Learning, Sec. 7.1 perceptron, non-separable bound 3 Shalev-Shwartz and Ben-David, Understanding Machine Learning, Sec. 21.4 (online) the perceptron 19 Novikoff, 1962 first proof of the mistake bound 34 Holin, p. 69/70, Lemma 4.1 leave-one-out error is unbiased 36 Freund and Schapire, βLarge margin classification using the perceptron algorithmβ, Machine Learning, 1999 mistake bound for non-separable data
Related
- Previous: Lecture 1.2: Learning from Finite Samples Β· Next: Lecture 3: Statistical Learning Theory Β· Course: Overview
- Concepts: Perceptron, Margin, Stochastic Gradient Descent, Leave-One-Out Error, Empirical Risk Minimization
- Exercises: Sheet 4, Exercise 1 (margin perceptron)