🌏 中文版
Video status: Videos included. This article is written from the official MOOC handout 206_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/23 to 23/23), and wherever the text says "in the lecture" it is paraphrasing what is said in the video.
This is Techniques Lecture 6 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 is the last lecture of the first, Embedding Numerous Features: Kernel Models. The same page summarizes the previous lecture, Techniques Lecture 5: Kernel Logistic Regression, this way: two-level learning for SVM-like sparse model for soft classification, or using representer theorem with regularized logistic error for dense model. This lecture carries the same tools over to regression: when the output is a real number, how do you use a kernel, and how do you keep the coefficients sparse.
There are four prerequisites: the analytic solution from Foundations Lecture 9: Linear Regression, ridge regression from Foundations Lecture 14: Regularization, the dual derivation from Techniques Lecture 4: Soft-Margin SVM, and the representer theorem from the previous lecture. After reading, you should be able to derive the analytic solution of kernel ridge regression on your own, go from the tube error all the way to the SVR dual, use complementary slackness to explain which points have a coefficient of 0, and compute both models' coefficients by hand for three data points to compare them.
Here is the route of the whole lecture first:
- Kernel ridge regression: substitute into ridge regression and solve for .
- Spot the problem: is dense, so prediction needs every training point.
- Change the error: replace the squared error with the tube error.
- SVR primal: rewrite it as a QP the way soft-margin SVM was written.
- SVR dual: get rid of the feature dimension, and get sparsity from complementary slackness.
- Summary: lay out the linear and kernel models from Foundations and the first six Techniques lectures on one map.
Putting a kernel on ridge regression: is the analytic solution still there
(Video 00:19–01:58 reviews the previous lecture and the representer theorem, 01:58–08:49 rewrites the problem in terms of , 08:49–14:36 solves it, 14:36–16:49 compares linear with kernel, and Fun Time follows.)
Starting from the representer theorem
Page 2 of the handout first recalls the previous lecture's conclusion. For any L2-regularized linear model
the optimal solution can be written as , so every such model can be kernelized. The previous lecture set err to the cross-entropy of logistic regression. This lecture sets it to the squared error of regression, , which is the ridge regression taught in Foundations.
Ridge regression had an analytic solution in Foundations; in the lecture, Lin describes it as a solution that reaches the answer in a single step. The question at the bottom of this page of the handout is: analytic solution for kernel ridge regression?
Replacing w with β
Page 3 simply substitutes. Since the optimal must be a linear combination of the , the handout says that without loss of generality we can solve for the optimal instead. Substitute term by term:
The regularization term. Each of the two brings its own sum. In the lecture, Lin points out that the first sum comes from the in front and the second from the behind:
The last step is the kernel trick: becomes , and never has to be computed.
The score inside the error term. The prediction for the -th data point is
Together they give the formula on the handout:
The handout annotates each of the two terms: the first is regularization of on -based regularizer, and the second is linear regression of on -based features. The lecture's explanation is the same one given for kernel logistic regression in the previous lecture: this problem can also be seen as a linear model in , where the data are first transformed by the kernel (the new features of the -th data point are its kernel values with every training point), and the regularization term is a special version that depends on .
Writing it with matrices
A double sum is awkward to differentiate, so the handout switches to matrices. Let be the kernel matrix whose entry is .
- The double sum is . The lecture's example: take a from the front and a from the back, and the coefficient multiplying them is row 3, column 5 of .
- is the -th component of the vector , so the sum of squares is . In the lecture, Lin notes that this is the same move as in Foundations' derivation of linear regression, where a sum of squares was written as the squared length of a vector.
Expand the squared length:
The cross term can be written as or as . They are the same number, and in the lecture Lin says it makes no difference which order you write it in. The whole objective is
The handout names this model kernel ridge regression: use representer theorem for kernel trick on ridge regression.
Solving for β
is quadratic in and has no constraints, so the approach is to find where the gradient is 0 (page 4). Differentiate the three terms separately:
- The gradient of is . The lecture uses a single-variable analogy: the derivative of with respect to is , with playing the role of and the role of . An addition in this article: this rule needs the matrix in the middle to be symmetric, and is, because .
- is also quadratic, the in the middle is symmetric as well, and the gradient is .
- is linear, and its gradient is the coefficient . The constant term has gradient 0.
Together:
The first term was originally , and the handout writes it as . In the lecture, Lin explains that two things were quietly slipped in: is symmetric, so adding a transpose changes nothing; and inserting an identity matrix changes nothing either. The purpose is to make all three terms start with so that it can be factored out.
One way to make the gradient is to make the vector inside the parentheses :
The handout says two things about this solution.
The inverse always exists. It does whenever , because is positive semi-definite, which is Mercer's condition from Techniques Lecture 3: Kernel SVM. The lecture puts it this way: a valid kernel gives a positive semi-definite , and adding a nonzero on the diagonal makes it invertible for sure. This article fills in the step in between: for any nonzero vector ,
so cannot be , and the matrix is invertible.
The cost is . The matrix to invert is , and it is dense. The lecture gives the same reason as for in the dual SVM lecture: most kernel values are not 0, unless two vectors happen to be orthogonal.
Two additions in this article. First, why the point where the gradient is 0 is a minimum: and are both upward-opening quadratic functions, their sum is still convex, and a point with zero gradient is the global minimum. Second, the handout's wording is one analytic solution. When is not invertible, other also make the gradient 0: add to the solution any that satisfies . But , so all these correspond to exactly the same , and whichever one you pick gives the same model.
The handout's conclusion on this page: can now do non-linear regression 'easily'. In the lecture, Lin adds that non-linear regression used to mean a feature transform followed by linear regression; now there is a second route, solving the regression problem hidden in the space directly through the kernel.
Numerical example: a quadratic kernel on three points
What follows is an example made up for this article, not from the slides. Three one-dimensional data points:
| 1 | ||
| 2 | ||
| 3 |
The kernel is the second-order polynomial from Techniques Lecture 3, , with .
Step 1: compute . For example , , and :
Step 2: solve . The three equations are , , and . Subtracting the third from the first gives ; substituting into the second gives ; substituting back into the first gives :
Step 3: write out . Use the conclusion of this section's Fun Time, :
What this result means. The three points actually lie on , yet what is learned is , which predicts , , at the three training points. The gap comes from regularization: is heavy for three data points and flattens the curve. Also, none of the three is 0.
Checking against ridge regression in the space. The transform that goes with this kernel is , because . Work back through :
, which agrees with the result above. Using the linear ridge regression formula directly in the space also gives . The two routes solve the same problem and differ only in whether the matrix to invert is or . This article ran the computation once with Python's fractions and once with numpy, and the results match.
The trade-off between linear and kernel
Page 5 puts the two kinds of ridge regression side by side, each with a figure above it: on the same data, linear ridge regression on the left draws a straight line and kernel ridge regression on the right draws a curved one, and the vertical red segments from the data points to the line are the errors.
| linear ridge regression | kernel ridge regression | |
|---|---|---|
| Solution | ||
| Flexibility | more restricted | more flexible with |
| Training | ||
| Prediction | ||
| The handout's comment | efficient when | hard for big data |
In the linear column, is the time to compute and is the time to invert a matrix. The lecture's explanation: the linear has length , so prediction takes time ; with a kernel, both training and prediction are tied to the data size , which makes the method a poor fit once the data get large. The lecture also connects back to something discussed in the earlier SVM lectures: besides efficiency, linear models have the advantage that model complexity is easier to control, and you switch to a kernel only when the problem is more complicated and you can afford the computation. The handout sums the page up in one line: linear versus kernel: trade-off between efficiency and flexibility.
Fun Time: g after solving for β
Question (page 6): After getting the optimal from kernel ridge regression based on some kernel function , what is the resulting ?
Answer: 1. The handout's solution joins two equations: the representer theorem gives , and the regression output is , so
Why the other choices are wrong is this article's explanation. Choice 2 has an extra , which is the SVM form ; here the coefficient of the linear combination is itself, and the information in was already used up when solving . Choices 3 and 4 add . only determines what is during training and does not appear in the prediction formula; the model in this section has no separate constant term either. The numerical example above was computed with choice 1, and it matched the result in the space.
A dense β is a problem: switching to the tube error and writing the SVR primal
(Video 00:00–03:33 covers LSSVM and the dense , 03:33–07:35 the tube error, 07:35–09:25 the comparison with the squared error, 09:25–12:14 the rewrite that mimics SVM, 12:14–16:17 the introduction of violations, 16:17–18:04 the parameters and the size of the QP, and Fun Time follows.)
LSSVM: similar boundary, many more support vectors
Foundations showed that linear regression can be used for classification. So can kernel ridge regression, and that use has a name: least-squares SVM (LSSVM). In the lecture, Lin explains that the words least-squares stress that it uses the squared error of regression.
Page 7 of the handout shows two figures on the same binary classification data, with soft-margin Gaussian SVM on the left and Gaussian LSSVM on the right, and the support vectors marked with boxes. The classification boundaries in the two figures are about the same. The difference is in the boxes: on the left only some of the points have one, and on the right almost every point does.
The reason lies in how is computed. In the lecture, Lin points out that comes out of a matrix inversion, and nothing in that makes some of its components come out exactly 0, so every data point is a support vector. The three-point example above is the same: none of the three is 0.
Many support vectors cost you at prediction time. In , every nonzero needs one kernel evaluation. The handout writes slower prediction, dense (BIG ), and in the lecture Lin calls such a bloated. The handout then sorts models into two groups:
- Dense : LSSVM, kernel logistic regression.
- Sparse : the standard SVM, where most are 0, a property given by the KKT conditions.
That fixes the goal of this section: do regression, but get a as sparse as the standard SVM's.
The tube error: a small miss is not an error
Page 8 of the handout changes the error function and calls the result tube regression. The figure draws a blue band (the tube) above and below the regression line:
- A data point inside the tube: no error.
- A data point outside the tube: the error is its distance to the edge of the tube.
In the lecture, Lin calls the tube a neutral zone: when the prediction is only slightly off the target, it counts as no error and costs nothing; only what goes beyond the neutral zone is charged, and only for the part that goes beyond. As a formula, with the predicted score and the target:
- When , the second argument is at most 0 and the max is 0.
- When , the second argument is positive and the error is .
This error is usually called the -insensitive error, with . The handout calls the vertical tube width; the lecture is more precise: is the distance tolerated above the line and also below it, so the whole neutral zone is high.
The lecture also says why this form was chosen: the hinge error of soft-margin SVM has a max with 0 in it too, so the errors look alike, the rest of the derivation can follow the SVM one, and that is what gives a chance of getting an SVM-style sparse solution.
Tube error versus squared error
The top of page 9 puts the figures for the two kinds of regression side by side: the left one has the blue tube and counts only the length of red line beyond the tube; the right one is the squared error, with no tube, and counts the square of the whole red length. In the lecture, Lin says the squared error is a bit like the case of a very, very narrow tube, except that the red length is then squared. The bottom of the page plots both errors against in one figure: the squared error is a parabola, while the tube error is flat near and a straight line of fixed slope on each side. The handout's conclusion is that the two are about the same when is small, and that the tube error is less affected by outliers. The lecture's explanation uses the word noise: far from the target the squared error grows quickly, and the model will change the whole line to accommodate a few far-off points; the tube error grows gently, so the problem is milder.
The table below was computed for this article, with , to show what each error is as the gap grows:
| tube error | squared error | |
|---|---|---|
When the gap goes from 3 to 10, the tube error grows by 7 and the squared error by 91. A single far-off data point weighs much more under the squared error.
Mimicking SVM: rewriting regularized tube regression
Page 10 first writes down L2-regularized tube regression:
and then compares it with the standard SVM:
| regularized tube regression | standard SVM | |
|---|---|---|
| Form | tube violation | margin violation |
| How to solve | unconstrained, but max not differentiable | not differentiable either, but QP |
| How to kernelize | representer theorem works, but no obvious sparsity | through the dual; KKT conditions bring sparsity |
The two "but"s on the left are the reasons not to solve it directly. The handout decides to mimic the standard SVM derivation. In the lecture, Lin says a few small things were done to make it look as much like SVM as possible: the parameter changes from to the customary in SVM; a goes in front of ; and the constant term is pulled out of and written as . The result is
An addition in this article on how the two parameters relate: multiply the whole objective of the previous formula by (a positive number, so the location of the minimum does not change) and you get , so corresponds to . The larger is, the smaller is and the weaker the regularization, which is the same conclusion the previous lecture reached when looking at soft-margin SVM.
From max and absolute value to linear constraints
Page 11 turns it into a QP in two steps.
Step 1: introduce the way SVM does. Soft-margin SVM uses a variable to record how much each data point violates, and the same is done here:
In the lecture, Lin explains that we want the gap between the score and to stay within , and whatever goes beyond is charged as . This article writes out why the two forms are equivalent: with fixed, the constraints require and also ; the objective wants as small as possible, so the optimal is exactly the larger of these two lower bounds, which is .
Step 2: take the absolute value apart. This is not a QP yet, because the absolute value in the constraint is not a linear operation. The absolute value stands for two cases: is above the score, or is below the score. The handout splits the one into two, with recording the violation on the upper side (upper tube violation) and the violation on the lower side (lower tube violation):
The right-hand inequality handles the upper side: when is above the score by more than , has to make up the excess. The left-hand inequality handles the lower side. In the lecture, Lin walks through it on the figure: for a data point above the line, the length of red line beyond the blue tube is ; for one below, the length beyond the tube is . Add up the lengths of all the red lines, add the regularization term, and that is what gets minimized.
This is what the handout calls the standard Support Vector Regression (SVR) primal: minimize regularizer plus the upper tube violations and the lower violations. The objective is now quadratic in plus linear in , and every constraint is linear in , so it is a QP.
An addition in this article: the two violations of one data point are never both positive. needs to be above the score by more than , and needs to be below the score by more than , and the two cannot happen together. So at the optimum equals the original single , and splitting it did not change the problem.
Two parameters and the size of the QP
Page 12 sums up this QP:
- Parameter : the trade-off of regularization and tube violation. The lecture compares it with SVM: SVM's sets whether you care more about making fewer mistakes or about a fatter margin; here it is whether you care more about smaller violations or about stronger regularization.
- Parameter : the vertical tube width, that is, how tolerant to be. The handout makes a point of noting one more parameter to choose. In the lecture, Lin says this is where SVR differs noticeably from SVM: no matter what, SVR has one more parameter to pick than SVM.
- Size: the variables are one , the components of , and two sets of with each, for in total. The constraints are for the upper and lower sides of the tube plus for , for in total.
shows up in the variable count again. As in the SVM lectures, the next step is to move to the dual and use the kernel trick to remove .
Fun Time: computing the two violations
Question (page 13): Consider solving support vector regression with . At the optimal solution, assume that and . What is and ?
- ,
- ,
- ,
- ,
Answer: 3. First compute . The target is below the score, and by , which is more than . The lower constraint requires , and minimization makes it exactly . The upper constraint already holds at . The handout's solution says that when there is a lower tube violation on some example, trivially there is no upper tube violation.
The in choice 1 is the gap between score and target, forgetting to subtract the the tube tolerates for free. Choice 4 has the right number on the wrong side: is below the score, so the violation is against the lower tube wall. Choice 2 makes both mistakes.
Taking the dual: escaping the feature dimension and seeing which points have β equal to 0
(Video 00:00–04:26 covers the Lagrange multipliers and a few KKT conditions, 04:26–09:25 compares the SVM and SVR duals, 09:25–12:38 covers sparsity, and Fun Time follows.)
Two sets of Lagrange multipliers
The SVR primal has two sets of tube-wall constraints, and page 14 gives each a set of multipliers:
- goes with the upper constraint .
- goes with the lower constraint .
and should each get a set of multipliers too. In the lecture, Lin explains why the handout leaves them out: the soft-margin SVM derivation already showed that multipliers of this kind can all be expressed through in the end, so only is tracked.
On this page the handout lists only "Some of the KKT Conditions" and leaves the full derivation to the reader; the bottom of the page reads: standard dual can be derived using the same steps as Lecture 4. In the lecture, Lin says it is almost a repeat of everything done in Techniques Lecture 2 or Lecture 4, only with more variables, and encourages everyone to take a sheet of paper and spend ten to fifteen minutes writing it out. That sheet of paper is written out below; the results the handout lists are marked as such, and the remaining steps were filled in by this article following Techniques Lecture 2: Dual SVM and Techniques Lecture 4.
Deriving the dual
Write the Lagrange function. Move each constraint into the form "some quantity ", multiply it by its own multiplier, and add it to the objective. The multipliers for are written and (this notation is this article's own), and no multiplier is negative:
As in Techniques Lecture 2, the primal problem equals , strong duality lets the min and the max trade places, and the inner problem has no constraints on , so every partial derivative has to be 0.
Partial derivatives with respect to and .
So and , which is what the lecture means by expressing them through . then becomes and . Substituting back, the coefficient of in is , likewise for , and every term containing disappears.
Partial derivative with respect to . The coefficient of is in the term and in the term:
This is the second condition listed on page 14 of the handout. With it, the terms containing disappear too.
Partial derivative with respect to .
This is the first condition the handout lists. is once again a linear combination of the , and the coefficient is the SVR version of . In the lecture, Lin points out that the comes from differentiating the inside the constraints, much as in soft-margin SVM.
Substitute back. With and eliminated, what is left of is
The sum in the second term is itself, so the first two terms combine into . The dual problem takes the max over :
Multiply by to turn it into a min, expand the squared length into a double sum, replace the inner products with the kernel, and you have the SVR dual at the lower right of page 15 of the handout, where is shorthand for :
Only kernel values remain in the formula, and is gone.
Matching it up without re-deriving: SVM against SVR
The lecture does not go through that derivation. Instead it uses the four colors on page 15 to show that the shape of a dual problem can be traced. The slide lays out the primal and dual problems of soft-margin SVM and SVR in two columns, and things of the same color end up in the same place:
| What is in the primal | Where it goes in the dual | soft-margin SVM | SVR |
|---|---|---|---|
| The multiplying in the constraint (and its coefficient) | Coefficients of the quadratic term | , with coefficients | |
| The constant in the constraint | Coefficients of the linear term | (from the 1 in ) | and |
| Partial derivative with respect to | One equality | ||
| and | Upper bound on the multipliers | , |
To make the correspondence visible, the slide writes the two SVR constraints as and , and that 1 stands where SVM's stands. In the lecture, Lin says that once you have these four colors down and know which coefficient goes where, you can write the dual from the primal.
The handout's conclusion on this page is: similar QP, solvable by similar solver. The lecture adds what this means in practice: the fast, good solvers designed for soft-margin SVM can be applied to SVR in a similar way.
Sparsity: points inside the tube have β equal to 0
All this effort was to find out whether SVR has SVM's kind of sparsity. The tool on page 16 is complementary slackness. The two conditions listed on page 14 of the handout are
Each is a multiplier times the slack of its constraint, and at least one of the two is 0. The lecture for Techniques Lecture 2 compared this relationship to Harry Potter and Voldemort, who cannot both survive; this lecture does not bring up the two names again and only keeps the same way of speaking: if the parentheses survive, the multiplier has to die.
Take a data point strictly inside the tube, . The handout's argument has four steps:
- It has no violation at all, so and .
- The two parentheses become and . The absolute value of the gap is strictly less than , so both parentheses are strictly greater than 0.
- The parentheses are not 0, so complementary slackness forces and .
- .
This data point contributes nothing to . Put the other way, the support vectors with can only be points on the tube wall or outside the tube (the handout: on or outside tube). The handout's conclusion is worded SVR: allows sparse . The more points there are inside the tube, the sparser is.
This article adds three more things that follow directly from these conditions and are not written on the handout:
- For points outside the tube, the multiplier hits . With an upper violation, . The constraint has its own complementary slackness , so , which means . A lower violation gives in the same way.
- The two multipliers of one data point are never both positive. If both were positive, both parentheses would have to be 0; the two parentheses add up to , which is always positive when , so they cannot both be 0. Hence is either or , with magnitude between 0 and .
- How to compute . Find a data point with : means , so ; means the parentheses are 0. Together they give , and this data point sits exactly on the upper tube wall. A data point with gives instead. This is the same procedure as computing from a free support vector (a support vector with ) in Techniques Lecture 4.
The three kinds of position in one table:
| Position of the data point | Violations | Multipliers | |
|---|---|---|---|
| Strictly inside the tube | both 0 | both 0 | |
| Exactly on the upper wall / lower wall | both 0 | / | between and / between and |
| Above / below the tube | / | / | / |
Numerical example: SVR on three points, primal and dual both solved
What follows is an example made up for this article, not from the slides. Three one-dimensional data points lie on one straight line, with no feature transform (, and the kernel is ), and , :
| 1 | ||
| 2 | ||
| 3 |
Step 1: solve the primal. Write . The upper violation of point 3 is at least , and the lower violation of point 1 is at least , so the sum of the violations is at least
Violations are never negative either, so the objective is at least , a lower bound that does not depend on . For it is , smallest at with value . For it is , whose derivative is , so the smaller is the larger the value, and it is larger than . The minimum of the lower bound is , attained at .
Next, confirm that this lower bound can be reached. with no violation at all needs for point 1 and for point 3, that is, and , so . The optimal solution is
Step 2: see where each data point is relative to the tube.
| score | score | Position | |
|---|---|---|---|
| 1 | exactly on the lower wall | ||
| 2 | strictly inside the tube | ||
| 3 | exactly on the upper wall |
Step 3: compute the multipliers from the KKT conditions. Point 2 is strictly inside the tube, so both of its multipliers are 0. Point 1 is on the lower wall, and its upper parentheses are , so and only can be positive. By the same reasoning, for point 3 only can be positive. Two equalities remain:
The solution is , both between 0 and . So
can also be computed with the formula added above: point 3 gives and point 1 gives , which agree.
Step 4: check the dual objective value. The quadratic term is . The linear term is . The total is , exactly the negative of the primal optimum (the dual was multiplied by to be written as a min), so strong duality holds.
What this result means.
- Only two of the three data points are support vectors. The middle one has and is not needed for prediction.
- The data actually lie on , yet SVR learns a line of slope . The tube tolerates an error of and the regularization term prefers a small , so it picks the flattest line that still just fits all three points inside the tube. When is chosen too large relative to the range of the data, the model comes out too flat, and that is the price of the extra parameter.
- Run kernel ridge regression on the same data (same kernel, ): , , . Try : , and making it equal means , so , none of them 0, and . The difference between one sparse model and one dense model shows up already on three data points.
This article checked the numbers in Python: solving the primal and the dual separately with scipy's numerical optimization gives , , , and objective values and ; scikit-learn's SVR(kernel='linear', C=1, epsilon=0.5) reports data points 1 and 3 as the support vectors, with coefficients and and intercept .
Fun Time: how many variables the SVR dual has
Question (page 17): What is the number of variables within the QP problem of SVR dual?
Answer: 4. The handout's solution: there are variables within , and another in .
Each of the other choices is the answer to a different question (this article's comparison): is the number of variables in the hard-margin SVM primal; is that of the SVR primal; is that of the SVM dual. The SVR dual has twice as many variables as the SVM dual because every data point has two tube walls, upper and lower.
Six lectures of kernel models on one map
(Video 00:00–02:25 is the map of linear models, 02:25–04:05 adds the kernel models, 04:05–05:47 discusses which ones are popular in practice, 05:47–06:44 is the power and responsibility of kernels, 06:44–07:20 is Fun Time, and the summary and the preview of the next lecture follow.)
There are five linear models
Page 18 of the handout first organizes the linear models. Foundations taught three: PLA/pocket for classification, linear (ridge) regression for real-valued regression, and logistic regression for soft classification. Techniques added linear soft-margin SVM to the classification column, and this lecture adds linear SVR to the regression column. In the lecture, Lin explains the logic of the layout: models that solve the same kind of problem go in the same column.
The full map once kernels are added
Page 19 grows two rows of kernel models underneath. The lecture's overall principle: as long as a linear model has regularization, it has a chance of being extended to a kernel. Together that makes four rows and three columns. The column names in the table below were added by this article following the lecture's explanation, and what is in the cells follows the handout:
| Row | Classification | Regression | Soft classification |
|---|---|---|---|
| 1 | PLA/pocket: minimize the 0/1 error in a special way | linear SVR: minimize the regularized tube error by QP | |
| 2 | linear soft-margin SVM: minimize the regularized hinge error by QP | linear ridge regression: minimize the regularized squared error analytically | regularized logistic regression: minimize the regularized cross-entropy by GD/SGD |
| 3 | kernel ridge regression: kernelized linear ridge regression | kernel logistic regression: kernelized regularized logistic regression | |
| 4 | SVM: minimize the SVM dual by QP | SVR: minimize the SVR dual by QP | probabilistic SVM: run logistic regression on SVM-transformed scores |
Row 3 relies on the representer theorem, and row 4 relies on the dual problem (probabilistic SVM is the two-level approach from the previous lecture).
Which are popular and which are less used
Pages 18 to 20 of the handout have one comment for each of the four rows:
| Row | The handout's comment | The lecture's reason |
|---|---|---|
| 1 | less used due to worse performance | PLA/pocket cannot match soft-margin SVM, which handles data that are not linearly separable and is efficient to solve. When squared error is what matters, linear ridge regression usually does better than linear SVR |
| 2 | popular in LIBLINEAR | These three models are the core of what LIBLINEAR implements, along with some variants |
| 3 | less used due to dense | Prediction takes much more effort and there is no extra benefit. Many people pick SVR over kernel ridge regression, and probabilistic SVM over kernel logistic regression |
| 4 | popular in LIBSVM | All three models are implemented in LIBSVM |
The lecture mentions that both packages were developed at NTU, and that LIBSVM is SVM software used by a great many people.
With great power comes great responsibility
Page 21 wraps kernel models up in one statement: the possible kernels are polynomial, Gaussian, or your own design (which must satisfy Mercer's condition), and coupled with the five models in rows 3 and 4 they are a powerful extension of linear models. The handout then quotes a line from the film Spider-Man: with great power comes great responsibility.
The lecture spells the line out. The Gaussian kernel corresponds to an infinite-dimensional transform, which is a great deal of power; Foundations already warned, when discussing feature transforms, that this kind of power calls for care. The concrete responsibility is to choose parameters carefully and validate carefully, so that the power does not get misused on overfitting.
Fun Time: which model is less used
Question (page 22): Which of the following model is less used in practice?
- ridge regression
- (linear or kernel) soft-margin SVM
- regularized logistic regression
Answer: 1. The handout's solution is that the pocket algorithm generally does not perform better than linear soft-margin SVM, and hence is less used in practice. Checking against the map above: pocket is in row 1; ridge regression and regularized logistic regression are in row 2, popular in LIBLINEAR; soft-margin SVM has its linear version in row 2 and its kernel version in row 4, both among the popular rows.
The summary on page 23 gives each of the four sections one line: kernel ridge regression is the representer theorem on ridge regression; the SVR primal is to minimize regularized tube errors; the SVR dual is a QP similar to SVM dual; and kernel models come with great power and great responsibility. The preview of the next lecture is making cocktail from learning models, and the lecture's picture is mixing a cocktail or a blended fruit juice, combining the strengths of different methods.
Self-check
1. Two data points: , ; , . Run kernel ridge regression with and , and find and .
Answer: and , so is a diagonal matrix with 5 on the diagonal, and . , which predicts at , smaller than the target ; that is the effect of regularization.
2. . One data point has score and target ; another has score and target . For each, what are , , the tube error, and the squared error?
Answer: for the first, and the target is above the score, so , , the tube error is , and the squared error is . For the second, , so it is inside the tube, both violations and the tube error are 0, and the squared error is .
3. Why must a point strictly inside the tube have equal to 0? Must a point with be outside the tube?
Criteria: the first part has to use complementary slackness and say that a point inside the tube has both violations equal to 0 and both parentheses strictly greater than 0, so both multipliers are 0. The answer to the second part is no, not necessarily: a point exactly on the tube wall can also have a nonzero . In this article's three-point example, both support vectors are on the tube wall and no point at all is outside the tube.
4. In the three-point SVR example, change to (with still ). What are the optimal and the objective value? What about and ?
Answer: reuse the example's lower bound . With , the derivative on the piece is , the minimum is at , and its value is , smaller than the of the no-violation solution. Once violations get cheaper, the model would rather let the first and last points stick out of the tube by in total in exchange for a flatter line; the multipliers of these two points both hit , and checks out. Here is not unique: keeping point 3 on or above the upper wall, point 1 on or below the lower wall, and point 2 inside the tube needs , and every in this range gives the same total violation and the same objective value. The reason is that no data point has a multiplier strictly between 0 and , so the formula under "How to compute " in the sparsity subsection has no point to use; the Techniques Lecture 4 handout says the same thing about soft-margin SVM: without a free support vector, you only get a range for . With , the lower bound on the sum of violations becomes and the lower bound on the objective is : for the derivative is , so the minimum is at , where , the objective value is , and all three points lie on the line. When the tube has no width, SVR fits the data exactly. This article checked both answers with numerical optimization.
5. data points, and after the feature transform. How many variables do the SVR primal and dual QPs each have? If you use kernel ridge regression instead, how large a matrix must be inverted?
Answer: the primal has variables and constraints. The dual has variables, independent of . Kernel ridge regression has to invert a dense matrix with entries, is on the order of , and almost none of the 10,000 values in the resulting are 0.
Exercises and corresponding reading
Neither semester of the in-person course scheduled this lecture. The Fall 2024 course page covered a revised Lecture 5 (slides 205u) in W11 (11/11) and went on to blending and bagging in the same week, with Lecture 6 not scheduled. The Fall 2026 course page finished kernel and soft-margin SVM in W10 and went straight to blending, bagging, and AdaBoost in W11 (11/18), with neither Lecture 5 nor Lecture 6 scheduled. So for this lecture the MOOC handout and videos are the only references, and both are free and public. If you only want to keep pace with the in-person NTU course, you can skip this lecture for now; if you want the complete picture of kernel models, this lecture fills in the regression part.
Homework. No public homework problem corresponds to this lecture. For how the homework maps onto the other Techniques lectures, see Techniques Homework and Final Project.
Hands-on. Take a regression data set and run scikit-learn's KernelRidge and SVR once each with the same RBF kernel. Compare their test errors, then count how many elements SVR's support_ has and how many entries of KernelRidge's dual_coef_ are nonzero, and you will see this lecture's sparse versus dense on real data. Then turn epsilon up and down and watch how the number of support vectors changes.
Further reading. Chapter 5 of the CS229 main notes derives kernel methods in a different way; Caltech Learning from Data is the English-language course for the same textbook.
Next lecture. Techniques Lecture 7: Blending and Bagging moves into the second family of techniques, Combining Predictive Features: Aggregation Models: when you have several models in hand, how do you put them together.
Course video sources
Original videos: Kernel Ridge Regression, Support Vector Regression Primal, Support Vector Regression Dual, Summary of Kernel Models
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: Changed to one article per lecture. This article covers only Techniques Lecture 6 and was rewritten from the handout and the video transcripts.
References
- Techniques Lecture 6 handout, 206_handout.pdf: the main source for this article. The derivations in the four sections, the four Fun Time questions, and the map of models all come from this handout.
- Machine Learning Techniques 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: confirms that this lecture was not on the Fall 2024 course plan.
- Machine Learning, Fall 2026 course page: confirms that this lecture was not on the Fall 2026 course plan.
- LIBLINEAR: the linear-model software mentioned for row 2 of the handout's map of models.
- LIBSVM: the kernel-model software mentioned for row 4 of the handout's map of models.
- CS229 main notes, main_notes.pdf: further reading, the kernel methods in Chapter 5.
- Caltech Learning from Data: further reading, the English-language course for the same textbook.
- Reading NTU Hsuan-Tien Lin Machine Learning Foundations & Techniques: Course Overview: where this lecture sits in the whole course and the reading routes.
Loading...