🌏 中文版
Video status: Videos included. This article is written from the official MOOC handout 08_handout.pdf and transcripts of this lecture's four official videos, with formulas following the handout. The transcripts are machine transcripts made for this article (Whisper), not official captions, and no human has proofread them. The videos are taught in Mandarin; the slides are in English. Each section opens with its official video and the approximate time ranges. Page numbers refer to the number at the lower right of each slide (0/25 to 25/25), and wherever the text says "in the lecture" it is paraphrasing what is said in the video.
This is Foundations Lecture 8 in Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques. The Roadmap on page 1 of the handout places it under the second of the four big questions, Why Can Machines Learn?, and it is the last lecture on that question. The conclusion of the previous lecture, Foundations Lecture 7: The VC Dimension, takes up a single line on the same page: learning happens if is finite, is large, and is low.
That conclusion was derived under two simplifying settings: the label of every comes from one fixed target function , and right and wrong are counted only as "classified correctly or not". Real data fits neither. Labels get recorded wrong, and people with identical conditions end up with different outcomes. Mistakes also differ in weight: letting an intruder into a classified system is not the same thing as keeping an employee out. In the lecture, Lin frames this session as going back over the assumptions made while deriving the VC bound and seeing how far they can be relaxed.
The prerequisites are the bin of marbles and Hoeffding's inequality from Foundations Lecture 4, PLA and pocket from Foundations Lecture 2, and expectations and conditional probability. After reading, you should be able to do four things:
- Explain why the VC bound still holds once is replaced by , and compute of any hypothesis for a small distribution.
- Given and an error measure, derive and compute the ideal prediction (for the 0/1, squared, and absolute errors).
- Write a cost matrix as a formula for , and work out how it moves the threshold for "should I predict ".
- Explain why weighted classification equals copying examples, and which two places in pocket have to change.
Does the VC bound still hold when the data is noisy
(Video 00:19–02:22 reviews the previous lecture and the learning flow, 02:22–04:31 covers the three kinds of noise, 04:31–10:14 the color-changing marbles, 10:14–12:56 the target distribution, 12:56–15:00 the new learning flow, and Fun Time follows.)
What the original flow diagram left out
Page 2 of the handout redraws the learning flow diagram that the earlier lectures kept using. It has five components:
- At the upper left is the unknown target function , which produces the label of every .
- At the top is the unknown distribution ; the training inputs and the future test input are all drawn from it.
- Together the two produce the training examples .
- The learning algorithm picks one hypothesis from the hypothesis set .
- What it picks is the final hypothesis , and the hope is .
This page adds an orange "+ noise" inside the box for , and the bottom of the page asks: what if there is noise?
Noise came up once before, in Foundations Lecture 2 with the pocket algorithm, where the only point was that the data might not be separable. Page 3 of the handout uses the bank's credit card approval example (age 23, female, annual salary NTD 1,000,000, 1 year in residence, 0.5 year in job, current debt 200,000; approve the card or not) to list three sources:
| Where the noise is | What the handout says | The situations given in the lecture |
|---|---|---|
| good customer, 'mislabeled' as bad | A recording error, a human error, or a mistake in the formula originally used to approve cards | |
| same customers, different labels | The data comes from different sources, and expert one and expert two think differently; on a binary classification plot, two points sit on top of each other, one marked as a circle and one as a cross | |
| inaccurate customer information | The customer filled in the form inaccurately, or the data was collected inaccurately |
The derivations in the earlier lectures did not account for any of this: came from some distribution and was produced by a fixed . The question on this page is whether the VC bound still works under noise.
Color-changing marbles
Answering that means going back to where the VC bound starts. Page 4 of the handout says one key of the VC bound is marbles. The setting from Foundations Lecture 4 goes like this (the left column of the page, which the handout calls deterministic marbles):
- Each marble is an drawn from .
- The marble's color is fixed: for a hypothesis , it is orange if holds ( is wrong here) and green if not.
The fraction of orange marbles in the bin is , and the fraction counted in a handful is . Hoeffding's inequality says the two fractions are close with high probability.
The right column is the noisy version, which the handout calls probabilistic (noisy) marbles:
- A marble is still .
- The color becomes random: , where .
In the lecture, Lin describes these as marbles that change color: the color is not fixed, and a marble might be orange 60% of the time and green 40% of the time. At any single moment the whole bin still has some fraction of orange. The way to estimate that fraction is still sampling, except that the color has to be written down the instant a marble is drawn. For example, draw 100 marbles; if 20 of them are orange at the moment they are drawn, use 20% to estimate the fraction of orange in the bin at that same moment.
The handout sums up what the two columns share in one line: same nature, the sampling only has to be i.i.d. for to be estimated. The conclusion is that the VC bound holds for data of this kind:
Drawing first and then drawing according to is the same thing as drawing a pair directly from the joint distribution . In the lecture, Lin explains that the only thing VC insists on is the sampling process, so has to be sampled too; it is drawn this way in training and drawn this way in testing. The handout does not rewrite the proof, and the lecture only says that rewriting those complicated proofs with color-changing marbles leaves the conclusion unchanged.
Here is an addition in this article on why that can be believed. Fix a hypothesis and define "wrong or not" for each example as
The are independent and come from the same , so are independent, identically distributed random variables that take only the values 0 and 1, each with expectation . That is all Hoeffding's inequality needs. It does not care whether equals 1 because differs from or because noise flipped . The new and are therefore
Hoeffding for a single hypothesis holds as before. The later steps that combine many hypotheses (the growth function, the VC bound) count how many different outcomes the hypotheses can produce on , which has nothing to do with how the labels are generated. All of this is only a reason to find "the conclusion is unchanged" credible, not a complete proof: a complete proof would rewrite every step of the VC bound with , which neither the handout nor the lecture does, and this article does not either.
The target distribution and the mini-target
Page 5 of the handout gives a name: the target distribution. It characterizes the behavior of the mini-target on one . The handout offers two ways to look at it.
View one: an ideal mini-target plus noise. The handout's example is
In the lecture, Lin asks the students directly: the circle has probability 0.7 and the cross 0.3, so which do you guess? Guessing the circle is wrong 30% of the time and guessing the cross 70%, so on this the circle is the better choice. The handout calls this best choice the ideal mini-target, ; the remaining 0.3 is the 'flipping' noise level. As Lin puts it in the lecture, the 30% of the time that guessing the circle is still wrong can be seen as noise added on top of the best choice.
View two: a fixed is a special case of the target distribution. Without noise,
So every result from the first seven lectures is contained in the new setting, and none of them has to be thrown away.
The bottom of this page restates the goal of learning: predict the ideal mini-target (w.r.t. ) on often-seen inputs (w.r.t. ). Each distribution takes care of one thing. In the lecture, Lin explains the role of : a point with large is drawn often, shows up often in , and carries more weight in , so on these common points the prediction should be close to the mini-target.
Page 6 of the handout updates the flow diagram accordingly (The New Learning Flow). It differs from page 2 in two places:
- The box at the upper left changes from "unknown target function " to "unknown target distribution , containing + noise", and it produces the of the training examples.
- There is a new dashed line from this box to on the right, labeled . In the lecture, Lin says this line is drawn on purpose for emphasis: the that is compared against at test time must be generated from the same distribution too.
The bottom of the page reads VC still works, pocket algorithm explained. What pocket does is push as low as it can when the data is not separable. The explanation in the lecture is that as long as the noise can be described by a target distribution, lowering still brings down with it. When Foundations Lecture 2 taught pocket this justification was not yet available; it is supplied here.
Working it out once: E_out with noise and its lower bound
The following is an example made up for this article, not from the slides. Simplify the bank's customers into three groups, let record only which group a customer belongs to, and let mean the customer pays normally after getting the card.
| Group | ideal mini-target | The least this group can be wrong | ||
|---|---|---|---|---|
| A | 0.5 | 0.9 | 0.1 | |
| B | 0.3 | 0.6 | 0.4 | |
| C | 0.2 | 0.2 | 0.2 |
The ideal mini-target column uses the rule from a moment ago: guess the side with the larger probability. For any hypothesis , can be computed by fixing and taking the expectation over first, then taking the expectation over :
If predicts on a group, the probability of error on that group is ; if it predicts , it is . Three hypotheses work out as follows:
| Hypothesis (predictions on groups A, B, C) | Computing | Result |
|---|---|---|
| , the ideal mini-target on every group | 0.21 | |
| , approve everyone | 0.33 | |
| , approve no one | 0.67 |
Each of the three groups has two possible predictions, for eight hypotheses in total; compute all eight and the smallest is 0.21. This result says two things. First, has a lower bound that is not 0: even knowing the complete and guessing the right side on every group, you are still wrong 21% of the time. That part is noise, and no change of model removes it. Second, only the gap above the lower bound is the hypothesis's responsibility: the 0.33 of approving everyone exceeds 0.21 by 0.12, all of it from guessing the wrong side on group C ().
Now look at sampling. The program below draws 1,000 examples from this joint distribution and computes for two hypotheses:
import random
random.seed(8)
P_pos = [0.9, 0.6, 0.2] # probability of y = +1 in groups A, B, C
data = []
for _ in range(1000):
r = random.random()
g = 0 if r < 0.5 else (1 if r < 0.8 else 2) # draw a group with 0.5 / 0.3 / 0.2
y = +1 if random.random() < P_pos[g] else -1 # draw the label from P(y|x)
data.append((g, y))
for name, h in [("ideal", (+1, +1, -1)), ("always +1", (+1, +1, +1))]:
print(name, sum(h[g] != y for g, y in data) / 1000)
The output is ideal 0.204 and always +1 0.308; against the values 0.21 and 0.33, the gaps are 0.006 and 0.022. For a single hypothesis, the guarantee from Hoeffding is , and both gaps are within 0.05. The labels are random and the sampling estimate is just as accurate, which is what the color-changing marbles are saying.
This article adds one more commonly used special case. Suppose there is a fixed underneath, and each label is flipped independently with probability (). Let , the error rate of without noise. On an where and agree, counts as wrong only when the label is flipped, with probability ; on an where they disagree, it counts as wrong only when the label is not flipped, with probability . So
With and this is . Because , the smaller the computed against the noisy labels, the smaller is as well: picking a hypothesis with noisy data points in the same direction as picking one without noise. Only the numbers differ: is multiplied by and then is added, so the lowest it can go is .
Fun Time: does separability of the data tell you whether f is linear
Question (page 7): Let's revisit PLA/pocket. Which of the following claim is true?
- In practice, we should try to compute if is linear separable before deciding to use PLA.
- If we know that is not linear separable, then the target function must not be a linear function.
- If we know that is linear separable, then the target function must be a linear function.
- None of the above
Answer: 4. Each of the three claims goes wrong in a different place.
- Choice 1. The handout's answer is: after computing if is linear separable, we shall know and then there is no need to use PLA. To confirm the data is linearly separable you have to find a line that separates it, and that line is exactly what PLA was going to give you. In the lecture, Lin says that logically one usually would not do this.
- Choice 2. The handout writes only What about noise?. can be linear, yet once noise is added to the labels the data is no longer separable; the lecture points to the situation in the pocket figure of Foundations Lecture 2.
- Choice 3. The handout writes What about 'sampling luck'?. The lecture gives two kinds of luck: is actually curvy, and the points that happened to be drawn can be separated by a line; or is noisy, and you were lucky enough that the drawn data missed every point the noise affected.
Lin spends some time in the lecture on the idea behind this question: a property of the data does not necessarily let you infer a property of . The guarantee VC gives runs in a different direction: get a low , pair it with a small , and you have a low . It does not say that must be linear or must not be linear.
How to score g: error measures and the ideal prediction on each x
(Video 00:01–02:02 sorts out the three properties of the original E_out, 02:02–04:10 covers pointwise error, 04:10–05:55 the 0/1 and squared errors, 05:55–11:30 the ideal mini-target, 11:30–14:10 the flow diagram with an error measure and the extension of VC, and Fun Time follows.)
The original E_out made three choices
The last box of the flow diagram is . "How close counts as close" needs a way of scoring, and in the lecture Lin calls this giving a score: someone hands you a , you have an in mind that you want, and there has to be some way to tell them whether it is good or not. Page 8 of the handout first writes out the one the earlier lectures used all along:
More generally there is an error measure . The handout points out that the original naturally made three choices:
- out-of-sample: averaged over unknown .
- pointwise: evaluated on one at a time. The contrast drawn in the lecture is that it does not need to draw ten at once and apply some combined measure; score one point at a time and take the average at the end.
- classification: only matters, that is, right or wrong.
The third is often also called the 0/1 error. In the lecture, Lin explains the name: there are only two cases, where being right costs 0 and being wrong costs 1.
Pointwise error measures
Page 9 of the handout isolates the "pointwise" part. Many error measures can be expressed as the average of some function over individual points, and the original is one of them:
is called the pointwise error measure. With it, the error on the training data and the error on the distribution are two averages of the same :
The formulas on this page are written with . The lecture adds a remark that ties them to the setting of "The target distribution and the mini-target": in the noisy setting, the in the formula is really , and the in is likewise replaced by a drawn from the distribution, so what is measured is the difference between and . By page 20, where the handout writes weighted classification, the formulas use directly.
The handout says that for simplicity it will mainly consider pointwise from here on. The reason given in the lecture is that other measures are usually more complicated, some are hard to handle, and they often have to start from the pointwise form anyway.
The two most important err
Page 10 of the handout renames the two inputs of : the prediction is written and the target is written . It then lists the two that will be used again and again:
| 0/1 error | squared error | |
|---|---|---|
| Definition | ||
| What it asks | correct or incorrect? | how far is from ? |
| Often for | classification | regression |
The lecture's explanation of the squared error: a difference of 2 gives an error of 4 and a difference of 10 gives an error of 100, so the error grows faster the farther away you are. It suits regression because demanding "exactly the same" makes no sense when the output is a real number; if the target is 3.141592, a guess of 3.14 may already be very accurate, so what matters is distance, not right or wrong.
The bottom of this page asks: how does 'guide' learning?
err and P(y|x) together decide the ideal mini-target
The subsection "The target distribution and the mini-target" said the ideal mini-target is "the best prediction on this ". In the 0.7 versus 0.3 example, the best prediction was to guess the more probable one. Page 11 of the handout points out that this answer actually depends on the error measure: and define the ideal mini-target . The example is an with three possible outputs:
For each candidate prediction , compute its average error on this , . The handout's table lists only the results; the computation is as follows.
| Average 0/1 error | Average squared error | |
|---|---|---|
| 1 | ||
| 2 | (smallest) | |
| 3 | ||
| 1.9 | (smallest) |
The 0/1 column: when predicting , any other value of is a mistake, so the average error is the total probability of the other values. With a prediction of 1.9, none of the three possible equals 1.9, so it is always wrong and the average error is 1.0. The handout puts "really? :-)" next to this number. As Lin says in the lecture, guessing 1.9 under the 0/1 error gets you laughed at, because it is not even a possible answer.
The squared column: , , , and weighting them gives , slightly below the 0.3 of predicting 2. The 1.9 that was just laughed at becomes the best prediction once the error is squared.
With the same , changing moves the ideal prediction from 2 to 1.9. The handout writes the general result for the two cases below the table:
The handout does not prove these two. In the lecture, Lin says the proofs are not hard and encourages everyone to try. The derivations below are additions in this article.
The 0/1 error. When predicting some possible value , the average error is
Making it smallest means making largest, that is, choosing the with the highest probability. Predicting a value outside gives an average error of 1, which cannot be better.
The squared error. Treat the average error as a function of :
It is a quadratic function of whose coefficient is , so it opens upward, and its minimum is where the derivative equals 0:
The second equality uses the fact that the probabilities sum to 1. The best prediction is the average with the probabilities as weights, which the lecture calls the weighted mean. Plugging in the example: .
Write this mean as . can then be split into two pieces (write as and expand; the cross term vanishes because ):
The second piece does not depend on . It is the variance on this , and it is also the noise the squared error cannot remove at this point. In the example it equals 0.29, so the squared column of the table can be checked at a glance: predicting 1 gives , predicting 2 gives , and predicting 3 gives .
The flow diagram gains a component
Since changes what "the ideal target" is, it has to appear in the flow diagram. Page 12 of the handout (Learning Flow with Error Measure) adds a blue ellipse, error measure , at the lower right, with two arrows coming out of it: one points to the final , meaning it is used to judge how good is; the other points to the algorithm , meaning the algorithm has to know it too. In the lecture, Lin explains the second arrow: if the algorithm is not told, it may keep its head down and do very well on the 0/1 error while what we care about is the squared error, and the two can be worlds apart.
The bottom of this page reads: extended VC theory/'philosophy' works for most and . The lecture says what has to change without going into details: for regression, for instance, you first have to define how the VC dimension of "functions with real-valued output" is computed; after definitional changes of this kind you get a VC bound that is almost the same or very similar. Lin says plainly in the lecture that these derivations are too tedious and nobody is asked to walk through them; what he hopes people remember is the spirit: although the earlier lectures derived everything only in the restricted setting of "binary classification, a fixed , and the 0/1 error", the conclusion carries over to other problems and other error measures.
Fun Time: the ideal mini-target for the absolute error
Question (page 13): Consider the following and . Which of the following is the ideal mini-target ?
- 2.5 = average within
- 2.85 = weighted mean from
- 3 = weighted median from
- 4 =
Answer: 3. The handout's answer is a single sentence: for the 'absolute error', the weighted median provably results in the minimum average err. The lecture suggests that the simplest approach is to plug the four numbers in and compare, and says the weighted median is the number at the place where the probability accumulates to about one half. First, plug in the numbers as the lecture suggests:
| Choice | Average absolute error | Result | |
|---|---|---|---|
| 1 | 2.5 | 1.000 | |
| 2 | 2.85 | 0.965 | |
| 3 | 3 | 0.950 | |
| 4 | 4 | 1.150 |
The smallest is . The lecture mentions that each of the four numbers has its own meaning but does not go through them. This article fills that in: choice 4 is the ideal mini-target for the 0/1 error (the most probable value is 4), choice 2 is the one for the squared error (), and choice 3 is the one for the absolute error. Choice 1 does not use the probabilities at all and treats the four values as equally likely. For the same distribution, three error measures give three different ideal predictions: 4, 2.85, and 3.
Why the median? The derivation here is an addition in this article. Let . Move slightly to the right: its distance to every on its left increases and its distance to every on its right decreases, so wherever is not equal to any ,
The slope is "the probability on the left" minus "the probability on the right". While the probability accumulated on the left is below one half, the slope is negative and moving right lowers the error; past one half, the slope is positive. The minimum is at the where the cumulative probability crosses 0.5. In this question the cumulative probabilities are 0.10, 0.45, 0.60, 1.00, crossing 0.5 at . Check against the slope: for between 2 and 3 it is , and between 3 and 4 it is , so falls to the left of 3 and rises to its right. The table's numbers confirm it as well: going from 2.85 to 3, the error drops by , which is exactly .
Where the error measure comes from: the application decides err, and the algorithm picks a separate êrr
(Video 00:00–02:20 covers fingerprint verification and the two types of error, 02:20–05:00 the supermarket, 05:00–06:57 the CIA, 06:57–11:55 err and êrr, 11:55–12:36 the updated flow diagram, and Fun Time follows.)
The two types of error in fingerprint verification
Page 14 of the handout uses fingerprint verification as the example. The classifier looks at a fingerprint and outputs for you and for an intruder. The use case given in the lecture is deciding whether you are the owner of this computer, which you may use only if the fingerprint matches. This classifier can make two types of error:
| (accept) | (reject) | |
|---|---|---|
| (you) | no error | false reject |
| (intruder) | false accept | no error |
A false accept lets in someone who should have been rejected; a false reject turns away someone who should have been accepted. The handout notes at the bottom of the page: 0/1 error penalizes both types equally. In the lecture, Lin explains that the earlier algorithms only count the number of mistakes, a circle turned into a cross and a cross turned into a circle each counting as one, and pay no attention to how important the two types are relative to each other.
Supermarket and CIA: one problem, two cost tables
Pages 15 and 16 of the handout put the same fingerprint verification into two settings, each with its own table whose numbers are the cost paid for a mistake.
The supermarket uses fingerprint verification to decide whether to give a discount, which only regular customers get.
| Supermarket | ||
|---|---|---|
| 0 | 10 | |
| 1 | 0 |
- False reject: the handout writes very unhappy customer, lose future business. The lecture makes it concrete: a regular who comes every day does not get the discount, gets very angry, never comes back, and tells friends not to come either, so what the supermarket loses is all the business afterward.
- False accept: the handout writes give away a minor discount, intruder left fingerprint. In the lecture, Lin says the store only earns a little less, and the other person has left a fingerprint in the system, so tracking them down is not hard.
The CIA uses fingerprint verification to control entry (the handout writes fingerprint for entrance); in the lecture, Lin describes it as deciding whether an employee may get into some system to see classified information.
| CIA | ||
|---|---|---|
| 0 | 1 | |
| 1000 | 0 |
- False accept: the handout writes very serious consequences. Someone without clearance sees classified information.
- False reject: the handout writes unhappy employee, but so what?. In the lecture, Lin says the employee at worst silently curses the lousy system and scans again; for the CIA's overall goal, an unhappy employee matters comparatively little.
In the lecture, Lin calls this kind of table a cost table and says it is sometimes called an error table. Both tables have 0 on the diagonal, since a correct classification costs nothing; they differ in which type of error is more expensive.
Where a cost table pushes the decision threshold
The following is an example made up for this article. It runs the two tables through the method of the subsection "err and P(y|x) together decide the ideal mini-target": and together decide the ideal mini-target, and now is a cost table.
Suppose a fingerprint has , that is, an 80% chance of being you. Predicting is wrong only when (a false accept), and predicting is wrong only when (a false reject):
| Average cost of predicting | Average cost of predicting | ideal mini-target | |
|---|---|---|---|
| 0/1 error | |||
| Supermarket | |||
| CIA |
For the same fingerprint that is 80% likely to be you, the supermarket should accept and the CIA should reject. The threshold can be derived directly in the general case. Let , let the cost of a false accept be , and let the cost of a false reject be . The average cost of predicting is , and that of predicting is . Predicting is the cheaper choice when
| Threshold | |||
|---|---|---|---|
| 0/1 error | 1 | 1 | |
| False reject costs 3 times a false accept (a number assumed in this article) | 1 | 3 | |
| CIA | 1000 | 1 |
The threshold for the 0/1 error is 0.5, which is "guess the more probable side". When a false reject is more expensive the threshold drops below 0.5: if a false reject costs 3 times a false accept, you should predict whenever the probability of it being you is above 25%. The supermarket's table also belongs to this class where a false reject is more expensive, which is why the 80%-you fingerprint above should be accepted at the supermarket. When a false accept is more expensive the threshold rises, and the CIA accepts only when it is more than 99.9% sure. A cost table does not change ; it changes the ideal mini-target, so the two settings want classifiers that look different. The lecture's summary is that saying "binary classification" does not mean always scoring by classification error; the same binary classification is a completely different situation at the CIA and at the supermarket.
The true err and the êrr the algorithm uses
Page 17 of the handout is titled Take-home Message for Now, and its first line is: is application/user-dependent. The error measure is decided by the application and the user.
In the ideal case the user hands you and you use it directly in the algorithm. In the lecture, Lin says this often cannot be done and takes his own number as the example: the CIA's 1000 is something the lecturer made up, and if you really asked the CIA, they could not say whether it should be 1000 times, 2000 times, or 5000 times. Users have an idea in mind, but turning it into numbers an algorithm can handle is hard.
So what the algorithm uses when it optimizes is often a different error measure, which the handout writes as (algorithmic error measure). In the lecture, Lin explains the hat: it is not necessarily identical to what the user really cares about. The handout lists three sources of :
true: just . If the user can supply it, this is best.
plausible: one you can give a reason for. The lecture describes it as a way that convinces ourselves. The handout gives two:
- The 0/1 error corresponds to minimum 'flipping noise'. The lecture goes back to the idea behind pocket: assume the misclassified points are all flipping noise and that there is little of it, and then finding the hypothesis with the smallest 0/1 error makes sense. The handout adds a reminder after this line: NP-hard to optimize, remember?, which is something Foundations Lecture 2 brought up before introducing pocket.
- The squared error corresponds to minimum Gaussian noise. The lecture's explanation: if you believe the noise is Gaussian, the exponent of the Gaussian distribution has a squared term, and making the squared term as small as possible is like looking for the smallest Gaussian noise.
This article writes that second remark as a formula. Suppose , where is Gaussian noise with mean 0 and standard deviation ; then the probability density of seeing is proportional to . The probability density of independent examples appearing together is the product over the examples, and taking the logarithm turns it into a sum:
The that makes the data look most likely is the that minimizes the sum of squared errors. This argument only shows that the squared error is plausible, on the premise that the noise really is close to Gaussian.
friendly: easy to optimize. The 0/1 error is plausible but very hard to optimize, so a third kind is needed: one that is friendly to the algorithm . The handout gives two:
- closed-form solution. As Lin puts it in the lecture, you write down the formula, compute straight through, and have the solution right away.
- convex objective function. The lecture's analogy is that minimizing is just like a ball rolling down from the mountain into the valley.
The bottom of the page reads : more in next lectures. As an addition in this article, here are the two instances coming up: linear regression in Foundations Lecture 9 uses the squared error and has a closed-form solution; logistic regression in Foundations Lecture 10 uses an error that is convex.
Page 18 of the handout updates the flow diagram once more (Learning Flow with Algorithmic Error Measure): the ellipse is still at the lower right and still points to and ; the ellipse of the algorithm now contains a small piece labeled . The bottom of the page states the division of labor in two lines: is the application goal, and is a key part of many . The lecture's description of is that it is the piece of the algorithm that tries to make our lives a little easier.
Fun Time: writing the CIA cost table as E_in
Question (page 19): Consider the CIA cost table (false accept 1000, false reject 1) as . What is when using this err?
Answer: 2. The key is keeping straight which class of examples each type of error happens on. Examples with are intruders; when is wrong on such an example it lets an intruder in, which is a false accept and costs 1000. Examples with are you; a mistake there is a false reject and costs 1. So the 1000 multiplies the sum over .
The handout's answer calls this error a false positive: when , the false positive made on such an example is penalized 1000 times more. This is the same thing as the false accept of the earlier pages (a negative judged as positive), and the lecture still says false accept when explaining this question.
The other choices: choice 1 is the original 0/1 error, with both types weighing the same. Choice 4 multiplies the 1000 onto the mistakes with , so the heavily penalized error becomes the false reject, the opposite direction from the CIA (closer to the supermarket, with a different multiple). Choice 3 makes the false accept term negative, so the more intruders get in, the lower becomes.
This article checks with a small set of numbers. Take , with 3 examples of you and 2 intruders; falsely rejects 2 of you and falsely accepts 1 intruder. The four choices come to , , , and . Adding up example by example from the cost table gives , and dividing by 5 gives 200.4, in agreement with choice 2.
Learning when the two errors are not equal: weighted classification and copying examples
(Video 00:01–02:54 defines weighted classification, 02:54–05:55 covers the intuitive modification and the doubt about it, 05:55–09:32 copying examples, 09:32–12:50 weighted pocket and reduction, 12:50–14:58 Fun Time, and the summary of the whole lecture follows.)
E_in and E_out for weighted classification
Page 20 of the handout calls the CIA table a Cost (Error, Loss, …) Matrix. In the lecture, Lin goes through the names: cost, loss, and error are used by different books and papers and mean roughly the same thing, something you want to be as small as possible; this course tries to stick with error. The rows of the table are the true and the columns are :
| CIA | ||
|---|---|---|
| 0 | 1 | |
| 1000 | 0 |
According to this table, the out-of-sample and in-sample errors are
Inside the braces is the weight of the example, and the after it is still right or wrong. The formula for is the answer to the Fun Time question "writing the CIA cost table as E_in", written another way. The handout calls this kind of problem weighted classification: different 'weight' for different .
The lecture first clears up something easy to confuse: the weight here is the importance of each example, which is a different thing from the weight vector of the line in PLA. It then gives an analogy: like an exam where each question carries different points, some worth a thousand points and some worth only one. The weight also need not depend only on ; another possibility mentioned in the lecture is that different customers have different importance.
The intuitive modification, and what it is missing
VC theory still applies here (the lecture asks everyone to take this on trust), so the remaining question is the same as before: how to make small. To tell it apart from the original 0/1 version, page 21 of the handout writes the weighted version as and the original as . The page is titled Naïve Thoughts, and it checks the two algorithms already in hand:
- PLA: the handout writes doesn't matter if linear separable. When the data is linearly separable, PLA ends with a line that makes no mistakes at all, . With no example misclassified, is also 0 whatever the weights are, and 0 is already the minimum. So PLA does not need to care about weights at all; just run it.
- pocket: when the data is not separable PLA does not halt, and pocket is needed. Only one step in pocket involves : if the newly found is better than the in the pocket, swap it in. The intuitive modification is to make the standard for "better" a weighted one: if reaches smaller than , replace by .
This modification looks reasonable. The handout asks at the bottom of the page: the original pocket has some guarantee on ; does the modified pocket have a similar guarantee on ? The lecture is blunter: taking an algorithm and changing one line relies on the intuition in your own head, which Lin half-jokingly calls "manual-labor intelligence" (a play on the Chinese word for artificial intelligence); after such a change, it is not clear whether the theoretical guarantee is still there. The next step is to find a modification with a justification.
Copying the −1 examples 1000 times
Page 22 of the handout is titled Systematic Route: Connect and . The approach is to connect the weighted problem to the 0/1 problem we already know how to solve. The page has a left column and a right column:
| original problem (left) | equivalent problem (right) | |
|---|---|---|
| Cost table | false accept 1000, false reject 1 | false accept 1, false reject 1 (the 0/1 error) |
| Data | : every example appears once | every example with appears once, every example with appears 1000 times |
The handout's conclusion: after copying examples 1000 times, for the left-hand side is equivalent to for the right-hand side.
The lecture explains it by collecting money. Suppose makes a false accept on . The data on the right has 1000 copies of this example; if is wrong on one copy it is wrong on the other 999 too, because they are the same . If each mistake is charged one dollar, pays a thousand dollars for this example on the right. A mistake on a example costs just one dollar. So the money collected on the right at "one dollar per mistake of either type" is exactly the money collected on the left according to the cost table, and one dollar per mistake of either type is the 0/1 error.
This article writes that passage as a formula. Say makes false accepts and false rejects on , and contains examples of and examples of (). Call the data set after copying ; its size is . Then
The two have the same numerator, and the denominators differ by a constant that does not depend on . Strictly speaking, then, the two numbers are not equal, and the symbol the handout uses is "≡"; but for any two hypotheses, whichever has the smaller on the left has the smaller on the right, and the that minimizes one minimizes the other. For the purpose of "finding the best hypothesis", the two problems are the same problem.
The right-hand side is ordinary 0/1 classification, so pocket can be used directly and its original guarantee applies along with it (the lecture adds that Lin never actually proved this guarantee and only asked everyone to trust it). So the simplest solution appears: really copy the examples and hand them to the original pocket.
Weighted pocket: copying only in your head
Real copying costs extra memory, disk, and time. In the lecture, Lin says one generally does not do it for real, but designs the algorithm while imagining that the data has already been copied. Page 23 of the handout calls this virtual copying and lists the two steps that are affected when the original pocket runs on . Together the two steps are the weighted pocket algorithm:
- weighted PLA: in each round, the PLA inside pocket picks an example at random and checks whether it is misclassified. Picking at random on , each example has 1000 copies, so it is picked with 1000 times the probability of each example. The handout writes: randomly check example mistakes with 1000 times more probability.
- weighted pocket replacement: comparing on equals comparing on . So if reaches smaller than , replace it.
The second step is the one line that intuition came up with a moment ago. What the intuitive modification missed is the first step: the probability of picking an example has to follow the weights too. It takes the systematic route to see that.
The lecture also points out an advantage of writing it this way. Copying can only be done a whole number of times, but "multiply the picking probability by the weight" has no such restriction: with a weight of 11.26, just raise the probability to 11.26 times.
At the bottom of the page the handout gives this approach a name: systematic route, also called reduction, and stresses that it can be applied to many other algorithms. In the lecture, Lin says it resembles how theoretical computer science transforms one problem into another in order to solve it; the binary classification algorithms taught later can all be extended to weighted versions in the same way. Later in this series, Techniques Lecture 8: AdaBoost uses the idea of "every example carries a weight" again.
A numerical example: eight points, three cost tables
The following is an example made up for this article, not from the slides. Use the positive rays from Foundations Lecture 5 as the hypothesis set: if , and otherwise. The input is one-dimensional; think of it as the similarity score from a fingerprint matching system, which accepts when the score exceeds the threshold . There are 8 examples, 4 of you and 4 intruders:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
|---|---|---|---|---|---|---|---|---|
The data is not "all on the left, all on the right", so every threshold misclassifies a few. The 8 points cut the number line into 9 segments, and taking one in each segment covers every distinct way of splitting. For each , count the false rejects ( but ) and the false accepts ( but ), then apply the three cost tables:
| False rejects | False accepts | 0/1: | Supermarket: | CIA: | |
|---|---|---|---|---|---|
| 0.5 | 0 | 4 | 0.5 | 0.5 | 500 |
| 1.5 | 0 | 3 | 0.375 | 0.375 | 375 |
| 2.5 | 0 | 2 | 0.25 | 0.25 | 250 |
| 3.5 | 1 | 2 | 0.375 | 1.5 | 250.125 |
| 4.5 | 1 | 1 | 0.25 | 1.375 | 125.125 |
| 5.5 | 2 | 1 | 0.375 | 2.625 | 125.25 |
| 6.5 | 3 | 1 | 0.5 | 3.875 | 125.375 |
| 7.5 | 3 | 0 | 0.375 | 3.75 | 0.375 |
| 8.5 | 4 | 0 | 0.5 | 5 | 0.5 |
Take : are classified as . is you but gets rejected (), and is an intruder but gets accepted (). The CIA's weighted error is .
What this table shows.
- The 0/1 error ties at and , both 0.25; it cannot tell these two thresholds apart.
- The supermarket picks : a low threshold that rejects no regular customer, at the price of letting in two people who should not get the discount.
- The CIA picks : the threshold goes above the highest-scoring intruder (), so no intruder gets in, at the price of rejecting 3 of the 4 legitimate users. Its 0/1 error is 0.375, worse than 0.25, but that is not the number the CIA cares about.
- The weighted is no longer a fraction between 0 and 1 and can be far larger than 1. Its unit is "average cost paid per example".
Checking the claim about copying examples. Copy each of the 4 examples of 1000 times and has examples. is wrong on examples of , so ; is wrong on 3, so . For every , on divided by on is , the constant from before. The nine thresholds rank identically on both sides, and the best is in both. This article actually built the copied data in a program and counted example by example, and all nine rows match.
The picking probabilities of weighted PLA. Picking one example uniformly on , the probability of picking one particular intruder example is , and the probability of picking one particular example of you is . The four intruder examples together take of the checks, so the algorithm spends nearly all its effort on "do not let the wrong person in".
Fun Time: with very unbalanced data, how bad is the hypothesis that always accepts
Question (page 24): Consider the CIA cost matrix. If there are 10 examples with (intruder) and 999,990 examples with (you). What would be for a constant that always returns ?
- 0.001
- 0.01
- 0.1
- 1
Answer: 2. Always returning gets all 999,990 examples of you right and falsely accepts all 10 intruders, each at a cost of 1000. With :
Choices 1, 3, and 4 are off by factors of 10, 10, and 100, which amounts to misreading the number of intruders or the weight by one digit.
The handout's answer says that while the quiz is a simple evaluation, it is not uncommon that the data is very unbalanced for such an application, and that properly 'setting' the weights can be used to avoid the lazy constant prediction. The lecture explains why this number is worrying: intruders are rare to begin with, so the data will have this kind of ratio; a hypothesis that accepts whoever shows up is obviously terrible, but 0.01 is a very small number and the computer may think it is doing fine.
This article adds a few numbers to make it clearer. Under the 0/1 error this hypothesis is wrong only of the time, nearly perfect, and the weight of 1000 has already magnified its error 1000 times, yet it is still only 0.01. Compare a hypothesis that takes the job seriously: it catches all 10 intruders but falsely rejects 2% of the legitimate users (about 20,000 examples), so , which is worse than the 0.01 of always accepting. From the copying point of view the reason is direct: 10 intruders copied 1000 times are only 10,000 examples, still only about 1% of one million. To make "always accept" as bad as "always reject" (error ), the weight would have to go up to . So the numbers in a cost table have to be read together with the ratio in the data; the lecture's conclusion is that adjusting the weights is one common way to deal with unbalanced data.
As an addition in this article, here is a working procedure: when you face an unbalanced classification problem, first write down the cost of each of the two types of error, then decide whether to adjust the weight of each example (the approach of this section) or to adjust the decision threshold (the approach of the subsection "Where a cost table pushes the decision threshold").
Summary of this lecture
Page 25 of the handout wraps each of the four sections into one line:
| Section | Conclusion |
|---|---|
| Noise and Probabilistic Target | can replace by |
| Error Measure | affect 'ideal' target |
| Algorithmic Error Measure | user-dependent; when the user cannot supply it, plausible or friendly |
| Weighted Classification | easily done by virtual 'example copying' |
The preview at the bottom of the page is next: more algorithms, please?. In the lecture, Lin says this session ends the more theoretical part of Foundations, and the next three or four lectures will teach more algorithms. The Roadmap likewise moves from the second question, Why Can Machines Learn?, to the third, How Can Machines Learn?.
Self-check
1. On some , , , and . Find the ideal mini-target under the 0/1 error, the squared error, and the absolute error, along with the minimum average error for each.
Answer: The 0/1 error picks the most probable value, , with average error . The squared error picks the weighted mean , and the average error is the variance . The absolute error picks the weighted median: the cumulative probabilities are 0.45, 0.60, 1.00, crossing 0.5 at , so it is 1, with average error (predicting 0 gives 4.15 and predicting 4.15 gives 4.68, both larger). The three answers 0, 4.15, and 1 differ a lot because of the faraway : it pulls the squared error toward itself, while the absolute error and the 0/1 error are hardly affected.
2. There is a fixed underneath, and labels are flipped at random with probability 0.2. A hypothesis disagrees with on 10% of the . What is the of computed against the noisy labels? How low can the best hypothesis go? If you measure for some hypothesis, how should you read it?
Answer: . The best hypothesis is itself, with and . Rubric: the reading has to say that 0.2 is the lower bound caused by noise, and that means this hypothesis is already close to the best, not "it is wrong 20% of the time, so the model is bad"; to compare hypotheses, look at the part above the lower bound.
3. A fingerprint has . What is the ideal mini-target under the CIA cost table and under the supermarket cost table?
Answer: CIA: the average cost of predicting is and of predicting is , so predict (0.95 does not exceed the threshold ). Supermarket: predicting costs and predicting costs , so predict . For the same fingerprint that is 95% likely to be you, the CIA still rejects.
4. , with 900 examples of and 100 examples of . A hypothesis makes 30 false rejects and 2 false accepts. With the CIA cost table, what are and ? After copying the examples 1000 times, how large is the data set? What is the 0/1 error of on it?
Answer: . . After copying there are examples, is wrong on of them, and the 0/1 error is . , which is . There are only 2 false accepts, yet they make up of the weighted error.
5. To turn pocket into weighted pocket, which two places have to change? If you change only the "pocket replacement rule", what is missing?
Rubric: the answer has to state (a) when picking an example at random to check, an example with a larger weight must be picked with proportionally higher probability; and (b) and are compared using . It also has to explain that both points come from "the original pocket running on the copied data": picking uniformly after copying is automatically the weighted probability. The version that changes only the replacement rule is not the original pocket on any data set, so there is no reason for the original guarantee to carry over automatically.
Exercises and corresponding reading
How the two semesters map. In Fall 2024 the slides for this lecture are 08u_handout.pdf, which has only three sections and drops the MOOC version's Weighted Classification. Fall 2026 likewise lists only the first three videos of this lecture in the required pre-class viewing for W4 (09/30). This article keeps the weighted classification section because the MOOC still has that video and because AdaBoost in Techniques uses the idea of every example carrying a weight. These mappings were checked on 2026-09-30.
Textbook. Both course pages map this lecture to 1.4 of Learning from Data (LFD).
Homework. Fall 2024 HW3 (released 2024-10-07, due 10-21, covering Lectures 7 to 10) has two problems related to this lecture. There are no official solutions, and grading is for enrolled students only:
- Q6: under the supermarket's error measure (a false reject is 10 times as important as a false accept), the ideal target becomes ; find . This article derived the general form of the threshold in "Where a cost table pushes the decision threshold"; that is this article's derivation, not an official solution, and for the homework's setting go by the problem statement. When you are done, plug in a few concrete and check that your really minimizes the average cost under the supermarket's cost table.
- Q7: the lecture has two definitions of , one compared against and one against . Prove the inequality between them, in which stands for the noise that cannot be removed. The flipping-noise formula in this article's "Working it out once" subsection is a special case of it and is a good way to build intuition first.
For the other HW3 problems see the Foundations homework guide. According to the course page, hw2 of Fall 2026 is scheduled for release on 10/07 and was not yet public when checked on 2026-09-30.
Access. The videos and handouts are free and public; the Fall 2024 homework PDF is public too, but without official solutions.
An English-language counterpart. Caltech Learning from Data uses the same textbook, and Error and Noise is its Lecture 4; its Lecture 8 is Bias-Variance Tradeoff, a different route from Lin's, which makes Lecture 8 Noise and Error.
Next lecture. Foundations Lecture 9: Linear Regression moves into How Can Machines Learn? and uses this lecture's squared error as to derive an algorithm with a closed-form solution.
Course video sources
Original videos: Noise and Probabilistic Target, Error Measure, Algorithmic Error Measure, Weighted Classification
Checked: 2026-10-13. The video IDs, titles, and lengths were taken from the official playlist that day; the videos have no caption track on YouTube, and what this article reports from the lecture comes from transcripts made for it.
Update Log
- 2026-10-13: The series now has one article per lecture; this lecture is a newly split-out article, written from the handout and the video transcripts.
References
- Foundations Lecture 8 handout, 08_handout.pdf: the main source for this article. The content of the four sections, the flow diagrams, the cost tables, and the four Fun Time questions all come from this handout.
- Machine Learning Foundations YouTube playlist: the IDs and titles of the four videos; what the text reports as said "in the lecture" is paraphrased from machine transcripts of these four videos.
- Hsuan-Tien Lin > MOOCs: the official entry for handouts and recordings.
- Fall 2024 slides for Lecture 8 (08u_handout.pdf): confirms that Fall 2024 teaches only the first three sections.
- Machine Learning, Fall 2024 course page: the corresponding LFD chapter.
- Machine Learning, Fall 2026 course page: the required pre-class viewing for W4 and the schedule of hw2.
- Fall 2024 Homework 3 (hw3_red.pdf): the content of Q6 and Q7.
- Learning from Data textbook website: the source of section 1.4.
- Caltech Learning from Data telecourse: the English-language counterpart course.
- Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques: Course Overview: where this lecture sits in the whole course and the reading routes.
Loading...