🌏 中文版
Video status: Videos included. This article is written from the official MOOC handout 205_handout.pdf and transcripts of the 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/20 to 20/20), and wherever the text says "in the lecture" it is paraphrasing what is said in the video.
This is Techniques Lecture 5 in Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques. The Roadmap on page 1 of the handout divides Techniques into three ways of handling features, and this lecture is still inside the first, Embedding Numerous Features: Kernel Models. The same page summarizes the previous lecture, Techniques Lecture 4: Soft-Margin SVM, this way: allow some margin violations while penalizing them by , which is equivalent to upper-bounding the dual problem's by .
With the previous lecture, the SVM itself is complete. This lecture turns in a different direction: the SVM only answers circle or cross, while Foundations Lecture 10: Logistic Regression answers how probable it is that a point is a circle. Lin opens the lecture by saying that it will look at what methods come out of combining logistic regression with kernels. The four sections do four things in order:
- Rewrite the soft-margin SVM in a form with no constraints and recognize it as L2 regularization.
- Compare the error the SVM uses with the error logistic regression uses, and explain why the two models are close.
- Use that closeness to make the SVM output probabilities (Platt's two-level learning).
- Prove the representer theorem and do logistic regression directly in the kernel's Z space.
The prerequisites are the primal and dual soft-margin SVM problems from the previous lecture, the kernel trick from Techniques Lecture 3: Kernel SVM, logistic regression and gradient descent from Foundations Lecture 10, and L2 regularization from Foundations Lecture 14: Regularization. After reading, you should be able to write the soft-margin SVM in unconstrained form and state how corresponds to , explain why the hinge error and cross-entropy look alike at the two ends, build a probabilistic SVM in three steps, prove the representer theorem yourself, and write down the expression that kernel logistic regression minimizes.
The whole article shares one set of six one-dimensional data points made up for this article (they are not in the handout). Every section computes on them once, and all the numbers were checked in Python. NTU's on-campus course did not schedule this lecture in full in either semester; how it maps is covered in "Exercises and corresponding reading" at the end.
Folding ξ into the objective: the soft-margin SVM is L2 regularization
(In the video, 00:18–03:20 reviews the first four lectures and introduces two software packages, 03:20–07:06 writes as a max, 07:06–10:00 compares it with regularization, 10:00–12:42 places the SVM among regularized models, and Fun Time follows.)
The four problems from the first four lectures
Page 2 of the handout gathers the first four lectures into one table. is the matrix from Techniques Lecture 2, with entries ; from Techniques Lecture 3 on, the inner product is computed with a kernel.
| primal | dual | |
|---|---|---|
| hard-margin | , subject to | , subject to and |
| soft-margin | , subject to and | the same objective, subject to and |
The two dual problems differ only in whether has the upper bound . The bottom of the page says soft-margin preferred in practice, with LIBLINEAR for the linear case and LIBSVM for the non-linear case. In the lecture, Lin adds that few people really use hard-margin in practice; that both open-source packages come from the lab of Professor Chih-Jen Lin at NTU and are used by many people around the world; and that the SVM LIBLINEAR solves differs slightly from the form taught in this course, though it does not perform much differently.
ξ does not have to be a variable
Page 3 goes back to the primal soft-margin problem:
The figure at the upper right of this page draws a fat boundary with one point inside it, labeled violation. The handout says that on any , is exactly that point's margin violation:
In the lecture, Lin goes through two cases. When a point violates the fat boundary, records how far times the score falls short of the 1 we want, which is , a positive number. When a point does not violate, records 0, and in that case is at most 0. Both cases are "the larger of two numbers", so they are written as one max.
The handout does not say why must take this value, so this article fills it in. Fix first and look only at :
- The only part of the objective that involves is . Since , every should be as small as possible.
- Each constraint governs just one : it has to satisfy both and .
- A number that is no smaller than two given numbers can be at best the larger of the two, which is the max above.
So "minimize over together" can be done in two levels: the inner level minimizes over , whose answer we already know, and after substituting it back the outer level has only left, with all the constraints used up. The handout calls the result the unconstrained form of the soft-margin SVM:
In the lecture, Lin explains that is no longer a variable but a result computed from and ; when optimizing, you only move and around and see which pair is best.
Side by side with L2 regularization from Foundations
Next to this expression, page 4 asks familiar? and then sets two expressions side by side:
The right-hand side is the augmented error from Foundations Lecture 14: one term handles the length of , the other handles the error. The left-hand side has exactly the same structure. The handout lists three differences: with shorter , another parameter, and special err.
- A shorter : in the lecture, Lin explains that the SVM separates out and writes it as , so the regularized has one component fewer and is not penalized.
- Another parameter: it uses , not .
- A special error: is the max from a moment ago. The hat marks it as the surrogate error the algorithm uses; the section "How similar the hinge error is to logistic regression's error" looks at it closely.
How do the two parameters convert? The handout gives only the conclusion, in the solution to this section's Fun Time; the conversion itself is an addition in this article. Multiply the whole right-hand expression by the positive number , which does not move the location of the minimum:
Matching it term by term with the left-hand side, corresponds to . The larger is, the smaller is and the weaker the regularization. This also fits how the previous lecture read : a large means caring more about the violations and accepting a narrower boundary (a longer ) in exchange.
Why the earlier lectures didn't solve this form directly
If the SVM is just a regularized model, why not introduce it that way from the start? The lower part of page 4 gives two reasons:
- not QP, no (?) kernel trick: in the lecture, Lin says this new problem looks at first as if it has no constraints, but it is also not "a quadratic objective with linear constraints"; everything has been packed into the expression being minimized. It is not a quadratic program, so the duality and kernels derived earlier for QP are not so easy to apply.
- not differentiable, harder to solve: a function that takes the max of two numbers has points where it cannot be differentiated, and optimizing it directly is not easy.
So, as Lin explains in the lecture, the earlier lectures followed the quadratic programming route and derived everything from hard-margin onward. An addition in this article: the handout puts a question mark in front of kernel trick, and that question mark is not answered until the section "Logistic regression directly in the Z space: the representer theorem", which proves that every L2-regularized linear model can use kernels.
Where the SVM sits among regularized models
The table on page 5 lines up four models:
| model | minimize | constraint |
|---|---|---|
| regularization by constraint | ||
| hard-margin SVM | [and more] | |
| L2 regularization | none | |
| soft-margin SVM | none |
The first two rows are "one thing as the objective, the other as the constraint", and the two swap the roles: the first row looks for the smallest among the of limited length; the hard-margin SVM looks for the shortest among those with . About the and more in brackets, Lin says in the lecture only that it actually adds more conditions; an addition in this article: hard-margin asks not just for separation but for every point to satisfy . The last two rows move the constraint into the objective, giving a sum of two terms. In the fourth row , and multiplying it by gives the total error.
The handout reads three statements off this table:
- large margin ⟺ fewer hyperplanes ⟺ L2 regularization of short . Asking for a fat boundary leaves fewer hyperplanes to choose from, which is the same thing as asking for a short .
- soft margin ⟺ special . Allowing violations and penalizing them amounts to choosing a special error.
- larger or ⟺ smaller ⟺ less regularization. There are two 's here, and the slide tells them apart by color: the in the first row is the upper bound on the length of , and the in the fourth row is the penalty on the violations. In the lecture, Lin says that whichever it is, making it larger corresponds to a smaller .
Why spend a section on this change of view? The handout's answer is that viewing the SVM as a regularized model allows extending and connecting it to other learning models. In the lecture, Lin is more specific: the plan is to extend the SVM to logistic regression and to general regression problems, and seeing these connections clearly first is what shows how the extension should be done.
Numerical example: six points, two values of C
What follows is an example made up for this article, not from the slides. Six one-dimensional points, with no feature transform (), so is a single number:
| 1 | 2 | 3 | 4 | 5 | 6 | |
|---|---|---|---|---|---|---|
The left side is mostly negative examples and the right side mostly positive, but the labels of points 3 and 4 stand on the wrong side, so no threshold separates the data cleanly. The hard-margin SVM has no solution on this data; only soft-margin can be used.
First, see that is computed. Take an arbitrary , so the score is . The six values of are, in order, , so is, in order, . Nothing has to be solved; the formula gives them. With the objective value is .
Then find the optimal solution. This data has a symmetry: replace every point with and the six points map back onto the same data set (for example, becomes ). For any , replacing it with gives the same on the mirrored points, so the two have the same objective value. The objective is convex ( is convex, and each max is the larger of two linear functions, which is also convex), so averaging two equally good solutions cannot make things worse, and the average is . It is therefore enough to consider , that is, classifiers whose boundary is at . Then is, in order, , and the problem is left with one variable (when the four outer points all violate, the six violations sum to more than 6, and the objective value is larger than at , so that case can be ignored):
The two max terms have their kinks at and , so look at three pieces:
| range of | ||
|---|---|---|
- : the slopes of the first two pieces, and , are both negative, and the slope of the third piece is positive, so the lowest point is at the kink , with and .
- : the slope of the first piece, , is negative, and the slope of the second piece, , is positive for , so the lowest point is at the kink , with and .
Both optimal solutions land on a kink where the function cannot be differentiated. The derivative does not exist there, so "set the derivative to 0" does not work, and this is what the handout means by harder to solve. Here is the solution point by point:
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 |
Points 2 and 5 sit exactly on the fat boundary, points 3 and 4 violate, and points 1 and 6 are outside the boundary. Putting the objective values of several together:
| objective value with | objective value with | ||
|---|---|---|---|
| (minimum) | |||
| (minimum) | |||
What this result means. corresponds to ; the solution is and the half-width of the fat boundary is , running from to . corresponds to , ten times as much regularization; the solution becomes , a shorter , with half-width , running from to , and the total violation rises from to . A small is a large : it accepts somewhat more violation to keep short. This article also solved the original problem with and the constraints by numerical optimization (SciPy's SLSQP) and ran a grid search on the unconstrained form over the plane; both gave the solutions above.
Fun Time: what a larger C means
Question (page 6): When viewing soft-margin SVM as regularized model, a larger corresponds to
- a larger , that is, stronger regularization
- a smaller , that is, stronger regularization
- a larger , that is, weaker regularization
- a smaller , that is, weaker regularization
Answer: 4. The handout's solution compares the two formulations on page 4, where corresponds to ; the derivation is the earlier step of multiplying by . and are inversely proportional, so a large means a small ; multiplies , a small penalizes a long lightly, and the regularization is weak. Choices 1 and 3 get the direction between and backwards; choice 2 gets the direction right but calls a small stronger regularization. The example above is an instance: as rises from to , falls from to and lengthens from to .
How similar the hinge error is to logistic regression's error
(In the video, 00:00–03:15 plots the SVM's error, 03:15–06:33 compares it with logistic regression's error, 06:33–08:34 covers the three linear models for classification, 08:34–09:32 raises the question in the opposite direction, and Fun Time follows.)
The error the SVM uses: hinge
The in the unconstrained form depends only on times the score. Page 7 follows the approach of Foundations Lecture 11: Linear Models for Classification: let the linear score be , put on the horizontal axis and the error on the vertical axis, and plot the errors to compare them:
In the figure the 0/1 error is a step: 1 when and 0 when . The SVM's error is two line segments: for it is the line with slope , and for it lies flat at 0. In the lecture, Lin gives two numbers: at the score is still short of 1, so the violation recorded is ; at it is .
The handout says is an upper bound of , and two cases confirm it:
- : , so the hinge is at least 1, while the 0/1 error is 1.
- : the result of the max is never negative, so the hinge is at least 0, while the 0/1 error is 0.
This error is often called the hinge error measure. In the lecture, Lin says it looks much like the thing that joins two door panels. The handout also stresses that it is a convex upper bound. This article adds the reason: and are both linear functions of , and the larger of two linear functions is a convex function. In the lecture, Lin says convexity gives it good properties to use in optimization.
The handout calls an algorithmic error measure, an error the algorithm uses because it is easier to solve. In the lecture, Lin recalls what Foundations did: with an upper bound of the 0/1 error in hand, you can make the upper bound small and so indirectly do well on the 0/1 error. The SVM does the same thing.
Logistic regression's error is another upper bound
Page 8 adds logistic regression's error to the same figure. The cross-entropy error used in Foundations is ; the one used here is the version converted to base 2, which the handout calls scaled cross-entropy:
In the lecture, Lin says only that this is a technical detail and that the change of base needs care. This article fills in the reason: at , , which is smaller than the 0/1 error's 1, so the natural-log version is not an upper bound near there. After dividing by , the value at is exactly 1. To confirm that it is an upper bound:
- : , so .
- : , so the logarithm is positive, greater than 0.
In the figure it is a smooth curve lying above the step.
Behavior at the two ends
Below the figure the handout gives a small table comparing the behavior as goes to either end:
Multiplying the second row by changes the base back to the natural log: . The reason for each of the four cells:
- hinge, : it is 0 once , an exact equality.
- hinge, : the value is . In the lecture, Lin explains that when is very large, that 1 is negligible.
- cross-entropy, : and ; it approaches 0 without ever reaching it.
- cross-entropy, : let , with very large. , and the last term goes to 0, so the whole thing is approximately . In the lecture, Lin puts it as the log and the exponential almost cancelling each other, because that 1 becomes negligible.
At the end where a point is badly wrong, both errors grow linearly with ; at the end where a point is confidently right, both are (almost) 0; the difference is concentrated in the middle. The handout therefore concludes:
In the lecture, Lin splits this statement into two halves: the SVM's objective has the term for the length of , so it resembles L2 regularization; and the error it uses is close to logistic regression's.
Numerical example: three errors side by side
The table below was computed for this article. The last column is the natural-log version, for comparison with the small table above.
| hinge | ||||
|---|---|---|---|---|
In every row the hinge and are no smaller than the 0/1 error. The last column is below 1 at and , so it is not an upper bound, and the change of base exists to fix that. At the last column is , already close to ; at it is , close to 0. The biggest difference between the two errors comes after : the hinge is exactly 0, while cross-entropy keeps a small positive value. In "The price: the β are usually nonzero" this difference turns into the difference of whether a coefficient is 0.
Applied to the six points and the SVM solution (where is ): the 0/1 errors sum to 2 (points 3 and 4 are misclassified), the hinge errors sum to , and the values sum to . Both upper bounds are larger than 2.
Now check "regularized logistic regression ≈ SVM" directly. Replace the hinge in the unconstrained form with , leave everything else alone, and keep at 1:
This problem is differentiable everywhere. Solved numerically (BFGS) for this article, it gives and , with the boundary at . The SVM solution is and , with the boundary also at . The two have the same direction and boundary location, and the size of differs by about 15%. On this example the two models do give very close classifiers, but not the same one.
Three linear models for classification
Page 9 lines up the linear models seen so far that can do binary classification:
| PLA | soft-margin SVM | regularized logistic regression for classification | |
|---|---|---|---|
| approach | minimize specially | minimize regularized by QP | minimize regularized by GD, SGD, and so on |
| pros | efficient if linearly separable | "easy" optimization and theoretical guarantee | "easy" optimization and regularization guard |
| cons | works only if linearly separable, otherwise needing pocket | loose bound of for very negative | loose bound of for very negative |
In the lecture, Lin goes through it column by column. PLA attacks the 0/1 error directly, but that is only manageable when the data is linearly separable. Logistic regression's function is smooth, so optimization is relatively easy, and adding L2 regularization gives some protection on model complexity. The SVM's theoretical guarantee comes from its derivation from the fat boundary. The shared weakness of the last two is that what they optimize is only an upper bound of the 0/1 error. "Loose" can be read off the earlier table: a point with counts as just 1 under the 0/1 error and as 4 under the hinge, so one badly wrong point is penalized heavily.
The bottom of the page has two lines. The first is regularized LogReg ⟹ approximate SVM: solving regularized logistic regression nearly solves the SVM. The second goes the other way, with a question mark after it: SVM ⟹ approximate LogReg (?). In the lecture, Lin says this is where expectations get overturned: what logistic regression originally wants is a probability, not circle or cross. Can what you get from solving an SVM also serve as some measure of the probability that each point is a circle? The section "Making the SVM output probabilities" answers that.
Fun Time: when the upper bound is tight
Question (page 10): We know that is an upper bound of . When is the upper bound tight? That is, when is ?
Answer: 3. The handout's solution says that plotting the figure shows it: the two are equal if and only if , in which case both evaluate to 0; in the lecture, Lin describes that stretch as the two lines lying on top of each other. Checking piece by piece:
- : the 0/1 error is 0 and the hinge is ; they are equal.
- : the 0/1 error is 0 and the hinge is ; they are not equal. Choices 1 and 4 both include this stretch, so they are wrong.
- : the 0/1 error is 1 and the hinge is ; they are not equal. Choices 2 and 4 both include this stretch, so they are wrong.
This article adds one small point: under page 7's definition , when is exactly 0 the 0/1 error is 1 and the hinge is , so apart from the stretch the two are also equal at the isolated point (in the figure on page 7, the hinge's sloped line passes exactly through the corner of the step at , height 1). This does not change the answer to the multiple-choice question: of the four choices, only choice 3 describes a range on which the two are equal everywhere.
Making the SVM output probabilities: run the SVM first, then learn two numbers
(In the video, 00:00–02:30 covers two naive ideas, 02:30–06:15 the two-level learning model, 06:15–08:14 Platt's three steps, 08:14–08:59 explains that this is only an approximate solution, and Fun Time follows.)
Two naive ideas, each missing one side
Soft binary classification wants a probability value between 0 and 1. Page 11 first lists two simple ideas.
Naïve Idea 1. Run SVM and get , apply the logistic function from Foundations Lecture 10 directly, and return
The handout's comment is that this makes direct use of the similarity between the two models and works reasonably well, but has no LogReg flavor. In the lecture, Lin says this approach usually performs decently in practice; its weakness is that almost none of the maximum likelihood that logistic regression was derived from gets used.
Naïve Idea 2. Run SVM, use as the starting point of logistic regression, run logistic regression, and return the logistic regression solution. The handout's comment is that this is not really "easier" than the original logistic regression, and SVM flavor (kernel?) lost. In the lecture, Lin explains that logistic regression is a convex problem and usually has a unique solution, so wherever you start you end up at about the same solution; that is the same as not using the SVM at all and running logistic regression directly, and this approach also has no way to tap the non-linear power of kernel SVM.
The handout's conclusion: want flavors from both sides.
Two-level learning: the SVM sets the direction, logistic regression sets the scale
The model proposed on page 12 is
Inside the parentheses is the score the SVM computes. In the lecture, Lin explains that two more degrees of freedom are given on top of this score: is scaling and is shifting.
- SVM flavor: the direction of the hyperplane is fixed by , so the kernel applies as before. In the lecture, Lin explains it geometrically: the SVM finds the normal vector of the separating line, and the normal vector does not move. Duality, kernels, and the rest of the SVM's tools can all be used, because the first step is the SVM exactly as it was.
- LogReg flavor: fine-tune with and so that the result matches maximum likelihood.
The handout attaches two expectations: often if is reasonably good, and often if is reasonably good. In the lecture, Lin explains that below 0 would mean the direction is reversed, which would mean the SVM had been doing nonsense from the start; and will be very close to 0 but not necessarily exactly 0, because there is a degree of freedom to adjust.
How are and learned? Apply the cross-entropy error from Foundations Lecture 10, with and already fixed numbers:
Under the score the handout writes . In the lecture, Lin steps back to a higher view: this score can be treated as a special transform that the SVM hands you, turning a multi-dimensional into a single number. The second stage only solves a logistic regression with one-dimensional data and two variables. The handout calls the whole thing two-level learning: LogReg on SVM-transformed data.
Platt's probabilistic SVM
Page 13 writes it as three steps under the heading Platt's Model of Probabilistic SVM for Soft Binary Classification. In the lecture, Lin says the method was proposed by a person named John Platt, so it is generally called Platt's model, and it is very widely used in the SVM field.
- Run SVM on to get or the equivalent , and transform every point to .
- Run logistic regression on to get .
- Return .
The handout adds a line of gray text to each of the first two steps: the actual model performs step 1 in a more complicated manner; the actual model adds some special regularization in step 2. In the lecture, Lin does not go into the details, saying only that a little regularization is added to make the problem less prone to overfitting, and mentioning that packages such as LIBSVM include this method.
This page has two more key points:
- The probabilistic SVM's boundary is not necessarily the same as the original SVM's, because of . happens where , that is, where the score equals ; the SVM's boundary is where the score equals 0. When the two come apart. In the lecture, Lin says that after the shift it is not necessarily the same as the SVM, but it may match what maximum likelihood asks for better.
- How to solve step 2: GD, SGD, or better, because there are only two variables. In the lecture, Lin says even simpler methods can be used.
The bottom of the page states where this section stands and the question to answer next: kernel SVM ⟹ approx. LogReg in -space; exact LogReg in -space? In the lecture, Lin is clear about it: doing this does not really solve logistic regression in the Z space. It only finds a fairly good solution by relying on the SVM plus the fine-tuning of and , and that is not the best logistic regression solution in the Z space.
Numerical example: fitting A and B to the SVM scores of the six points
What follows is an example made up for this article. It reuses the earlier SVM solution, and .
Step one: transform. ; the six values are , and the labels are still .
Step two: logistic regression with two variables. The quantity to minimize is . Differentiating with respect to gives , and the chain rule then gives:
This is the same expression as the gradient in Foundations Lecture 10, only with the "features" replaced by . Start gradient descent from the position of Naïve Idea 1, . In the first step the six values of are and the corresponding are , so
and the six terms in cancel in pairs (points 1 and 6 have the same and opposite signs of , and so do the other two pairs), giving 0. With learning rate 1, moves from to and stays at 0. After 116 such steps in total, both partial derivatives are below in absolute value, and the descent stops at
is exactly 0 because this data set is symmetric; in general it will not come out so neatly. and agree with what the handout expects.
Step three: output probabilities.
| SVM score | Naïve Idea 1: | probabilistic SVM: | ||
|---|---|---|---|---|
What this result means. The two approaches give the same ordering and the same boundary; they differ in scale. For the leftmost point, Naïve Idea 1 only dares to say "the probability of being positive is 0.159", while the probabilistic SVM says 0.046. The average cross-entropy error drops from () to (), and the latter matches maximum likelihood better. This article's reading: the scale of the SVM score is set by "points on the fat boundary score exactly ±1", a scale that has nothing to do with probability, so is needed to rescale it.
The data in this example is one-dimensional, so already covers every linear function of , and the second stage is in fact the same as running unregularized logistic regression directly on . When the data is multi-dimensional, the direction of stays fixed and only two numbers can be adjusted; that is when two-level learning and full logistic regression differ.
A case where is not 0. Add a seventh point . Its , so its hinge error is 0. The new objective equals the old one plus this point's hinge; it is nowhere smaller than the old one, and at the old optimal solution the two are equal, so the SVM solution does not change at all and the boundary stays at . The logistic regression step does change: solving again on seven points gives and . The position of probability moves to the score , which in terms of is , slightly off the SVM boundary . is very close to 0 but not 0, which is what the handout means when it says the two boundaries are not necessarily the same. It also shows the difference between the two errors: a point outside the boundary has no effect at all on the hinge, and still a small effect on cross-entropy.
Fun Time: plugging in the kernel score
Question (page 14): Recall that the score for the kernel SVM. When coupling the kernel SVM with to form a probabilistic SVM, which of the following is the resulting ?
Answer: 4. The handout says only to plug the kernel formula of the score into . Substituting and multiplying through:
multiplies the whole score, including ; is added on the outside. Choice 3 forgets to multiply by and has no . Choice 2 swaps the roles of and . Choice 1 makes both mistakes. This question also shows that prediction does not need itself: it needs only the support vectors' , the kernel, and the three numbers , , and .
Logistic regression directly in the Z space: the representer theorem
(In the video, 00:00–03:05 finds the key behind the kernel trick, 03:05–08:23 covers the representer theorem and its proof, 08:23–10:57 derives kernel logistic regression, 10:57–13:49 gives another view, 13:49–14:27 discusses the coefficients not being sparse, and Fun Time and the summary follow.)
What the kernel trick relies on
The probabilistic SVM is only an approximation. In the lecture, Lin picks up the question left at the end of the probabilistic SVM: the goal now is to really do logistic regression in the Z space, not an approximate solution. The trouble is that the SVM's kernel came from the dual of a QP, while logistic regression's expression has a log and an exponential in it and is not a quadratic program at all, so that road is closed.
So we have to go back and ask why the kernel trick works. Lin's analysis in the lecture: the kernel trick replaces the inner product in the Z space with a function that is easy to compute in the X space; inner products are computed during training, and prediction also needs the inner product of and . Only if can be written as a linear combination of the already seen can the inner product at prediction time be replaced by a kernel. Page 15 writes this as one line:
The handout then lists three examples already seen, in all of which is written as :
| model | where comes from |
|---|---|
| SVM | the dual solutions |
| PLA | the number of times example was used for a mistake correction |
| logistic regression by SGD | the total SGD moves accumulated on example |
The third can be verified directly (the verification below is an addition in this article). SGD for logistic regression picks one example at a time, and the update is . Starting from , every step adds some positive number times , so no matter how many steps are taken, is a linear combination of the , and the coefficient of example is the sum of that over the times it was picked. Techniques Lecture 2: Dual SVM already called this phenomenon being represented by data.
All three examples hold, but each for its own reason, and the last two are about the an algorithm happens to produce. The handout asks the more general question: when can the optimal always be represented by the ?
The representer theorem and its proof
The claim on page 16: for any L2-regularized linear model
the optimal solution satisfies . What "linear model" means here, Lin says in the lecture, is that the error is computed only through the score ; err can be whatever function you like. In the lecture, Lin says the result is all-encompassing: the ridge regression and the L2-regularized logistic regression covered in Foundations are both inside it.
The proof is by contradiction. The handout has only four lines, and every step is filled in below.
Step one: split the optimal solution into two parts. Let , where is some linear combination of , and is perpendicular to every . This is the decomposition from linear algebra that projects a vector onto a subspace, and every vector can be split this way. In the lecture, Lin likens to a remainder: what is left after removing the part the can span. What we want to prove is .
Step two: suppose and compare with .
On the error term the two are the same. For every ,
is perpendicular to every , so the inner product is 0. The scores are the same, so is the same, and so is the sum of the terms.
On the regularization term, is smaller:
The cross term is 0, because is a linear combination of the and is perpendicular to every . is the squared length of , which is strictly greater than 0 when .
Step three: contradiction. has the same error term as and a strictly smaller regularization term, so its whole objective value is lower than that of . But is the optimal solution. On the slide is black and is red, and in the lecture Lin says the red one beats the black one, like someone scoring higher than the top-ranked student when there is no rank 0. So the assumption fails, , and is a linear combination of the .
In the lecture, Lin says this proof goes around in circles a little and that the conclusion is what matters. The handout writes the conclusion at the bottom of the page in these words, any L2-regularized linear model can be kernelized!
This article adds three points, all read off the proof:
- The proof needs . With the regularization term is gone, and the argument above only shows that is as good as , which yields no contradiction.
- The proof uses only two things: the error looks only at , and the regularization term is . The second is used in "the squared length splits into the sum of the squares of two perpendicular components", a property only L2 has.
- The score on this page of the handout has no . If a separate, unregularized is added, the score is , replacing with still leaves the score unchanged, and the same proof goes through.
A small example (made up for this article). The Z space is two-dimensional, with only two examples and , which span only the direction . Take and split it into and . Scores: and ; and , exactly the same, so whichever err is used, the two have the same error. Squared lengths: and , and the missing 2 is exactly . cannot be the optimal solution, because is always better.
Applying it to logistic regression: replacing w with β
Page 17 applies the theorem to L2-regularized logistic regression:
The optimal solution must be , so the handout says that without loss of generality we can solve for the optimal instead. In the lecture, Lin explains that since the solution must have this form, there is no need to find that long ; concentrate on finding the coefficients of the linear combination. The substitution happens in two places (the inner sum uses to keep it apart from the outer ):
Replacing the inner product with the kernel in both places gives kernel logistic regression (KLR):
The variables are the coefficients . In the lecture, Lin stresses that this number equals the amount of data and no longer has anything to do with the dimension of the Z space. How is it solved? The handout writes GD/SGD/... for unconstrained optimization: it has no constraints at all, so the methods learned in Foundations all work. In the lecture, Lin contrasts two ways of obtaining coefficients: the SVM's is solved through a special dual problem, while KLR's is optimized directly after the substitution. Prediction uses the line from page 15:
This article fills in the gradient that gradient descent needs. Write the kernel matrix as (, symmetric), so the score of point is . The partial derivative with respect to :
The first term comes from the derivative of the quadratic form ; the second is the same derivative as in "Numerical example: fitting A and B to the SVM scores of the six points", multiplied by one more factor .
Another view: a linear model of β
Page 18 reads the same expression from another angle. Lin's lead-in in the lecture: suppose nobody had told you about the long detour through the Z space and you just looked at this expression. What would you see?
- is the inner product between and a vector, namely . In other words, the kernel is doing a transform: it replaces with its similarities to each of the training points (in the lecture, Lin reminds us that a kernel is a kind of similarity). plays the role of the weights in this -dimensional space.
- is a special regularizer. In the lecture, Lin says the regularizer we are used to is the inner product of with itself, and now there is an extra in the middle.
So KLR can be read in two ways, which the handout puts side by side:
| a linear model of | transform | regularizer | |
|---|---|---|---|
| reading 1 | the kernel itself as the transform | kernel regularizer | |
| reading 2 | the embedded-in-kernel transform | L2 regularizer |
The handout adds the line similar for SVM. In the lecture, Lin takes the SVM with a Gaussian kernel as the example: its result is a linear combination of a bunch of Gaussians, which can be seen as a linear model on those Gaussian transforms, or as a linear model in an infinite-dimensional Z space.
The price: the β are usually nonzero
The page ends with a warning box: unlike coefficients in SVM, coefficients in KLR often non-zero! In the lecture, Lin explains that for the SVM, the of the points outside the fat boundary are all 0 and only the support vectors are nonzero, while most of the that KLR produces are nonzero. On whether the solution has many zeros (sparsity), the two are very different. In the summary Lin calls it a price: with many nonzero , more has to be paid in computation. This article adds where that price lands: predicting a new point requires one kernel evaluation for every training point with .
The handout does not say why, so this article offers an explanation using the gradient above. The gradient is 0 at the optimal solution. When is invertible (for example, a Gaussian kernel on pairwise distinct data points), a zero gradient forces every term in the parentheses to be 0:
The value of is always between 0 and 1 and is never exactly 0, so every is nonzero. For a point with a very large (a point classified very correctly), is very small and is close to 0 but not 0. This is exactly the difference seen in the table of "Numerical example: three errors side by side": cross-entropy is still positive and still has a slope after , so every point keeps contributing; the hinge is flat after , those points have no effect on the solution, and their is 0.
Numerical example: kernel logistic regression on six points
What follows is an example made up for this article. The same six points, with the Gaussian kernel from Techniques Lecture 3 and : . , corresponding to the earlier .
The kernel matrix. Points at distance 1 give , at distance 2 give , at distance 3 give , and anything farther rounds to 0:
Solving for . Start from and run gradient descent with the gradient above (solving once more with BFGS gives the same result):
| score | |||||
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 |
Checking one of the scores: . Checking as well: with the factor is 1, , and ; both match.
What this result means.
- None of the six is 0; even points 1 and 6, farthest from the boundary, have . For the linear SVM with the same , the dual solution is : points 3 and 4, which violate the boundary, hit the upper bound ; points 2 and 5, on the boundary, are between 0 and ; points 1 and 6, outside the boundary, are 0. (Check: and .)
- These two sets of coefficients use different kernels, so the comparison is not a fair one. For a fair one, go back to the linear regularized logistic regression with in "Numerical example: three errors side by side" (, ). Its zero gradient gives , and the six coefficients are . Same data, same linear model, same : the SVM's coefficients include two zeros, and logistic regression's six are all nonzero.
- It also has to be said plainly that the SVM's sparsity is not guaranteed. Solving the SVM dual on these six points with the same Gaussian kernel and , this article gets : all six points are support vectors. With so little data and so narrow a kernel, no point falls outside the fat boundary. The difference is that the SVM's can be 0, and whenever a point falls outside the fat boundary its is 0; KLR's , by the formula above, is never 0.
- The Gaussian kernel gives the model flexibility: the signs of all six scores agree with the labels, so points 3 and 4 are classified correctly too, which a one-dimensional linear model cannot do. The probabilities all stay near because the regularization at is strong. Lowering to (corresponding to ) turns into and the six probabilities into . A small means weak regularization, larger coefficients, and a model more confident about the training data, consistent with the conclusion of the section "Folding ξ into the objective".
- Predicting a new point uses all six training points. Take : its kernel values with the six points are , the score is the inner product of this vector with , about , and . This six-dimensional vector is the transformed data described in "Another view".
Fun Time: the dimension of the space for the linear model of β
Question (page 19): When viewing KLR as linear model of (with the kernel as the transform, together with the kernel regularizer), what is the dimension of the Z space that the linear model operates on?
- , the dimension of the original X space
- , the number of training examples
- , the dimension of some feature transform that is embedded within the kernel
- , the regularization parameter
Answer: 2. The handout's solution: for any , the transformed data is , which is -dimensional. In the lecture, Lin restates the question one more way: how many parameters does this linear model have? The answer is the same, the coefficients . In the six-point example every is turned into a six-dimensional vector, and is six-dimensional too.
Choice 1 is the dimension before the transform (1 in the example). Choice 3 is the dimension of reading 2: when KLR is viewed as a linear model of , lives in a -dimensional space, and for the Gaussian kernel is infinite. The question asks about reading 1. Choice 4 is the value of a parameter, not a dimension.
The Summary on page 20 reduces each of the four sections to one line: the soft-margin SVM is L2-regularization with hinge error measure; it approximates L2-regularized logistic regression; for soft binary classification, the common approach is two-level learning; kernel logistic regression is the representer theorem applied to L2-regularized logistic regression. The preview of the next lecture is kernel models for regression.
Self-check
1. Using the same six points, take . Compute the six and the objective value of the unconstrained form with . Is it better or worse than ?
Answer: the scores are, in order, ; is ; and is , which sums to . The objective value is , worse than the optimal solution's . Note that points 4 and 5 are classified correctly () and their is still positive: the hinge penalizes "not exceeding 1", not just "misclassified".
2. An L2-regularized model uses . What is when it is written the SVM way? To make shorter, should be raised or lowered?
Answer: . A shorter means stronger regularization, so should be raised and lowered.
3. On what range of is , without the change of base, smaller than the 0/1 error? What does this show?
Answer: for the 0/1 error is 0, and nothing is smaller than that. For the 0/1 error is 1, and is equivalent to , that is, . So on the stretch it is smaller than the 0/1 error and is not an upper bound. After dividing by to change to base 2, the value at goes from to 1, and only then does the whole curve lie above the 0/1 error. Criterion: you should be able to point out that the problem is near and work out that .
4. A probabilistic SVM has learned and , and the SVM underneath is the one from the six-point example, and . At which does it put the probability at exactly ? What is ?
Answer: gives the score ; gives , which differs from the SVM boundary , and that is the effect of . The score at is 1, so .
5. The Z space is two-dimensional, with and . Someone claims that the optimal solution of some L2-regularized linear model () is . Use the proof of the representer theorem to show that this is impossible, and find a better .
Answer: the two span only the direction . Project onto it: and , whose inner product with is . has the same scores as (5 on for both, 10 on for both), so the error is the same; and , so the regularization term is smaller. Hence is better than , and cannot be the optimal solution. Extension: the in is not unique ( and both work), because the two are linearly dependent; the theorem guarantees that a exists, not that it is unique.
Exercises and corresponding reading
Corresponding weeks in the two semesters. NTU's on-campus course did not schedule this lecture in full, so this article can only follow the MOOC handout and videos. The Fall 2024 course page taught 205u_handout.pdf in W11 (11/11) under the changed title SVM for Soft Binary Classification; its Summary lists only the first three sections of this lecture, without the Kernel Logistic Regression section, and the same week goes straight on to blending and bagging. The Fall 2026 course page finishes kernels and soft-margin SVM in W10 and moves directly into blending, bagging, and AdaBoost in W11 (11/18), without scheduling this lecture. These are the results of a check on 2026-09-30. If you only want to keep pace with the NTU classroom, the first three sections are what matter; if you want the full picture of kernel models, the representer theorem section is the foundation for the next lecture.
Homework. This lecture has no public homework of its own. Q3 of Fall 2024 HW6 (released 2024-11-18, due 12-02) touches a related topic; it is an auto-graded multiple-choice problem with no official solution. It changes the soft-margin SVM's violation penalty from to (squared hinge), gives the dual problem, and asks how to compute the optimal once has been solved. The problem practices the dual derivation of the previous lecture and also this lecture's view that "ξ does not have to be a variable": is the error, and changing how it is penalized is changing the error function. A suggestion: derive the dual from the Lagrange function yourself first and confirm it has the form the problem gives, then answer the question about ; you can solve the primal and the dual separately with a small data set and a general-purpose QP package to verify your formula. The guide to the whole assignment is in Techniques Homework and Final Project.
Hands-on. Type in this article's six points yourself: use a grid search to find the minimum of the unconstrained form and confirm the solutions for and ; then write a two-variable gradient descent starting from and confirm that it stops at . Both parts need only plain Python.
Further reading.
- Next to 205u, the Fall 2024 course page lists the further reading A Note on Platt's Probabilistic Outputs for Support Vector Machines (Lin, Weng, Lin), which discusses exactly the "actual model" mentioned in the handout's two lines of gray text. This article did not read that paper page by page and does not cite its contents.
- Chapter 5 of the CS229 main notes derives kernel methods in a different way and can be compared with this lecture's representer theorem.
- Caltech Learning from Data is the English-language course for the same textbook.
Next lecture. Techniques Lecture 6: Support Vector Regression applies the representer theorem to regression, first obtaining kernel ridge regression, which has an analytic solution, and then dealing with the problem this lecture leaves behind: how to make the coefficients sparse the way the SVM's are.
Course video sources
Original videos: Soft-Margin SVM as Regularized Model, SVM versus Logistic Regression, SVM for Soft Binary Classification, Kernel Logistic Regression
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. The first and third videos carry shortened titles on YouTube (Soft-Margin SVM as Regularized, SVM for Soft Binary); the section names in the handout are the full ones.
Update Log
- 2026-10-10: Marked the video status and checked the recording sources and how they were obtained.
- 2026-10-10: Rechecked the video status. The embedded videos match the lecture in the official playlist.
- 2026-10-13: This article was originally combined with Techniques Lecture 6. It was changed to one article per lecture, now covers only Techniques Lecture 5, and was rewritten from the handout and the video transcripts.
References
- Techniques Lecture 5 handout 205_handout.pdf: the main basis of this article; the derivations, tables, and four Fun Time questions of the four sections all come from this handout.
- Machine Learning Techniques YouTube playlist: the IDs and titles of the four videos; what this article 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.
- Foundations Lecture 14 handout 14_handout.pdf: the augmented error of L2 regularization, which "Side by side with L2 regularization from Foundations" compares with the unconstrained form.
- Machine Learning, Fall 2024 course page: the W11 schedule and the further-reading list.
- Fall 2024's 205u_handout.pdf: the title and Summary of the on-campus version, used to show that it covers only the first three sections.
- Machine Learning, Fall 2026 course page: confirms that this lecture is not scheduled in the course.
- Fall 2024 Homework 6 (hw6_red.pdf): the content of Q3.
- Lin, Weng, Lin: A Note on Platt's Probabilistic Outputs for Support Vector Machines: further reading listed on the Fall 2024 course page; this article only points out that it exists.
- LIBSVM: the non-linear SVM software named on page 2 of the handout.
- LIBLINEAR: the linear SVM software named on page 2 of the handout.
- CS229 main notes main_notes.pdf: further reading, the kernel methods of Chapter 5.
- Caltech Learning from Data: further reading.
- Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques: Course Overview: where this lecture sits in the whole course and the reading routes.