Classification · Part 5
A straight line cannot separate every class pattern. Map the inputs to a new feature space, then use the kernel trick to compute the inner products needed by an SVM.
6.4 · Nonlinear SVMWhat if no straight line separates the classes?
Part 4 learned a wide linear margin. Now one class surrounds the other. We extend the model by changing the geometry of the feature space.
6.4 · Nonlinear SVM
Map the predictors into a higher-dimensional space and fit a linear SVM there.
6.4.1 · The kernel trick
When the mapped vectors become too large, compute their inner products directly.
6.4 · Nonlinear SVMWhy a line cannot isolate the center from the ring
Inspect the inner cluster and outer ring. The outside class surrounds the inside class.
These 300 observations form an inner cluster surrounded by a ring. The classes cannot be separated by a line in the original two input coordinates. We can add a feature that measures squared distance from the center.
Static preview. Open handout.html to use the interactive example.
6.4 · Nonlinear SVMWhy a straight line cannot separate the ring
A line cannot put the center on one side and the whole ring on the other. The two points on opposite sides of the ring are joined by a segment that passes through the center.
Open the corresponding slide ↗6.4 · Nonlinear SVMMap the observations to a higher-dimensional space
To separate the center from the ring, map each observation to a cup-shaped surface. Keep its two coordinates and add a third for height.
6.4 · Nonlinear SVMSee what the new height measures
The center stays at height zero. A ring point gets a positive height. The farther a point lies from the center, the higher it lands on the surface.
Open the corresponding slide ↗6.4 · Nonlinear SVMRotate the lifted points and inspect the separating plane
A gold diamond marks the selected point. Drag to rotate, or toggle the plane to see the gap between the two height ranges.
The chart preserves each original point and adds x₁² + x₂² as its height. The displayed plane is placed in the gap between the observed height ranges. A linear SVM in the lifted space can learn a separator, which appears as a nonlinear boundary in the input plane.
Static preview. Open handout.html to use the interactive example.
6.4 · Nonlinear SVMA horizontal plane separates the lifted points
The inner points sit below the plane and the outer points sit above it. In the original two-dimensional view, the points at the plane’s height trace a circle.
Open the corresponding slide ↗6.4 · Nonlinear SVMA feature map can make a linear separator possible
Circular data
All blue points are below the cut. All orange points are above it.
When the heights overlap
The height ranges overlap. No single height cut separates these classes.
The added plane in the demonstration is a visual example. Fit a linear SVM in the mapped space to choose the weights and bias by the margin objective.
Open the corresponding slide ↗6.4 · Nonlinear SVMRecap · How linear SVM learns the weights
We choose the weights and bias that give the widest margin. Minimizing the squared weight norm does this while the constraints keep every training point on or beyond its own margin edge.
6.4 · Nonlinear SVMFit a linear SVM in the mapped space
m original featuresOutput
d mapped features
The objective stays the same. In the margin constraint, replace xᵢⱼ with ψⱼ(xᵢ).
In the mapped space, . The +1 counts the bias w₀. The feature map itself has m inputs and d outputs. If we fold the bias into the sum, it multiplies the fixed coordinate .
6.4.1 · The kernel trickThe Kernel Trick
Watch on YouTube6.4.1 · The kernel trickWhy do we need the Kernel Trick?
Suppose we only need the dot product of two mapped points. Try this quadratic map, which uses the two squares and their scaled product.
Original pair
Map to three coordinates, then take the dot product
Take the original dot product, then square it
Same dot product
1216.4.1 · The kernel trickA polynomial map can create too many features
A real dataset may need a much larger feature space. Consider a full degree-10 polynomial map for observations with 100 features. Powers and products quickly make the mapped vector too large to build.
6.4.1 · The kernel trickThe Lagrange Multipliers Visualized
Watch on YouTube6.4.1 · The kernel trickWhat are Lagrange multipliers?
Give each training point one nonnegative parameter, called a Lagrange multiplier. Its value weights that point’s margin constraint.
From multipliers to a separator
In the dual problem, we solve for first. The optimal multipliers let us recover the weights and the bias that solve the original SVM problem, called the primal.
Why subtract each constraint term?
The margin rule is . A point that falls short has a negative value inside the parentheses. Subtracting then raises the Lagrangian when .
6.4.1 · The kernel trickWrite the SVM problem using Lagrange multipliers
Use one multiplier per training point to bring the margin constraints into the objective.
Here is the score of training point i.
The weight term favors a wider margin. The sum adds a cost when a point falls short of its margin edge and its multiplier is positive.
Try the sum with one point
6.4.1 · The kernel trickPrimal and dual solve the same SVM
Both formulations give the same widest separating strip for this hard-margin SVM. They search using different variables.
Primal · Move the boundary
Choose how the line tilts and where it sits. Find the widest margin while keeping every point on the correct side of its margin edge.
Dual · Weight the training points
Give each training point a multiplier. The weighted, signed points add up to the normal. Points with multiplier zero contribute nothing. Use the margin points to locate the line.
6.4.1 · The kernel trickDifferentiate the Lagrangian, then set the derivatives to zero
Differentiate ℒ with respect to the weights and the bias.
Set both derivatives to zero to obtain the weight vector and the balance condition.
6.4.1 · The kernel trickThe dual chooses one multiplier per training point
1. Expand the Lagrangian. Start with the constrained-margin expression, then distribute the minus sign and collect terms.
2. Use the results from the previous slide. Substitute into the second term to get . The bias term is zero because .
3. Expand the squared norm. Take the inner product of the weighted sum with itself. This gives one term per pair of mapped points. Maximize the result over the allowed multipliers.
6.4.1 · The kernel trickUnderstanding the SVM Dual Formulation Geometrically
Follow three points with the identity feature map, from their original coordinates to the maximum-margin separator.
Open the corresponding slide ↗6.4.1 · The kernel trickThe Kernel Trick replaces the mapped inner product
Lifting the points made it possible to separate the ring from its center. To use that geometry, the dual needs the dot product of each pair of lifted points.
For the feature map from the ring example, compute each term using the two original coordinates of each point.
Original pair
Map both points, then take their dot product
Reuse the ring example’s feature map. Keep both coordinates and add the height.
Evaluate the kernel on the original pair
Same value
4 for the SVM dual6.4.1 · The kernel trickThe quadratic kernel saves work
For a point with m original features, the quadratic map includes every squared feature and every scaled product of two distinct features.
Quadratic feature map
Build coordinates per point, then take the dot product of the expanded vectors.
Equivalent quadratic kernel
Take the dot product of the original inputs and square it. That gives the same result in 2m operations per pair, using the original m coordinates.
Optional derivation · Not required for study
The two √2 factors give 2 for every distinct feature pair. Grouping those terms gives the square of the original dot product.
Check your understandingFour questions about nonlinear SVMs
- The inner class reaches radius 1.2. The ring starts at radius 1.5. Choose a height threshold z = t for z = x₁² + x₂² and justify it.
- Two training points have labels −1 and +1. Their dual multipliers are 0.4 and 0.6, respectively. If the first stays fixed, what must the second be to satisfy the bias condition?
- The feature map gives ψ(x) = (2, 1) and ψ(z) = (−1, 3). What must a kernel matching this map return for κ(x, z)?
- Where does the kernel enter the dual? Which parts of the optimization stay the same?
Check your understandingWork through the four answers
- The possible threshold range is 1.44 < t < 2.25. For example, t = 2 puts the highest inner point below the plane and the lowest ring point above it.
- The bias condition is −0.4 + a₂ = 0, so a₂ = 0.4.
- Compute the inner product of the mapped coordinates. κ(x, z) = 2 × (−1) + 1 × 3 = 1.
- Replace each mapped inner product with the kernel value. The multipliers, labels and constraints stay the same.
6.4.1 · The kernel trickFrom a feature map to the kernel trick
Map the features
A linear separator in the mapped space can describe a nonlinear boundary in the original inputs.
Learn the dual
Use one multiplier per training observation. The data appear through mapped inner products.
Evaluate a kernel
Compute each mapped inner product directly from the original inputs.
Further readingBishop on classification
Read chapters 4 and 7 for linear discriminants, perceptron learning, and support vector machines.
Open the corresponding slide ↗Lecture recapWhat to take away
- Explain how a feature map can separate the center from a surrounding ring.
- Follow the mapped objective, Lagrangian and dual using the same notation.
- Use a kernel to compute the mapped inner products in the dual.