🌏 中文版
Video status: Videos included. This article is written from the official MOOC handout 14_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/22 to 22/22), and wherever the text says "in the lecture" it is paraphrasing what is said in the video.
This is Foundations Lecture 14 in Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques. The Roadmap on page 1 of the handout divides Foundations into four questions, and this lecture belongs to the fourth, How Can Machines Learn Better? The previous lecture, Foundations Lecture 13: Hazard of Overfitting, is down to one line on that page: overfitting happens with excessive power, stochastic/deterministic noise, and limited data. That lecture compared the remedies to driving, and the one called "putting on the brakes" is this lecture's subject, regularization.
There are four prerequisites: the matrix form and the gradient from Foundations Lecture 9: Linear Regression, the polynomial transform and the nested hypothesis sets from Foundations Lecture 12: Nonlinear Transformation, the VC bound from Foundations Lecture 7: The VC Dimension, and inner products and perpendicularity of vectors. You do not need to have studied Lagrange multipliers; this lecture explains them with geometry.
After reading, you should be able to go from the constraint to the closed-form solution on your own, compute the solution for different values of by hand on a small data set, and explain how , , and the effective VC dimension move together, and why L1 gives sparse solutions.
Here is the whole derivation of the lecture first:
- Step back to a lower-order polynomial: this is the same as adding a constraint to the higher-order problem.
- Soften the constraint: from "these particular coefficients are 0" to "at most this many are nonzero", and then to "the sum of squared coefficients is at most ".
- Geometric condition: at the optimal solution, the negative gradient of is parallel to , with the ratio set by .
- Solve for a given : solve one linear equation and get a closed-form solution.
- Switch to an unconstrained problem: minimize the augmented error.
- Connect back to VC theory: regularization makes the effective VC dimension smaller.
- Switch to other regularizers: L1, symmetry, and how large should be.
Writing "step back to a lower-order polynomial" as a constraint: the regularized hypothesis set
(Video 00:17–03:53 reviews the previous lecture and gives the idea of regularization, 03:53–08:54 writes stepping back as a constraint, 08:54–14:18 covers the looser constraint, 14:18–18:37 covers the softer constraint, and Fun Time follows.)
The goal: get from the right figure to the left one
Page 2 of the handout shows two figures. The horizontal axis is and the vertical axis is ; each figure has five data points, a blue target function, and a red fit.
| Right figure (overfit) | Left figure (regularized fit) | |
|---|---|---|
| Red curve and the data | Passes through every point; is very low | Does not pass through every point |
| Shape of the red curve | Swings widely up and down between the points | Smooth |
| Red curve and blue curve | Far apart; is large | Almost on top of each other |
The right figure is the overfitting from the previous lecture. In the lecture, Lin says it is what you get when you fit a small amount of data with a polynomial of order four or higher, and that the left figure comes from a lower-order polynomial. So the job is to "step back" from the hypothesis set of high-order polynomials to a low-order one. The handout writes the idea as step back from to , and next to it draws the nested rings from Foundations Lecture 12: .
The handout also says where the name comes from: regularization comes from function approximation for ill-posed problems. The explanation in the lecture is that ill-posed means too many functions satisfy the conditions, so you do not know which one to pick and have to narrow the range first. Regression is this kind of problem too: the data is only finitely many points, and a great many functions pass through them.
Stepping back is adding a constraint
Page 3 of the handout uses a one-dimensional input with the -th order polynomial transform as the example:
Linear regression follows the transform. Under the earlier notation, the weights in the transformed space should be written . On this page the handout announces that will simply be written ; the reason given in the lecture is to avoid having a crowd of little worms flying around in the formulas. This article follows the handout: from here on is the weight vector after the transform, and the transformed data is written .
The hypotheses in the two hypothesis sets look like this:
Set through to 0 in a hypothesis of and what remains is a hypothesis of . The handout writes it this way: AND "constraint that ". So step back = constraint.
Page 4 turns this sentence into optimization problems. On both sides is an 11-dimensional vector (the handout writes ):
The way the lecture puts it: the problem on the left accepts every 11-dimensional vector, while the problem on the right does not even look at vectors that fail the condition and searches for the best one only among those that satisfy it.
At the bottom of the page the handout asks a question on the students' behalf: why don't you just use ? If you want a 2nd-order polynomial, three coefficients are enough, so why take the detour? The answer in the lecture is that this step is taken to widen the view. Once the problem is written as "a big set plus a constraint", you can adjust the constraint, and the later derivation becomes easier.
Looser: only say how many coefficients are 0
The constraint of says which eight coefficients are 0. Page 5 loosens it: require only that at least eight are 0, whichever eight they are. At least eight equal to 0 means at most three not equal to 0:
is 1 when the condition holds and 0 when it does not, so the sum counts the nonzero coefficients. The handout lists how this set relates to the other two:
- : more flexible than . Every that satisfies " through are all 0" also satisfies "at least eight are 0".
- : less risky than . In the lecture, Lin says it is not as all-encompassing as , so it may overfit less easily.
An example added in this article: has only three nonzero coefficients, so it is in but not in .
A hypothesis like this, with most coefficients equal to 0, is called a sparse hypothesis. The lecture mentions its benefit: when predicting later you only compute the three nonzero terms and add them up, instead of computing every term.
The bad news is at the bottom of the page: minimizing over is NP-hard. The intuition given in the lecture is that the in the constraint is a discrete function. Foundations Lecture 2: Perceptrons and PLA first ran into it in the perceptron's 0/1 error, and it was already clear then that functions of this kind are hard to optimize. This article adds one number to give a feel for it: just choosing "which three coefficients may be nonzero" out of 11 has possibilities, and once the dimension grows, trying them one by one is not feasible.
Softer: the sum of squared coefficients is at most C
Page 6 switches to a constraint that is easy to handle. The old one counted how many coefficients are nonzero. The new one measures how large the coefficients are: add up the square of every coefficient and require the total to be at most an upper limit fixed in advance:
The thinking in the lecture: a coefficient that is 0 or very close to 0 has a small square, and a coefficient that is not 0 has a large one. So the sum of squares can serve as a continuous version of "how many are nonzero", and it avoids the discrete function. can be a number like 13, 15, or 11.7.
The handout says two things about .
First, it overlaps with but is not exactly the same. The three 11-dimensional vectors below are examples made up for this article, not from the slides, with :
| Nonzero count | In ? | In ? | ||
|---|---|---|---|---|
| 2 | Yes | Yes | ||
| 1 | Yes | No | ||
| 11 | No | Yes |
The third row is the case described in the lecture: a hypothesis whose coefficients are all small but none of them 0 is in and not in .
Second, it forms a nested structure as varies. The handout calls it a soft and smooth structure over :
offer only 11 levels to choose from, while is a real number; in the lecture, Lin says this amounts to infinitely many hypothesis sets lined up by the size of . means no constraint, which is the original ; at the other end, contains the single hypothesis .
The handout calls the regularized hypothesis set and writes the optimal solution found in it as . The conclusion of this section: a regularized hypothesis set is the original hypothesis set plus a constraint.
Fun Time: which one is not in H(1)
Question (page 7): For , which of the following hypothesis (weight vector ) is not in the regularized hypothesis set ?
Answer: 3. Compute for each choice and compare it with 1:
- Choice 1: , so it is in the set.
- Choice 2: , exactly on the boundary, which still counts as in the set.
- Choice 3: the sum of squares of ones is . Because , this number is at least 2, which exceeds 1, so it is not in the set.
- Choice 4: copies of add up to exactly 1, on the boundary and also in the set.
The question says for a reason: when , choice 3 has a single component, its sum of squares is 1, and it is in . Choices 2 and 4 have the same length; one puts all the length on a single coefficient and the other spreads it evenly over all of them. does not care how the length is distributed, and that is also where it differs from .
Solving the constrained problem: Lagrange multipliers, augmented error, and weight decay
(Video 00:00–01:57 writes the matrix form, 01:57–09:03 explains the Lagrange multiplier with geometry, 09:03–12:40 finds the closed-form solution for a given λ, 12:40–17:20 covers the augmented error, 17:20–19:39 looks at the results for different λ, 19:39–23:08 covers Legendre polynomials, and Fun Time follows.)
First, the matrix form
Page 8 writes the problem with vectors and matrices. Stack the transformed data points row by row into a matrix and the labels into a vector . Foundations Lecture 9 derived , and the handout writes "remember?" next to it. The in the constraint is the inner product of with itself:
The constraint has a geometric meaning: a feasible lies inside a ball centered at the origin with radius (the handout writes hypersphere). Every outside the ball is ruled out.
Geometry: at the optimal solution, the negative gradient is parallel to w
Page 9 thinks about the problem with a two-dimensional figure. The figure has three things:
- Blue ellipses, labeled , are the contour lines of . Their center is , the linear regression solution with no constraint. In the lecture, Lin says is like a valley whose bottom is at .
- A red circle, labeled , is centered at the origin. A feasible solution has to be inside the circle.
- A point on the circle, with three arrows drawn from it: the blue points toward the side where the valley bottom is, the red normal points outward from the origin, and the green arrow runs along the tangent of the circle.
With no constraint, the gradient descent taught in Foundations Lecture 10: Logistic Regression rolls down along all the way to . Now the ball is in the way. If is already inside the ball, it is the answer and the constraint does nothing. In the lecture, Lin says that most of the time this is not the case: is outside the ball, and the solution we want is then on the boundary of the ball.
This article adds the reason for the boundary: is a convex function. If the optimal solution were in the interior of the ball, you could move in every direction around it, yet no direction would make smaller, so it would be the bottom of the whole valley, , contradicting " is outside the ball".
The next question is how to tell whether a given on the sphere is the optimal solution. The handout does it in four steps:
- The decreasing direction is .
- The normal vector of the sphere is itself. The sphere is , and the direction from the origin to a point on the sphere is perpendicular to the sphere there. Moving outward along this direction rolls out of the ball and violates the constraint; the directions perpendicular to it run along the sphere, and in the lecture, Lin says a small step that way still stays on the sphere.
- If and are not parallel, split into a component along the normal vector and a component perpendicular to it. The latter is the green arrow in the figure, and it is not zero. Moving along the green arrow decreases without leaving the sphere. The handout's wording is can decrease without violating the constraint. This is not the optimal solution.
- So at the optimal solution , the green component must be zero, that is,
Two vectors are parallel when one equals the other times a number. The handout writes this ratio as :
In the lecture, Lin says the extra 2 and are there only to make the coming derivation convenient. is called the Lagrange multiplier, an important tool for solving constrained optimization problems; the four steps above are its geometric meaning, and someone who has never studied it can understand it from this geometry. The handout states the goal as: find a Lagrange multiplier and such that this equation holds.
This article adds why is positive. Rearranged, the equation reads , and means the negative gradient points out of the ball: the valley bottom is outside the ball, so the downhill direction is outward. If the negative gradient pointed into the ball, one step inward would be feasible and would also decrease , so that point would not be the optimal solution either.
Someone tells you λ: solve one linear equation
The unknowns have gone from a single to plus , and in the lecture, Lin voices the complaint for the students: the problem seems to have become more complicated. Page 10 of the handout handles this by first assuming an oracle tells you (in the lecture, a classmate who somehow knows everything). The only unknown left is then .
Foundations Lecture 9 computed the gradient of linear regression: . Substitute it into the parallel condition:
Everything in the equation except is a known number, and appears only to the first power; the lecture stresses that this is a linear equation. Multiply both sides by , and the 2 and added earlier cancel here:
Write as ( is the identity matrix), combine the two terms that contain , and move to the right:
Compared with , the only addition is . The handout notes that this is called ridge regression in Statistics.
The last step uses an inverse matrix. Does it always exist? In the lecture, Lin says it always does when : is positive semi-definite, adding a positive makes it positive definite, and a positive definite matrix is always invertible. This article fills in the calculation behind that sentence. For every that is not the zero vector:
The first term is never negative, and the second is strictly greater than 0 when . If the matrix were not invertible, it would send some nonzero to the zero vector and the expression above would equal 0, a contradiction. The of Foundations Lecture 9 may fail to be invertible when there is too little data and then needs the pseudo-inverse; with added that problem is gone, and the solution is unique.
Another angle: minimizing the augmented error
The second version of page 10 reads the same equation in a different way. The starting point in the lecture: need not be that of linear regression. It could be that of logistic regression, where there is no closed-form solution, so how should this condition be read then?
We used to solve because we wanted to minimize . What we have to solve now is "the gradient plus some term equals zero", so look for a function whose gradient is exactly that whole left-hand side. In the lecture, Lin describes this as running differentiation backward into integration. The partial derivative of with respect to is , so , and therefore
The right side is the left side of the parallel condition. So solving the parallel condition is the same as minimizing
The extra term is called the regularizer and the whole function is called the augmented error, augmented meaning "with something added on". This new problem has no constraint at all; the lecture puts it as the original condition having moved inside the thing being minimized. The handout writes the procedure as:
is allowed too. The regularizer then disappears and we are back to the original problem of minimizing only .
This also changes which parameter the user supplies. The way the lecture tells it: originally the user gives and we still have to find the that corresponds to it; since every corresponds to some , we may as well ask the user for directly. For the user, giving either one takes about the same effort, and for us, having leaves just one unconstrained problem to solve. The conclusion at the bottom of the page is: minimizing unconstrained effectively minimizes some -constrained .
This article adds a check that does not rely on the figure, to confirm that the converse also holds. Given , let be the minimizer of and take . For every that satisfies , rearranging gives
The second inequality uses . So really is the one with the smallest in .
Numerical example: three data points, λ from 0 to 100
What follows is an example made up for this article, not from the slides. So that it can be drawn in the plane and matched against the figure on page 9, has only two dimensions: no high-order transform, , and the hypothesis is the line . There are three data points:
| 1 | |||
| 2 | |||
| 3 |
Step 1: compute the two matrices.
is symmetric about 0, so is a diagonal matrix and its inverse can be written down directly.
Step 2: the solution without regularization. . The three predictions are , the errors are , and . .
Step 3: plug into the closed-form solution. The diagonal of is and , so
Take : . The three predictions are , and their differences from are , so
rises from to , and the squared length of falls from to .
Step 4: check the parallel condition. At :
And . The two add up to the zero vector, and the negative gradient points in the same direction as .
Step 5: compare with the constrained problem. This lies on the circle with squared radius . Take another point on the same circle, for example :
- , higher than .
- .
- The normal vector is the direction of , . Splitting the negative gradient, the component along the normal vector is and the component perpendicular to it is , which is not zero.
This is the green arrow in the figure on page 9: moving along the circle in the direction of increasing lowers further, and the green component vanishes only on reaching . For this article, a program cut this circle into two million points and computed at each one; the minimum occurs at , in agreement with the closed-form solution.
Step 6: sweep over .
| (the equivalent ) | ||||
|---|---|---|---|---|
What this result means. As goes up, gets shorter and shorter, the equivalent gets smaller and smaller, and gets higher and higher. When is very large, is pressed close to the zero vector, the line becomes almost , and approaches . raises by only , while raises it by almost . The two coefficients are also shrunk by different ratios: at , is multiplied by and by , so the direction with the smaller number on the diagonal of shrinks more.
In the other direction, a given also has its , but you have to solve the equation : corresponds to , to , and to . When , is already inside the circle and . This equation has no simple formula for its solution and needs a numerical method. When the lecture says that a user who gives leaves us the extra work of finding the corresponding , this is the step it means.
If you want to recompute it yourself, the program below prints every row of the table above:
import numpy as np
Z = np.array([[1, -1], [1, 0], [1, 1]], dtype=float)
y = np.array([1, 3, 2], dtype=float)
N = len(y)
for lam in [0, 0.1, 1, 3, 10, 100]:
w = np.linalg.solve(Z.T @ Z + lam * np.eye(2), Z.T @ y)
e_in = np.mean((Z @ w - y) ** 2)
print(lam, w.round(3), round(w @ w, 3), round(e_in, 3), round(e_in + lam / N * (w @ w), 3))
The four figures in the handout and the name weight decay
Page 11 goes back to the five data points from the start of the lecture and fits them with four different values of . The four figures, from left to right:
| What the red curve looks like | The handout's label | |
|---|---|---|
| Passes through every point and swings widely between them | overfitting | |
| Smooth, almost on top of the blue target | ||
| Smooth, starting to move away from the target, not passing through every point | ||
| A very flat curve, far from the target | underfitting |
is the original result of minimizing only . In the lecture, Lin says that adding as little as already makes the red curve smooth and close to the blue one; when is raised a lot the curve is still smooth but far from the blue one again, which is the underfitting from the previous lecture. The handout sums up the lesson in one sentence: a little regularization goes a long way. Lin says in the lecture that this borrows the saying "a little goes a long way", whose original meaning is that a little effort can accomplish a lot.
The handout then gives the method a name: it calls weight-decay regularization and lists three equivalent things:
The explanation in the lecture is that acts like a penalty on a long : the thing being minimized contains times the squared length, so the longer is, the more it is penalized. The name weight decay refers to making the weights smaller. The table in the numerical example above is an instance of these three things.
This article adds another reading of the name, using the gradient descent from Foundations Lecture 10. Run gradient descent on and each step is
is the step size. As long as is positive and not too large, the number in the parentheses is between 0 and 1: every step first shrinks the old weights a little and then updates with the original gradient.
The bottom of the page has one more line: go with 'any' transform + linear model. In the lecture, Lin says this lecture uses the polynomial transform plus linear regression as its example, and the same regularization can also be paired with logistic regression or with other transforms. This article adds: paired with logistic regression there is no closed-form solution, and you can minimize with the gradient descent formula above.
One detail: Legendre polynomials
Page 12 explains a treatment behind those four figures. In the lecture, Lin says that to make the results look a bit better, a small trick was applied to the transform. Written out, the regularized problem is
This page of the handout prints the index of the first sum as to . The data is numbered from the 1st point to the -th, and page 8 writes the same sum with , so the formula above uses to .
If is the original polynomial transform (the handout calls it the naïve polynomial transform) and lies in , then is extremely small when is large. For example, at , . The handout's note reads: really small, needing large . For a high-order term to affect the result it has to come with a very large coefficient, and large coefficients are exactly what regularization penalizes. In the lecture, Lin says this amounts to over-penalizing the high-order terms: the low-order part is tolerated a lot, while regularization comes down too hard on the high-order part. The lecture also mentions that numbers this small cause precision problems.
The handout's approach is to switch to another basis, which it calls the normalized polynomial transform:
are the Legendre polynomials. The handout lists the formulas and graphs of the first five:
| Formula | |
|---|---|
is still a polynomial of order , so the functions this basis can form are exactly the same as with the original . The hypothesis set has not changed; what changes is which set of coefficients represents the same function. The lecture describes it as a change of coordinates: the original coordinates are not perpendicular to one another, which is what causes trouble for regularization. If you think of functions as vectors with infinitely many dimensions, you can require their pairwise inner products to be 0, and the Legendre polynomials are what you get by orthogonalizing the original polynomials. In linear algebra this procedure is called Gram–Schmidt orthogonalization; that name is an addition in this article.
This article backs the passage with two calculations. Take the inner product of functions to be :
- The original basis is not perpendicular: and , neither of which is 0.
- The Legendre polynomials are pairwise perpendicular: for this article, were multiplied in pairs and integrated, and every pair of different ones gives 0.
The handout calls this basis 'orthonormal basis functions'. Computed directly from the formulas the handout lists, the inner product of each one with itself is (for to , in order, ), which is not 1. So strictly speaking these formulas are orthogonal, and each still has to be multiplied by a constant to have unit length. This does not affect the point the handout is making: they are perpendicular to one another.
How much the same function is penalized under the two bases differs a great deal. Take :
| Basis | Coefficients | |
|---|---|---|
| Legendre | , the rest 0 | |
| Original polynomials | , , |
It is the same curve, but written in the original basis its weight decay penalty is 33 times as large. is more extreme, at to . The advice in the lecture: this is only a supplementary detail, but remember that when you later do polynomial regression with regularization, Legendre polynomials will work better.
Fun Time: when the regularized solution equals the original one
Question (page 13): When would equal ?
- all of the above
Answer: 4. The handout says choices 1 and 2 shall be easy, and that choice 3 means there is effectively no constraint on .
- Choice 1: when , , and the in the closed-form solution disappears too, leaving . In the lecture, Lin says this is like covering up the regularizer.
- Choice 2: when , and there is no constraint.
- Choice 3: says that itself satisfies the constraint. It has the smallest among all and it is feasible, so it is also the smallest among the feasible ones. The way the lecture puts it, the red ball is large enough to contain .
Choice 2 is in fact a special case of choice 3. Applied to the numerical example: , so and both give , and the corresponding is 0 in both cases; the constraint starts to matter only when drops below . The handout writes the range of as " or ", and this shows why has to be included: a whole range of maps to the same .
What regularization corresponds to in VC theory: the effective VC dimension
(Video 00:00–01:52 covers the two formulations and the VC guarantee, 01:52–05:00 puts the augmented error and the VC bound side by side, 05:00–07:42 covers the effective VC dimension, and Fun Time follows.)
Not confined to H(C), yet getting its guarantee
The second part of Foundations (Why Can Machines Learn?) ended with the VC bound: is no larger than plus a price for model complexity. This section asks how regularization relates to that theory.
Page 14 draws three boxes:
| Box | Content |
|---|---|
| Upper left: regularization by constrained minimization | s.t. |
| Upper right: its VC guarantee | |
| Lower left: minimizing the augmented error |
An arrow goes from the upper left to the upper right: if you really pick hypotheses only from , the complexity in the VC bound is computed with that of , which is smaller than that of the whole . Between the upper left and the lower left is a two-way arrow labeled equivalent to some , the conclusion of "Another angle: minimizing the augmented error" above.
What we actually do is the lower-left one. In the lecture, Lin calls this being lazy: set a and solve, without going back to work out what it corresponds to. The handout's conclusion is: minimizing : indirectly getting VC guarantee without confining to . The lecture explains what "indirectly" means: there is no constraint during optimization, so every is under consideration, but each carries an extra penalty that says which ones are liked and which are not; the finally chosen falls in some , and the guarantee in the upper right speaks about that .
Two Ωs: one measures a hypothesis, one measures a hypothesis set
Page 15 puts two formulas side by side:
Both sides are plus a term, and the added terms are different:
- The regularizer measures how complex a single hypothesis is. The lecture thinks of it with polynomials: a high-order polynomial is wiggly and a low-order one is smooth, and this term speaks about how complex the curve represented by is in itself.
- The of the VC bound measures how complex the whole hypothesis set is; the handout calls it the generalization price. In the lecture, Lin says it stands for how many choices there are.
The lecture notes that the symbol is being overloaded here: the regularizer is written as well, and is used for everything that is a complexity. The handout continues: if 'represents' well, then is a better proxy of than . The reason given in the lecture: a very complex polynomial should, in some sense, live in a very complex hypothesis set, so the two kinds of complexity are related.
The handout splits the benefit of minimizing into two lines:
- (heuristically) operating with the better proxy: doing the work with a better stand-in.
- (technically) enjoying flexibility of whole : still free to choose within the whole .
The lecture states explicitly that the first line is a heuristic and not mathematics; it only compares where the two formulas look alike. This article adds a reminder as well: this does not say that is an upper bound on .
How much is actually used: the effective VC dimension
Page 16 asks from another angle: when you regularize, how much of the price for model complexity do you actually pay? Write the problem in a general form, with the dimension after the transform written :
The handout answers in three lines:
- Counted by the rules: . Every is considered during minimization (the handout writes all considered), so the hypothesis set is the whole .
- What is actually needed is only , with the equivalent to . The way the lecture puts it: it looks like everything is considered, but only a few end up near the valley bottom, the ones inside .
- So is called the effective VC dimension and written . is the algorithm, which here is "minimize ".
The point is that takes two arguments. Model complexity used to be measured by the hypothesis set alone; in the lecture, Lin says the hypothesis set and the algorithm now have to be looked at as one package, by how the algorithm chooses within the hypothesis set and how much of its power it actually uses. If the algorithm puts on the brakes in there (adding a regularizer is putting on the brakes), the VC dimension it uses may be smaller than that of the whole hypothesis set, and generalization may improve with it.
The handout's explanation of regularization is these three lines:
The lecture calls this a "conceptual" definition. The handout gives no formula for computing , and no proof that the inequality still holds once it is substituted into the VC bound.
Back to the three-point example
What follows is an addition in this article. In the earlier example is all lines , and the price counted by the rules is fixed, independent of . The set actually used, however, shrinks with :
| The set containing the chosen | |
|---|---|
| , in effect the whole | |
, each smaller than the next. By , the absolute value of the slope cannot exceed , and the same holds for the intercept; all that can still be drawn is a small bunch of gentle lines close to . "All lines" and "this small bunch of lines" sit in the same , and what the handout is saying is that the complexity of the latter is the price actually paid.
The handout gives no number for . Statistics has a separate, commonly used quantity for ridge regression called the effective degrees of freedom, defined as . It is not the same definition as the handout's ; it is borrowed here only to see that "the effective number of parameters decreases continuously". In this example it equals : at it is 2, exactly the number of coefficients; at it is ; at it is ; and at it is about .
Fun Time: what happens to the effective VC dimension as λ grows
Question (page 17): Consider the weight-decay regularization with regression. When increasing in , what would happen with ?
- ↑
- ↓
- and does not depend on
- and does not depend on
Answer: 2. The handout's answer is a chain of equivalences:
The first relation was seen in the table that sweeps over in the numerical example: as goes from 0 to 10, the equivalent drops from to . With a smaller , is a smaller ball whose hypotheses are a part of the original ones; when a hypothesis set gets smaller, its VC dimension does not get larger.
Choice 1 has the direction backward. The in choice 3 is the number counted by the rules, and it really does not depend on , but it is not ; the two are equal only when , with no regularization at all. The 1126 in choice 4 is a number this course often uses in examples ( is another one) and has no basis whatsoever.
Other regularizers: three directions for choosing, L1 and L2, and how large λ should be
(Video 00:00–05:18 covers the three directions for choosing a regularizer, 05:18–09:32 compares L2 and L1, 09:32–11:43 looks at the optimal λ, 11:43–12:19 is Fun Time, and the summary follows.)
Three directions for choosing a regularizer
Everything so far has used . Page 18 asks: if we switch to a more general , what principles are there? The handout opens with: want: constraint in the 'direction' of target function. The way the lecture puts it, the best constraint would of course be knowing the target function directly, but in machine learning that is exactly what you do not know; one step back, if someone can tell you roughly which direction the good hypotheses lie in, narrowing the range toward there is also very good.
The handout lists three ways to choose:
| Choice | Meaning | The handout's example |
|---|---|---|
| target-dependent | If you know some properties of the target function, put them in | Symmetry regularizer |
| plausible | Pick a direction you can convince yourself of: toward smoother or simpler hypotheses | Sparsity (L1) regularizer |
| friendly | Easy to optimize | Weight-decay (L2) regularizer |
target-dependent. The example in the lecture: if you believe the target is an even function or very close to one, press down only the coefficients of the odd powers, and let the coefficients of the even powers grow a bit. This article adds why this is right: an even function satisfies ; in a polynomial, the even-power terms have this property and the odd-power terms change sign, so a polynomial that is an even function has only even-power terms.
plausible. Under this item the handout gives the reason on a gray background: stochastic/deterministic noise both non-smooth. The lecture ties it back to the previous lecture: regularization is used against overfitting, overfitting comes from noise, and both kinds of noise jump around and are not smooth; the target function should be smooth relative to the noise, so choose smooth hypotheses more often. L1 is covered in detail in the second half of this section, and in the lecture, Lin says it is fairly useful in practice.
friendly. Weight decay belongs to this class. In the lecture, Lin says it only adds a squared term, so the whole optimization problem stays about the same as the original.
What if you pick a bad regularizer? The handout writes: bad? no worries, guard by . The explanation in the lecture is that the regularizer is multiplied by , so as long as is among the candidates, the worst case is not using it at all. That is the last line of protection.
The bottom of the page has a comparison, and the handout asks "ringing a bell?" In the lecture, Lin says that when Foundations Lecture 8: Noise and Error Measures chose an error measure there were three possibilities: the user tells us what they want, we pick one we can convince ourselves of, or we pick one that is easy to optimize. The two sides follow the same scheme:
| Three ways to choose | |
|---|---|
| Error measure | user-dependent, plausible, friendly |
| Regularizer | target-dependent, plausible, friendly |
The handout writes the augmented error as error + regularizer . Each of the two parts of has three ways to be chosen, and in the lecture, Lin says these are three important aspects of designing a machine learning algorithm.
L2 and L1: a circle and a diamond
Page 19 puts the two regularizers side by side, each with a geometric figure.
| L2 regularizer | L1 regularizer | |
|---|---|---|
| Formula | ||
| Convexity | Convex | Convex |
| Differentiability | Differentiable everywhere | Not differentiable everywhere |
| Characteristic | Easy to optimize | Sparsity in solution |
| Shape of the constraint (two dimensions) | Circle | Diamond |
The left figure is the same as on page 9. The right figure replaces the red circle with a red diamond whose four vertices are on the coordinate axes. In the lecture, Lin says the graph of the absolute value function is pointed, with its point at , where it is not differentiable, so L1 is somewhat harder to solve than L2; it is still convex, though.
The in the right figure is drawn on an edge of the diamond, not at a vertex. Whether it is the optimal solution is decided by the same check: is the negative gradient parallel to the normal vector of the boundary? The red arrow in the figure is labeled sign, and in the lecture, Lin says the direction perpendicular to this edge is the vector you get by taking the sign of each component of . An example added in this article: the edge where both components are positive is , every point on it has signs , and the normal vector is .
This is where the difference lies. This article spells it out a little more: every point on the circle has a different normal vector, so wherever points, some point on the circle has a normal vector parallel to it. A whole edge of the diamond has only one normal vector, and would have to point exactly in the direction , which rarely happens. The way the lecture puts it: on an edge, the negative gradient is usually not parallel to the normal vector, so there is always a green component pulling along the edge, and it stops only at a vertex. A vertex is on a coordinate axis, which means some are 0. So the optimal solution with L1 often occurs at a vertex, and what you get is a sparse solution.
The handout's conclusion is L1 useful if needing sparse solution. The lecture uses a phone as the example: train a 1126-dimensional , and by the time the phone has computed every dimension its battery is gone; if only five of them are nonzero, the phone computes just five terms, which is faster and saves power.
Comparing L1 and L2 on the same data
What follows is a calculation made up for this article, not from the slides, reusing the three data points from before. First complete the square in . Expand directly:
Then complete the squares:
This is the valley: its bottom is at with height , and the contour lines are ellipses. and have no cross term, so after adding the L1 regularizer , the two coefficients can be minimized separately. Look at the part alone (multiplying by 3 does not move the minimizer):
- If the minimizer is at , then there, and differentiating gives , so . This answer counts only if it is positive, that is, if .
- When , the derivative on the part is always positive, so the value gets smaller toward 0; on the part both terms get smaller toward 0. The minimizer is at .
The same goes for : , which becomes 0 only when . Put next to the L2 solution :
| L2 solution | L1 solution | |
|---|---|---|
L2 multiplies each coefficient by a ratio; however large gets, the coefficient only gets closer and closer to 0 and is never exactly 0. L1 moves each coefficient toward 0 by a distance that does not depend on the size of the coefficient (here moves and moves ), so the already small is quickly moved to 0 and then stays there. At the L1 solution is , the hypothesis becomes the horizontal line , and the slope term is gone entirely. That is sparsity. For this article, the L1 minimizer at was also checked with a grid search; it lands at , in agreement with the formula's .
How large λ should be: it depends on how much noise there is
Page 20 has two figures from experiments. The horizontal axis of both is (0 to 2), the vertical axis is the expected , and a dot marks the lowest position on each curve.
| Three curves | Position of the lowest point | |
|---|---|---|
| Left figure, stochastic noise | , , | is at ; the larger , the further right the lowest point |
| Right figure, deterministic noise | , , | is at ; the larger , the further right the lowest point |
(Reading the figures by eye, the lowest points for and are both a little past , and those for and are just over ; the handout lists no numbers.)
is the variance of the stochastic noise and is the order of the target polynomial; both are notation from the previous lecture. The lecture explains that the right figure learns with a 15th-order polynomial, so the curve has no deterministic noise, has some, and has a lot.
The handout draws two conclusions:
- more noise ⟺ more regularization needed. The handout ties this back to the driving analogy of the previous lecture: more bumpy road ⟺ putting brakes more.
- noise unknown: how much noise there is cannot be known in advance, so it is important to make proper choices.
The way the lecture puts it, you have to pick the best one out of many values of for regularization to do its job. How to pick is left to the next lecture, which the lecture previews as teaching not only how to choose but also how to choose the transform and which linear model to use.
Fun Time: a different penalty on every term
Question (page 21): Consider using a regularizer to work with Legendre polynomial regression. Which kind of hypothesis does the regularizer prefer?
- symmetric polynomials satisfying
- low-dimensional polynomials
- high-dimensional polynomials
- no specific preference
Answer: 2. The handout's answer: there is a higher 'penalty' for higher-order terms, and hence the regularizer prefers low-dimensional polynomials. (The slide's low-dimensional and high-dimensional mean low-order and high-order polynomials.)
The multiplier in front of each is : 1 for , 2 for , 32 for , and 1024 for . A coefficient of the same size costs 1024 times as much on as on the constant term. To keep small, the cheapest thing to do is press the coefficients of the high-order terms very small, and the chosen hypothesis ends up close to a low-order polynomial. The way the lecture puts it, a very heavy regularization has been placed on the high-order part.
Choice 1 corresponds to the symmetry regularizer that penalizes only the odd-order terms; this question penalizes odd and even orders alike, so it has no preference for symmetry. Choice 3 has the direction backward. Choice 4 is wrong because the multiplier differs from term to term; there would be no preference only if they were all 1, and that is weight decay again. This article adds: the question demonstrates how to write a preference into . If you want low-order, simpler hypotheses, raise the multipliers on the high-order terms; in the classification on page 18 of the handout, moving toward simpler hypotheses belongs to the plausible class.
The lecture in four sentences
The summary on page 22 reduces each of the four sections to one line:
- Regularized Hypothesis Set: the original plus a constraint.
- Weight Decay Regularization: add in .
- Regularization and VC Theory: regularization decreases .
- General Regularizers: target-dependent, plausible, or friendly.
The preview of the next lecture is choosing from the so-many models/parameters.
Self-check
1. Two data points: , ; , . Do weight-decay linear regression with and . Compute , , and , and compare with .
Answer: and . At , , the line passes through both points, and . At , , the two predictions are and , and ; , and .
2. Continuing from the previous question, the user gives instead of . What corresponds to ? What about ?
Answer: , and its squared length is . Setting it equal to gives , so . , so already contains in the ball, the constraint does nothing, and .
3. Someone says: "When you minimize the augmented error, every w can be chosen, so the hypothesis set is still the whole H, the VC dimension is still d̃ + 1, and regularization does not help generalization." Which part of this is right, and where is the problem?
Criterion: the answer should say that the first half is right, since really is ; the problem is that it looks only at the hypothesis set and not at how the algorithm chooses. Once is given, the chosen falls in some , and the handout uses for this complexity actually paid, which is smaller than and gets smaller as gets larger. Better still if the answer adds that the handout gives only a conceptual definition and no formula.
4. There is a single coefficient . Minimize and separately. What do you get for each? What difference between L1 and L2 does this show?
Answer: for the first, the derivative gives , so . For the second, when the derivative is , always positive, so the value decreases toward 0; when both terms decrease toward 0; the minimizer is . L2 shrinks to half but not to 0, and L1 gives 0 outright.
5. Represent in the Legendre basis and in the original polynomial basis. What is the weight decay in each? How does this relate to "high powers of x are small"?
Answer: in the Legendre basis only , and the sum of squares is 1. In the original basis and , and the sum of squares is . For the absolute value of is never larger than that of , and over the middle stretch it is far smaller, so to make up a function value of the same size the high-order term needs a larger coefficient, and it is penalized more heavily as a result.
Exercises and corresponding reading
Correspondence across two semesters. The Fall 2024 course page schedules Foundations Lectures 13 and 14 in the same week (W7, 10/14), and the slides for this lecture are 14u_handout.pdf. The Fall 2026 course page also places it in W7 (10/21); when checked on 2026-09-30 the slide link for that week was still a 404, so this article uses only the MOOC handout.
Textbook. Both course pages map this lecture to Section 4.2 of Learning from Data (LFD).
Homework. None of the questions below has an official solution. Fall 2024 HW4 was released on 2024-10-21 and due on 11-04, and HW5 was released on 11-04 and due on 11-18.
| Homework | Question | Content | Where it connects to this lecture |
|---|---|---|---|
| HW4 | Q9 | Generate virtual examples by adding Gaussian noise to the inputs and derive the form of the expected value of a matrix; a note in the question points out its relation to the matrix that regularized linear regression inverts | The data hinting of the previous lecture connects to this lecture's |
| HW5 | Q1 | Write additive smoothing as an estimation problem with a regularizer and find | General regularizers |
| HW5 | Q5 | Prove that linear regression with particular virtual examples added has the same solution as a weighted L2 regularization | Derivation of the closed-form solution |
| HW5 | Q6 | Under the second-order Taylor approximation of , find how the L2-regularized solution relates to , , the Hessian, and | The parallel condition and the closed-form solution |
| HW5 | Q10 | Use LIBLINEAR (-s 6) to run L1-regularized logistic regression on the 2-versus-6 subproblem of mnist.scale, choose by , repeat 1126 times, and plot histograms of and of the number of nonzero weights | L1 and sparse solutions |
| HW5 | Q13 (bonus) | The closed-form coordinate descent update for the elastic net | L1 plus L2 |
Q6 can be tried first on this article's three data points: the of linear regression is already a quadratic function, so the Taylor approximation has no error. The Hessian in this example is , with and on the diagonal, and ; substituting into the formula you derive should give .
The data set mnist.scale and the tool LIBLINEAR are both public. Q10 asks you to read the README yourself and work out how LIBLINEAR's parameter C converts to the of the lecture, and that step is itself part of the exercise. With no official solution, you can check yourself this way: when is chosen by , the choice usually lands on one of the smaller values of among the candidates, because the weaker the regularization, the easier it is to get low (this article's table shows the same thing); if your results overwhelmingly choose the largest , check the direction of the conversion first. Q10 deliberately chooses by ; the following Q11 and Q12 switch to a validation set and 3-fold cross validation, and those two questions belong to the next lecture. The guide to the whole assignment is in the Foundations homework guide.
Hands-on. Take whichever linear model you have at hand, sweep the L2 coefficient upward from 0, multiplying by 100 each time, plot the training error and the validation error in the same figure, and see whether the change across the four figures on page 11 of the handout shows up again on your data.
Further reading. Other treatments of the same topic: Stanford CS229 Lecture 6: Bias and Variance, Regularization, and Model Selection and Why Do Ridge, Lasso, and Weight Decay Make Models More Stable?. Techniques comes back to this lecture twice: Techniques Lecture 2: Dual SVM turns the Lagrange multiplier from a given parameter into an unknown to solve for, and Techniques Lecture 5: Kernel Logistic Regression looks at the SVM again from the viewpoint of regularization.
Next lecture. Foundations Lecture 15: Validation answers the question this lecture leaves open: the amount of noise is unknown, so how should be chosen?
Course video sources
Original videos: Regularized Hypothesis Set, Weight Decay Regularization, Regularization and VC Theory, General Regularizers
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 14 handout, 14_handout.pdf: the main source for this article. The derivations in the four sections, the four Fun Time questions, and the figures on pages 2, 9, 11, 12, 19, and 20 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.
- Machine Learning, Fall 2024 course page: the corresponding week, the 14u slides, and the LFD chapter.
- Machine Learning, Fall 2026 course page: the corresponding week and LFD chapter.
- Fall 2024 Homework 4 (hw4_red.pdf): the content of Q9.
- Fall 2024 Homework 5 (hw5.pdf): the content of Q1, Q5, Q6, Q10, and Q13.
- LIBLINEAR and LIBSVM datasets: mnist.scale: the tool and data used in HW5 Q10.
- Learning from Data textbook website: the source of Section 4.2.
- Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques: Course Overview: where this lecture sits in the whole course and the reading routes.
Loading...