Skip to main content
Mathematical Foundations for Machine Learning

Support Vector Machines

Published: 2026-07-11
Level: postgraduate
Audience: Postgraduate students in Machine Learning

Prerequisite Knowledge

This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.

Previously Covered in This Subject

    Vector spaces, rank, and linear independence — covered in Lecture 3 (Groups. Vector Spaces, and Linear Combinations) and Lecture 4 (Vector Spaces, Linear Independence, Basis and Dimension) Partial derivatives, the chain rule. And gradients — covered in Lecture 8 (Singular Value Decomposition and Vector Calculus) and Lecture 9 (Gradients, the Jacobian, and Taylor Series) Convexity and the Hessian matrix — covered in Lecture 10 (Taylor Series and Hessian-Based Optimization) and Lecture 12 (Challenges of Gradient Descent and Constrained Optimization) Gradient descent — covered in Lecture 11 (Gradient Descent) Taylor series — covered in Lecture 9 and Lecture 10; the exponential expansion underpins the RBF kernel's infinite-dimensional interpretation

20.1 Hard Margin SVM — Review

20.1.1 Maximizing the Margin

Hook. Imagine you are a city planner drawing a road to separate two neighborhoods. You could sketch the road right next to one neighborhood. — but then a single new house could land on the wrong side. What if you instead built the widest possible road, keeping it as far from both neighborhoods as possible? That road would survive small changes in house locations. SVM does the same thing with data.

Intuition. Think of a sheet of paper with red dots on one half and blue dots on the other. You lay a ruler between them. You can slide the ruler around and tilt it — many straight lines separate the dots. But one particular placement leaves the most breathing room on both sides. SVM finds that placement. The trick is to measure distance not to all dots. But only to the ones nearest the ruler — those are the support vectors.

Analogy — the widest street. Picture two rows of houses facing each other across an empty lot. You want to pave a street between them. If the street hugs one row. A new house built slightly closer to the other side could end up in the middle of the road. The safest street is the one whose edges are as far as possible from the nearest house on either side. That is exactly what the margin is: the width of the empty strip between the closest houses of the two classes.

Where the analogy breaks: real houses sit on a flat 2D lot. Data lives in -dimensional space and the "street" is a -dimensional hyperplane. But the geometry works the same way — the margin is still the perpendicular distance between two parallel boundary planes.

Formal definition. A Support Vector Machine in its hard-margin form finds a hyperplane that separates two classes with the widest possible margin. The margin is the perpendicular distance from the separating hyperplane to the nearest data point on either side.

The hyperplane is written as:

where is the weight vector (a normal vector. — it points perpendicular to the hyperplane) and is the bias term (it shifts the hyperplane away from the origin). For any two points on the hyperplane, the vector between them is orthogonal to .

The margin. Imagine three parallel planes with the same normal vector :

    Positive margin boundary: Decision boundary: Negative margin boundary:
We set the margin boundaries at . This is a normalization choice — scaling and by the same factor leaves the decision boundary unchanged. So we have the freedom to pin the boundaries at . This is called the canonical hyperplane convention.

The margin is the perpendicular distance between the two boundary planes. Let be a point on the boundary and be a point on the boundary. The vector connecting them is . Projecting this vector onto the unit normal :

Since and :

So the margin is:

where is the Euclidean norm of .

To maximize the margin , you minimize . For mathematical convenience, SVM minimizes . The factor makes derivatives cleaner. The square makes the objective strictly convex — the surface curves upward everywhere with exactly one minimum and no local traps.

Symbol registry:

SymbolMeaningTypeDomain
weight vector (normal to hyperplane)any real -vector
bias term (intercept)any real number
-th data pointany real -vector
label of -th point or
Lagrange multiplier (penalty)non-negative

20.1.2 The Primal Optimization Problem

You want every data point correctly classified and at least one unit away from the decision boundary. Multiply the signed output by the label :

    If the point is on the correct side, If the point is on the wrong side, the product is negative
The constraint enforces two things at once: correct classification AND distance of at least 1 from the boundary. When , the constraint becomes (point is at or beyond the positive boundary). When , it becomes (point is at or beyond the negative boundary).

Primal Hard-Margin SVM:

This is a convex quadratic programming problem. The objective is quadratic (and strictly convex in ), and the constraints are linear in both and .

Scope. Hard-margin SVM applies only when:

    The data is linearly separable — a hyperplane exists that perfectly splits the two classes. If the data is not separable, the feasible set is empty and no solution exists.No outliers contaminate the boundary — a single mislabeled point on the wrong side of the margin makes the problem infeasible. This is why soft-margin SVM (Section 20.4) exists.The classes are balanced enough that pushing the margin out evenly does not favor one class. When one class has far fewer examples, the margin may be dominated by the majority class's layout.
If you try hard-margin SVM on non-separable data, the optimization has no feasible solution — the constraints cannot all be satisfied. The solver will simply fail.

20.1.3 Lagrangian and Dual Formulation

To solve the constrained optimization, we use the method of Lagrange multipliers. Each constraint gets a multiplier . The Lagrangian function is:

Think of each as a fine levied by an inspector when a data point sits on or inside the margin. A zero fine means the point is safely outside. A positive fine means the point is "touching" the margin and matters.

Analogy — site inspector. Hire an inspector () for each house. If the house is on the pavement or on the wrong side of the street, the inspector levies a fine. Your job: build the widest street possible while minimizing the total fines you pay. The Lagrangian combines both goals — widen the street () and avoid fines ().

We find the stationary point by setting the partial derivatives to zero.

Derivative with respect to :

The optimal weight vector is a linear combination of the training data points. This is an instance of the representer theorem — the solution lies in the span of the data.

Derivative with respect to :

The weighted sum of labels must balance. The positive and negative influences cancel out.

Substituting back to get the dual. Replace in the Lagrangian with . The algebra (collecting terms, using to drop the -term. And simplifying the quadratic form) yields the dual problem:

subject to:

This is a simpler problem. The decision variables are now the 's — one per data point — instead of the -dimensional . The dual depends only on dot products between data points. No weight vector or bias appears directly. This dot-product dependency is the door the kernel trick walks through later (Section 20.6).

Visual intuition. Imagine a 2D scatter plot. The x-axis is feature , the y-axis is feature . Blue discs are the positive class, orange crosses are the negative class. The decision boundary is a straight line . Two dashed lines parallel to it, at distances and in the scaled coordinate system, mark the margin edges. The weight vector points perpendicular to all three lines. The distance between the two dashed lines is . A shorter means a wider gap. The support vectors are the points that touch the dashed lines — typically just a few points. The ones closest to the boundary.

Pitfalls.

    Forgetting the bias. Without the bias term , the hyperplane must pass through the origin. This forces for the decision boundary. In general, the data is not centered at the origin, and you need the bias to shift the boundary anywhere.Confusing the margin formula. The margin is , not . The factor of 2 comes from the two boundaries being at and — total width is 2 units in the canonical scale.Scaling trap. and are defined only up to a scale factor. If you multiply both by 10, the decision boundary stays the same, but changes. The SVM convention fixes this by pinning the margin boundaries at .Assumption of separability. Hard-margin SVM assumes perfect linear separability. Real data rarely satisfies this. If your solver returns "infeasible," switch to soft-margin SVM.
Recap. Hard-margin SVM finds the widest possible empty strip separating two classes. The margin is . And maximizing it leads to a quadratic program: minimize subject to every point being at least one unit from the boundary. The dual formulation reveals that is built only from dot products among data points. — a fact that will let us lift data into higher dimensions using kernels.

Bridge. Now that you have the optimization problem, the next question is: which data points actually matter? The answer lies in the KKT conditions and the idea of support vectors. — only the points sitting exactly on the margin influence the classifier. The rest of the data is irrelevant. Section 20.2 makes this precise through complementary slackness.

Real-world connection. SVMs powered text classification for over a decade — spam filters, document categorization, sentiment analysis. The hard-margin variant is mostly a pedagogical stepping stone, but the geometry it establishes (maximum margin. Support vectors, dual formulation) is the foundation every kernel method builds on. In bioinformatics, hard-margin ideas underpin protein fold recognition where data from different structural classes genuinely separates in feature space.

20.2 Support Vectors via Complementary Slackness

20.2.1 Complementary Slackness Condition

Hook. You solved a classification problem and got a weight vector . Now ask: which training points actually decided where the boundary went? Surprisingly, the answer is "hardly any of them." Most of your training data contributed nothing at all to the classifier.

Intuition. Think of a tug-of-war. The rope's position is determined by the strongest pullers at the front — not by the crowd cheering from behind. In SVM, the "pullers" are the data points closest to the separating hyperplane. Points deep inside their class region are like bystanders — they exert zero force on where the boundary sits.

Analogy — the fence posts. Imagine you stretch a fence between two fields. You only need posts at the points where the fence comes closest to the crop on either side. Once those posts are in, the rest of the fence is determined. You do not need a post for every inch of field — just the critical spots. Support vectors are the fence posts. Complementary slackness is the rule that says: only posts at the tightest spots get any pull.

The KKT (Karush-Kuhn-Tucker) conditions are the "optimality checklist" for a constrained optimization problem. One of them — complementary slackness — is the reason SVM is sparse. It says: for every constraint, the product of the Lagrange multiplier and the constraint slack must be zero.

For hard-margin SVM, the primal constraint is:

The dual constraint on the multiplier is . Complementary slackness demands:

This is a binary switch. For each data point, the product is zero only if at least one factor is zero:

    Scenario A: . The multiplier is "switched off." The point's constraint slack has no influence on the solution. This means the point is safely outside the margin — .Scenario B: . The point sits exactly on the margin boundary. Its multiplier can be positive (it may be zero, but it is allowed to be non-zero). This point contributes to and therefore shapes the classifier.
These are the only two possibilities. A point cannot both have a positive multiplier AND sit far from the margin — the product would be non-zero. Violating complementary slackness.

The four KKT conditions together are:

    Primal feasibility: for all Dual feasibility: for all Stationarity: (gave us and )Complementary slackness: for all
For convex problems like SVM, Slater's condition guarantees strong duality — the dual solution equals the primal solution. The SVM problem is convex (quadratic objective. Linear constraints) and the feasible region has an interior (at least one point satisfies the constraints with strict inequality). So Slater's condition holds. This is why we can confidently solve the dual problem and get the correct answer.

20.2.2 Support Vectors Define the Classifier

Recall from the Lagrangian stationarity condition:

The weight vector is built as a weighted sum of data points, each scaled by . Complementary slackness drives this home: any point with contributes exactly nothing. So the sum reduces to only those points with :

These points — the ones with — are the support vectors. They "support" the hyperplane. Remove or move one, and the boundary shifts. Remove a non-support-vector, and nothing changes at all.

This is why the method is called Support Vector Machine. The classifier lives and dies by its support vectors. Change a point far from the margin and nothing happens. Move a support vector and the whole boundary shifts.

In practice, the number of support vectors is typically a small fraction of the training data. The sparsity is a huge practical advantage: prediction only requires computing dot products with the support vectors, not the full training set.

Visual intuition. Picture the 2D scatter plot from Section 20.1. Three parallel lines: the decision boundary in the center, and two margin boundaries at . Most blue discs are far to the right of the line. Most orange crosses are far to the left of the line. Only a handful of points — maybe 2 or 3 — actually touch the dashed lines. Draw a circle around those touching points. Those are the support vectors. Now erase all other points. The maximum-margin line stays exactly the same. The support vectors alone determine everything.

Scope. Complementary slackness as stated here applies to the hard-margin case where the margin boundaries are at exactly . In soft-margin SVM (Section 20.4), the condition becomes:

Plus an additional condition for the slack variable multipliers. The interpretation changes: points with are margin support vectors; points with are inside the margin or misclassified.

Pitfalls.

    Thinking all points are on the margin. In the hard-margin case. Complementary slackness forces iff the point is exactly on the margin. But in soft-margin, points inside the margin or misclassified can also have positive . The exact location depends on whether (on the margin) or (inside or wrong side).Confusing Slater's condition with KKT. Slater's condition is a qualification — it guarantees strong duality applies. KKT conditions are the optimality checks the solution must pass. For SVM, both hold because the problem is convex and strictly feasible, but they serve different roles.Why not use all points? If every point contributed, the classifier would be a dense sum over the entire dataset. Prediction would be slow. The sparsity from complementary slackness is a feature, not a bug — it makes SVM efficient at test time.
Recap. Complementary slackness forces only for points on the margin. Those points are the support vectors, and they alone build the weight vector . All other points contribute nothing. This is why SVM is sparse: the classifier depends on a handful of critical points near the boundary.

Bridge. Section 20.3 works through a concrete numerical example where you solve for . , and with two data points — showing the full machinery in action on a tiny dataset.

Real-world connection. The sparsity of support vectors is what made SVM practical at scale long before GPUs existed. A classifier trained on a million documents might depend on only a few thousand support vectors. In text classification (spam detection, news categorization). This meant fast predictions — you only compute dot products against the support vectors, not the full vocabulary. The same sparsity principle re-emerges in modern techniques like prototype-based learning and coreset selection.

20.3 Hard Margin SVM: Worked Numerical Example

20.3.1 Problem Setup

Hook. All the theory — Lagrangians, duality, KKT — means nothing until you can solve a concrete problem with real numbers. Here is one. Two data points, opposite classes. Find the maximum-margin line.

Intuition. With exactly two points of opposite class, the maximum-margin line is simply the perpendicular bisector of the segment joining them. The SVM machinery should recover exactly that. Watch as the algebra confirms what geometry tells you upfront — a nice sanity check.

Analogy. You and a friend stand 10 meters apart in a field. You claim the ground on your side is yours; your friend claims the other side. The fairest boundary is the line exactly halfway between you, running perpendicular to the line connecting you. SVM with two opposite-class points does exactly the same thing in higher dimensions.

You are given two data points:

With only two points, both must be support vectors. The decision boundary is a line exactly halfway between them.

The hyperplane equation is:

where is the weight vector. For the two support vectors, the margin conditions are:

The unknowns are , , , — but is expressed in terms of through the Lagrangian derivative. So the true unknowns are .

20.3.2 Expressing in Terms of Data Points

From the Lagrangian derivative :

Substitute this into the two margin equations.

For point 1:

Expanding with the bilinearity of the dot product:

For point 2:

Expanding:

We have three unknowns (, , ) and two equations. We need a third.

20.3.3 The Third Equation and Dot Product Computation

From the stationarity condition :

Plugging in and :

This makes sense: with two symmetric points, their multipliers balance.

Now compute the dot products:

20.3.4 Solving the System of Equations

Plug the dot products and known values into the two main equations.

Equation 1 (from point 1, with margin ):

Equation 2 (from point 2, with margin ):

Equation 3 (from stationarity):

Substitute into both equations:

Equation 1 becomes:

Equation 2 becomes:

Subtract the first transformed equation from the second:

Since :

Now find . Use :

Now compute :

So and .

The decision boundary is :

Multiply through by :

The margin boundaries are (positive side) and (negative side). The margin is:

Sense check. The two points are 2.83 units apart (distance from to is ). The margin equals exactly the distance between the points. — which makes sense: both are support vectors on opposite margins. So the total gap between the boundary planes equals the distance between the two closest opposite-class points.

20.3.5 Geometric Interpretation

Plot the two points: is in the positive class and is in the negative class. The line connecting them runs diagonally. The separating hyperplane is perpendicular to that connecting line and passes through the midpoint. The midpoint of and is . And — exactly what the equation says.

The weight vector is parallel to . Which is perpendicular to the line (since the normal to is . And is just the negative of that normal — same direction, flipped sign by the label convention).

Logic check: Even without SVM machinery. The maximum-margin line between two points of opposite class is the perpendicular bisector of the segment joining them. The SVM math recovers exactly that. The midpoint satisfies , and the weight vector is orthogonal to the bisector.

Scope. This 2-point solution strategy works cleanly only for the hard-margin case. With 3+ points, not every point is a support vector. And you need to use complementary slackness to identify which are zero and which are positive. The approach here — setting up equations from the margin conditions for every point. — only works when you know in advance which points are support vectors. For larger problems, you solve the dual quadratic program numerically using SMO (Sequential Minimal Optimization) or a QP solver.

20.3.6 Student Questions on the Worked Example

Q: Can we just take the bias as 1 and avoid solving for it?

A: You can set bias to 1 only if the data is normalized first. With unnormalized data, the bias can be any value — the optimization finds the right number. Setting it to 1 without normalization would force the hyperplane to be one unit from the origin. Which may sit nowhere near your data. You must solve for from the equations.

Q: How do you get the derivative and the condition ?

A: Take the Lagrangian: . Differentiate with respect to . The first term has no , so its derivative is zero. The sum expands to . Only the middle term depends on . Its derivative is . Setting this to zero gives the stationarity condition .

Q: What would happen if we left bias out entirely?

A: Without bias, the equation becomes for positive points. A plane of that form must pass through the origin — the decision boundary is forced through no matter what direction points. That works only if the data happens to be separable by a plane through the origin. In general, the bias term is what lets the boundary sit anywhere in space. Drop it and you severely restrict what the classifier can do.

Recap. For two opposite-class points, SVM algebraically recovers the perpendicular bisector: . , decision boundary , margin . The three equations come from two margin conditions plus the stationarity condition .

Bridge. This example used hard-margin SVM. But what if one of the points was mislabeled or the data was not perfectly separable? Section 20.4 introduces soft-margin SVM, which lets some points violate the margin — paying a penalty for each violation.

Real-world connection. Solving small SVM problems by hand like this builds the intuition you need to debug production classifiers. When scikit-learn's `SVC` gives a surprising decision boundary. You can trace it back: check the support vectors, verify their dot products, and ensure the margin conditions hold. In practice, numerical solvers like LIBSVM use SMO to solve the dual. But the underlying linear system for the support vectors is exactly the structure you just solved manually.

20.4 Soft Margin SVM

20.4.1 The Slack Variable

Hook. Hard-margin SVM is a perfectionist — it demands every point sit outside the margin. One outlier, one mislabeled point, and the whole problem becomes infeasible. Real data is never that clean. How do you build a street when a few houses are already built in the middle of the road?

Intuition. Instead of demanding perfection, you allow some points to break the rules — but you charge them a penalty. The deeper a point intrudes into the margin or crosses to the wrong side, the more it pays. This creates a trade-off: you can have a wide margin (good for generalization) if you accept a few violations (tolerable if the cost is low).

Analogy — the speed limiter. Driving a car with a speed limiter set to 100 km/h. Going above 100 costs you a fine proportional to how much you exceed it. If fines are cheap (small ), you speed whenever convenient. If fines are ruinous (large ), you stay strictly under 100 no matter what. Soft-margin SVM uses exactly this penalty structure — the slack variable measures "how much over the limit" each point goes. And is the fine per unit of violation.

A slack variable is introduced for each data point. It measures how far a point intrudes into the margin or crosses to the wrong side. Three regimes:

    : Point is correctly classified and outside (or on) the margin. No penalty.: Point is correctly classified but inside the margin strip. It is between the boundary and the decision boundary (or the boundary and the decision boundary).: Point is misclassified — on the wrong side of the decision boundary. The larger , the deeper the violation.
The hard constraint relaxes to:

When , this reduces to the hard-margin constraint. When , the right-hand side drops below 1. Letting the point sit closer to the decision boundary or even cross it.

20.4.2 Soft Margin Primal Form

The objective now has two competing forces. You still want a wide margin (minimize ), but you also penalize violations (minimize ). The soft-margin primal:

subject to:

is a hyperparameter you choose before training. The sum is the total slack — the aggregate violation across all points. Points that are correctly classified and outside the margin contribute zero to this sum.

Note that the regularization is on only — the bias term is not regularized. This is because the bias does not affect the margin width; the margin depends only on .

20.4.3 The C Parameter — Trade-off Control

controls the trade-off between margin width and training error:

    Large (e.g., or ): Every unit of slack is heavily penalized. The optimizer works hard to keep tiny. The margin becomes narrow. The boundary twists to avoid errors. The model memorizes noise — it overfits. At the limit , soft-margin approaches hard-margin.Small (e.g., ): Slack is cheap. The optimizer prioritizes a wide margin over perfect classification. The boundary is smooth and generalizes well, but some training points may be misclassified or sit inside the margin.
Think of as an inverse regularization strength. A large means weak regularization (the term gets relatively little weight compared to the penalty sum). A small means strong regularization (the margin term dominates, forcing small and the margin large).

Symbol note: Some texts parametrize with and write the objective as . This flips the intuition — large then means strong regularization. The professor uses the -SVM convention: .

Scope.

    Soft-margin SVM still requires the data to be mostly separable. If the two classes are completely mixed (e.g., random labels), even soft margin cannot find a good classifier. The kernel trick (Section 20.6) can help with non-linear separability, but fundamentally inseparable distributions need a different model.The primal formulation has variables (), which is impractical for large feature dimensions. The dual (Section 20.4.4) recasts it in terms of variables (). Making it suitable when is moderate but is large. is scale-sensitive. If you rescale your features (e.g., from meters to millimeters), the same has a very different effect. Always normalize features before tuning .

20.4.4 Soft Margin Dual Form

The Lagrangian for soft-margin SVM introduces multipliers for the classification constraints and for the non-negativity constraints :

Stationarity conditions:

    (same as hard margin) (same as hard margin)
Since , the third condition gives . Combined with the dual feasibility , this yields the box constraint:

The dual maximization problem is identical in form to hard margin:

But with the modified constraint on :

Interpretation of values:

    : Point is correctly classified and outside the margin.: Point is a support vector exactly on the margin boundary (margin support vector).: Point is a support vector inside the margin or misclassified. Its .
The box constraint is what makes the dual easy to solve numerically. — it constrains each to a bounded interval. Which is efficient for coordinate-descent solvers like SMO.

Visual intuition. Picture the 2D scatter with a soft-margin boundary. Most blue discs are to the right of the dashed line (zero slack). A few blue discs sit between the line and the decision boundary (). Maybe one blue disc is on the wrong side (). The weight vector is shorter than it would be under hard margin — the margin is wider. The boundary does not contort to accommodate every outlier.

Pitfalls.

    Not tuning . The default in most libraries is rarely optimal. You must cross-validate over a logarithmic grid (e.g., ).Forgetting to normalize. Features with large ranges dominate the norm and the dot products. Always standardize to zero mean and unit variance before training SVM.Large on noisy data. A very large forces the boundary to fit every point, creating a wiggly, overfitted decision surface. The test accuracy collapses.Confusing the box constraint. means no alpha can exceed . Points with are not "more important" — they are actually the troublemakers (inside the margin or misclassified).
Recap. Soft-margin SVM introduces slack variables that let points violate the margin at cost . The dual has the same objective as hard-margin but constrains . Points with are safe, are margin support vectors. And are margin-violating support vectors. The hyperparameter trades off margin width against training error.

Bridge. The slack variables directly lead to the hinge loss. When you optimize out the slacks, the objective becomes an unconstrained problem: minimize . Section 20.5 derives and analyzes this loss function in detail.

Real-world connection. Soft-margin SVM is the version used in every production library (scikit-learn's `SVC`, LIBSVM, SVMlight). Hard-margin is a teaching tool. In medical diagnosis, a soft-margin classifier tolerates a few misclassified patients (false positives or false negatives) to achieve a wider. More generalizable margin — critical when diagnostic measurements are noisy and overlapping.

20.5 Hinge Loss

20.5.1 Deriving the Hinge Loss

Hook. The soft-margin primal has both and as variables — unknowns. But you can eliminate the slacks entirely and get a single, clean optimization problem in just and . The function that replaces the slacks is the hinge loss — the native loss function of SVM.

Intuition. Imagine a grading scheme: if your answer is far on the correct side of the cutoff, you get zero penalty. If it is close to the boundary or wrong, you lose points. The penalty grows linearly as you drift further from the safe zone. The hinge loss captures exactly this: zero penalty for "comfortably correct" and linear penalty for "too close" or "wrong."

Analogy — a restaurant rating system. A chef's performance is rated by customer satisfaction scores. If the score is above 4 stars (comfortably good), no penalty. If it drops below 4, the penalty is — a chef with a 3.2 gets a penalty of 0.8. A chef with a 1.5 gets a penalty of 2.5. The penalty is zero for solid performers and grows linearly for underperformers. The hinge loss works the same way: it is zero above the threshold of 1, and rises linearly below it.

Start from the soft-margin constraint:

Rearrange to isolate :

Together with the non-negativity constraint , the slack must be at least the larger of these two lower bounds. Since the objective wants to minimize each , the optimizer will set it to the smallest value that satisfies both:

Define — the score, the label-signed output. Then the hinge loss is:

Substituting this into the soft-margin objective gives an unconstrained problem:

The first term (regularizer) controls margin width. The second term (loss) penalizes points that are too close to or on the wrong side of the boundary. This is empirical risk minimization with L2 regularization and hinge loss.

20.5.2 Two Cases for the Hinge Loss

The hinge loss naturally splits into two regimes based on the score :

Case 1 — Comfortably correct (): The point is classified correctly and lies on or outside the margin. Then , so . No penalty. These points do not contribute to the loss term at all.

Case 2 — Too close or wrong (): Two sub-cases:

    : The point is on the correct side of the boundary but inside the margin. The loss is .: The point is on the wrong side of the boundary (misclassified). The loss is .
The loss grows linearly without bound as the point moves further into the wrong territory. This is why hinge loss is called a linear penalty loss — unlike squared loss. It does not explode quadratically for large errors. This makes SVM robust to outliers that are correctly classified (they produce zero loss) but still penalizes misclassified points proportionally.

Comparison with zero-one loss: The zero-one loss is 1 for any misclassification and 0 otherwise. The hinge loss is a convex upper bound — it is always at least as large as the zero-one loss. And being convex makes it far easier to optimize. Minimizing the hinge loss pushes the zero-one loss down indirectly.

Worked hinge loss calculation. Given , , , :

Step 1 — Compute the linear output:

Step 2 — Compute the score:

Step 3 — Compute the hinge loss:

Result: The point has a score of 2.5, which is well above 1 — it sits far on the correct side. Hinge loss is zero.

Another example — point with same , , :

This point is misclassified (negative score) and pays a penalty of 2.5.

Scope.

    Hinge loss is not differentiable at (the "hinge" point). Gradient-based optimizers need subgradient methods — the subgradient is 0 for . at , and for .For the dual formulation, hinge loss manifests as the box constraint . There is no explicit hinge loss in the dual — it shows up only in the primal/unconstrained form.
Q: How do you actually compute hinge loss for a given point?

A: Three steps: (1) compute the dot product . Add the bias ; (2) multiply by the label to get the score ; (3) compute . This gives the loss for that single point. The total loss is the sum over all points.

Pitfalls.

    Confusing the score with the dot product. The dot product alone () is not the score. — you must multiply by the label. A positive dot product for a negative-class point means misclassification, but the raw dot product doesn't capture this. The score folds the label into the signal.Hinge loss is not cross-entropy. For binary classification with , the hinge loss is . For labels in , the hinge loss is where — a different convention. Know which label encoding your framework uses.Forgetting the margin term. The unconstrained objective is , not just . Without the regularizer. The optimizer would make large enough to push all scores above 1 — trivially achieving zero loss but with no margin.
Recap. The hinge loss is zero for points correctly classified with margin. And grows linearly for points too close to or on the wrong side of the boundary. It is a convex upper bound on the zero-one loss, making it optimizable. Substituting hinge loss into the soft-margin objective eliminates the slack variables, giving an unconstrained regularized empirical risk minimization problem.

Bridge. Armed with soft margin and hinge loss, you can now handle non-separable data. But what if the data is separable only by a curve, not a line? Section 20.6 introduces the kernel trick — a way to lift data into higher dimensions where linear separation becomes possible. Without ever visiting those dimensions.

Real-world connection. Hinge loss appears beyond SVM — in ranking algorithms (RankSVM). Structured prediction, and some neural network training schemes (maximum-margin neural networks). In text categorization, hinge-loss-trained linear classifiers can match the accuracy of much more complex models while training in seconds on CPUs. Making them the go-to baseline for production systems with tight latency budgets.

20.6 The Kernel Trick

20.6.1 Non-Linear Separability

Hook. A straight line can separate two classes in many problems. But what about the XOR pattern — four points arranged like a checkerboard? No single line can split them. You have two choices: accept misclassifications forever, or get clever. The kernel trick is the clever one.

Intuition. Imagine you have red and blue marbles on a flat table, arranged in the XOR pattern. You cannot draw a straight line that separates them. Now lift one color of marbles slightly above the table. In 3D, a flat sheet of paper can slide between the lifted marbles and the ones still on the table. Look down from above — the boundary looks curved. But in the elevated space, it is perfectly flat. The kernel trick does this mathematically: it lifts data into a higher dimension where separation becomes trivial. But it never actually moves the points — it just computes what their dot products would be in that higher space.

Analogy — the map projection trick. A flat map of Earth distorts distances. But if you measure the straight-line distance through the Earth (3D). You can get the true shortest path without ever needing a globe. — you compute it from latitude and longitude using spherical geometry. The kernel function is that formula: it computes similarity in the high-dimensional "true" space directly from low-dimensional coordinates.

20.6.2 Projecting to Higher Dimensions

The XOR problem shows why linear classifiers fail on non-linear data. Points at and are class A. Points at and are class B. Any line that gets three right gets the fourth wrong.

The mathematical insight: define a feature map that transforms each data point into a higher-dimensional space ():

In this new space, you find a linear hyperplane . When mapped back to the original space, this linear hyperplane becomes a non-linear decision boundary.

For XOR, using lifts the points into 3D. The blue points (same signs) stay near the floor. The red points (different signs) get lifted upward by the interaction term . A flat plane in 3D neatly separates them.

20.6.3 SVM as a Similarity-Based Classifier

The key observation is in the dual prediction formula. Recall . Substitute into the prediction function:

For a new input , you compute its dot product with every support vector . Weight by , sum them up, and add the bias.

A dot product measures similarity. Parallel vectors give large positive values. Orthogonal vectors give zero. Opposite vectors give large negative values. SVM is fundamentally a similarity-based classifier: it compares your new point to the support vectors and votes based on which support vectors it most resembles. The sign of makes the final call — positive for class , negative for class .

The training objective (the dual) also depends only on dot products between data points: . At no point does the algorithm need individual coordinates — only pairwise similarities.

20.6.4 The Kernel Trick Intuition

Now the crucial problem: projecting all data into a high-dimensional feature space and then computing dot products there is computationally crushing. Suppose your data lives in dimensions and you want polynomial features up to degree 5. The number of expanded features is:

Computing explicit 96-million-dimensional vectors for every point and then taking dot products is not practical.

The kernel trick sidesteps this entirely. You define a kernel function that computes the dot product in the high-dimensional feature space directly from the original low-dimensional coordinates, without ever constructing :

In the prediction formula, you replace every dot product with the kernel:

In the dual training objective:

The kernel gives you the power of operating in a high-dimensional feature space while only paying the computational cost of operating in the original low-dimensional space. The data points never leave their original coordinates.

Why this works: The kernel function must correspond to a valid inner product in some (possibly infinite-dimensional) Hilbert space. This is guaranteed if the kernel is symmetric and positive semidefinite — the Gram matrix must be positive semidefinite for any set of points. This is Mercer's condition.

Visual intuition. Left panel: a 2D scatter of XOR data — two blue squares at opposite corners. Two red circles at the other corners. No straight line separates them. Middle panel: an arrow showing the feature map lifting the data into a 3D space. The red circles rise above the blue squares. Right panel: a flat semi-transparent plane in 3D cleanly separates the lifted points. Dotted lines project the 3D plane back to 2D — it becomes a curved hyperbola. Below the panels: "The decision boundary is a straight plane in the lifted space. It looks curved only because you are viewing its shadow in the original 2D."

Scope.

    The kernel trick works for any algorithm whose training and prediction depend only on dot products between data points. This includes kernel PCA, kernel ridge regression, and kernel k-means — not just SVM.Not every function of two vectors is a valid kernel. It must be a symmetric, positive semidefinite function satisfying Mercer's theorem. Linear, polynomial, RBF, and sigmoid (under certain parameters) kernels are valid.The kernel trick does not help if the data is linearly separable in the original space. — a linear kernel suffices. Kernels are for when linear separation fails.
Pitfalls.

    Kernel does not mean "automatically better." A poorly chosen kernel or badly tuned kernel parameter can give worse results than a linear SVM. Start with a linear kernel as a baseline.Confusing the kernel with the Gram matrix. The kernel function is the formula. The Gram matrix is the matrix whose entries are . You compute it once before solving the dual.Forgetting that the support vectors stay in the original space. You do not find support vectors in the high-dimensional feature space. The support vectors are still the original data points with . Only the similarity measure changes.
Recap. The dual SVM formulation depends only on dot products between data points. The kernel trick replaces every dot product with a kernel function that computes the dot product in a high-dimensional feature space without ever constructing that space. This lets SVM find non-linear decision boundaries in the original space by finding linear hyperplanes in an implicit high-dimensional space.

Bridge. The kernel trick is a beautiful idea, but which kernel should you use? The next two sections cover the two most important ones: the polynomial kernel (Section 20.7) and the RBF/Gaussian kernel (Section 20.8). — the latter being the workhorse kernel used in practice.

Real-world connection. The kernel trick is one of the most influential ideas in machine learning. It decouples the learning algorithm from the data representation. The same SVM solver works with a linear kernel for text, a string kernel for DNA sequences. A graph kernel for molecular structures, and a pyramid match kernel for images — just swap the kernel function. Google's early ranking systems used kernel methods, and kernel-based Gaussian processes are standard in Bayesian optimization for hyperparameter tuning.

20.7 Polynomial Kernel

20.7.1 Polynomial Feature Explosion

Hook. You want to fit a curved decision boundary. The obvious approach: create polynomial features (, , , , , ...), then run a linear SVM on the expanded dataset. But watch out — the number of features explodes combinatorially. A 100-dimensional input with degree-5 polynomial features produces nearly 100 million features. That is impossible to store, let alone compute dot products on.

Intuition. Imagine you are writing out every monomial term like by hand for a 100-dimensional dataset. The number of unique monomials grows faster than your patience. But computing takes roughly 100 multiplications and one exponentiation. The polynomial kernel is a shortcut: it computes the dot product in the expanded space using only the original features. Bypassing the combinatorial explosion entirely.

Analogy — the expanded shopping cart. You go shopping with a list of 100 items (your original features). You want to consider all pairs of items that go well together (polynomial interactions up to degree 2). Writing out all pairs would take 5050 entries. But if someone gives you a magic formula that computes the "pairwise compatibility score" of two shopping carts using only the individual items. You get the same result without ever listing the pairs. The polynomial kernel is that magic formula.

20.7.2 The Polynomial Kernel Formula

For a -dimensional input and polynomial degree , the number of polynomial features up to degree is:

This counts all monomials like up to degree . For example, gives features: . For : features — nearly 100 million.

Derivation (stars and bars): How many monomials of exactly degree can you form from variables? A monomial is with . This is the classic "stars and bars" problem: arranging stars and bars. The count is . Summing over to gives .

The polynomial kernel avoids this explosion:

where is the polynomial degree and is an optional constant.

    : the pure polynomial kernel . This creates features of exactly degree (homogeneous polynomials).: the inhomogeneous kernel . This includes all lower-degree terms as well. For : . Which is exactly the dot product of with .
Note the coefficients in the feature map. These come from the multinomial expansion. The binomial coefficients appear inside the square root to ensure the dot product of the scaled features reproduces the kernel value exactly.

Worked comparison — polynomial kernel vs. explicit expansion. With 2D vectors . , the dot product is . Degree-5 polynomial kernel:

The explicit expansion would create features per point, requiring 21-component vectors and a 21-dimensional dot product. The kernel computes the result in one power operation.

Cost comparison. Kernel trick: 2 multiplications, 1 addition, 1 exponentiation. Explicit: 21 features per point 2 points = 42 feature computations, then 21 multiplications and 20 additions for the dot product. For , the gap becomes astronomical: one 100-dimensional dot product + power vs. ~96 million explicit features.

Q: How do you choose the polynomial degree?

A: There is no closed-form answer. Try degrees 2, 3, 4, 5 and use cross-validation to pick the one with lowest error. In practice. Most practitioners skip polynomial kernels entirely and go straight to the RBF kernel. — the RBF implicitly includes all polynomial degrees (up to infinity) and removes the need to guess. Tune gamma well and RBF handles almost any situation.

Scope.

    The polynomial kernel works well when the true decision boundary is approximately a low-degree polynomial surface. Image data and text data rarely satisfy this — RBF kernels are almost always better for those domains.The parameter (the additive constant) controls the influence of lower-order terms. Larger gives more weight to lower degrees. uses only homogeneous degree- terms.Polynomial kernels with high degree () can become numerically unstable. — kernel values can explode (large dot product raised to a high power). Normalize your data and consider using a moderate degree.
Visual intuition. A 2D scatter plot with a circular decision boundary separating an inner cluster (class +1) from an outer ring (class -1). Left panel: a linear kernel fails — no straight line can separate them. Middle panel: a degree-2 polynomial kernel finds a circular boundary. Right panel: a degree-3 polynomial kernel produces a more complex, wavy boundary that starts overfitting. Caption: "Higher polynomial degrees produce more flexible boundaries but risk overfitting."

Pitfalls.

    Numerical overflow. If is large (e.g., 100) and , the kernel value is . This overwhelms floating-point arithmetic. Always scale features to small ranges before using polynomial kernels.Odd-degree kernels with all-positive features. If all features are positive, an odd-degree polynomial kernel cannot separate data that requires sign changes. The polynomial will always be a monotonic function of the dot product.Choosing degree too high. Degree-10 or degree-20 kernels almost always overfit catastrophically. In practice, or use RBF instead.
Recap. The polynomial kernel computes the dot product in the space of all polynomial features up to degree using only the original dot product. — one number. It avoids computing the expanded features explicitly. The constant controls whether lower-degree terms are included, and the degree controls the flexibility of the decision boundary.

Bridge. The polynomial kernel solves the linear-separability problem for a wide class of curved boundaries. But it has a major limitation: you must choose the degree in advance. The RBF kernel (Section 20.8) eliminates this choice by giving the model access to all polynomial degrees. — up to infinity — in a single kernel function.

Real-world connection. Polynomial kernels are the kernel of choice when domain knowledge suggests polynomial structure — for example. In image retrieval using color histograms (bhattacharyya kernel is a special polynomial kernel). In natural language processing with bigram/trigram features, and in certain genomics applications where gene-gene interaction effects are known to be low-order. However, for general-purpose classification, polynomial kernels have been almost entirely superseded by RBF.

20.8 Radial Basis Function (RBF) Kernel

20.8.1 RBF Kernel Formula

Hook. What if you could give your SVM access to every polynomial degree — first. Second, third, all the way to infinity — in a single kernel? And you only have to tune one parameter? The RBF kernel does exactly that. It is the default kernel in every SVM library for good reason.

Intuition. The RBF kernel measures similarity by distance. Two points close together get a kernel value near 1. Two points far apart get a value near 0. It is like a "fuzzy indicator" of whether two points are neighbors. The parameter controls what counts as "close."

Analogy — the thermal camera. A thermal camera blurs heat signatures: nearby warm objects blend together in the image. Far objects stay sharply separate. The RBF kernel does the same for data points. A small blurs widely — even distant points look similar. A large sharpens — only points in the immediate neighborhood look alike. The kernel value is the "heat similarity" between two points, and gamma is the sensitivity knob.

The RBF (Radial Basis Function) kernel, also called the Gaussian kernel, is:

where:

    is the squared Euclidean distance between and is a scaling hyperparameter you choose is the exponential function
The exponential maps large distances to kernel values near zero and small distances to values near one. The kernel value is always in . When , the distance is zero and (maximum similarity).

20.8.2 Gamma as a Scaling Parameter

Gamma controls how fast similarity decays with distance. Expand the squared norm:

The first and third factors depend only on individual points — they are scaling factors. The middle term contains the dot product , which is where the similarity comparison actually happens. This connects the RBF kernel back to the linear kernel through the exponential of the dot product.

Effect of gamma:

    Large (e.g., ): Distance of 1 unit gives — nearly zero. Even nearby points are treated as dissimilar. Each support vector influences only its immediate neighborhood. The decision boundary is wiggly and highly localized — it can fit any shape, but it overfits noise.Small (e.g., ): Distance of 1 unit gives — still very high similarity. Points influence each other over long distances. The boundary is smooth and generalizes well.
Gamma is like in a Gaussian distribution. A large means a narrow Gaussian. — only very close points are "similar." A small means a wide Gaussian — distant points still share similarity.

20.8.3 RBF and Infinite Dimensions via Taylor Series

The real power of the RBF kernel is that it corresponds to an infinite-dimensional feature space. You can prove this with the Taylor series of the exponential.

Recall the Taylor series:

Set in the middle term of the RBF expansion:

Now here is the key insight: each term is itself the exact result of a degree- polynomial kernel. So the infinite sum is equivalent to using ALL polynomial kernels — degrees — simultaneously, weighted by the Taylor coefficients .

The full feature map for the RBF kernel is infinite-dimensional:

The factors at the front ensure the dot product exactly equals . The represents all degree-2 monomial terms, and the pattern continues for all degrees.

Why this matters: You do not need to decide whether your decision boundary is degree-2, degree-3, or degree-10. The RBF kernel grants the model access to all degrees simultaneously. The Taylor coefficients provide a natural weighting — they decay rapidly for large (since grows fast). So very high-degree features contribute less unless is large. Tuning adjusts how much influence each degree gets.

Q: When should I use polynomial kernel versus RBF kernel?

A: The RBF kernel is, in practice, a superset of the polynomial kernel. If polynomial features of any degree provide good separation, the RBF kernel can capture that and more — and usually performs better. Most practitioners go straight to RBF. The real tuning effort goes into picking a good value through cross-validation. Tune well, and RBF handles almost any situation.

Q: When we project to a higher dimension, how do we identify the support vectors there?

A: You never explicitly find support vectors in the high-dimensional space. The support vectors remain the same data points from the original low-dimensional space. — the indices with are the support vectors. The kernel trick computes what their dot products would be in the high-dimensional space without ever constructing that space. You try different kernels and gamma values and pick the one with the lowest classification error. The support vectors themselves do not change identity — only how their similarity to other points is computed changes.

Visual intuition. Two side-by-side plots. Left: RBF kernel with very small — the decision boundary is almost a straight line. The Gram matrix heatmap shows a smooth, broad band of high similarity along the diagonal. Right: RBF kernel with — the decision boundary wraps tightly around individual data points, creating complex isolated islands. The Gram matrix is nearly diagonal — each point is only similar to itself. Caption: "Small gamma = smooth, general boundary. Large gamma = wiggly, overfit boundary that treats each point as its own island."

Scope.

    The RBF kernel's feature space is infinite-dimensional, so there is no explicit weight vector you can inspect. You cannot say "feature 17 has weight 3.2" — the weights are implicitly encoded in the support vector coefficients.RBF kernels are stationary — they depend only on the distance , not on the absolute positions. This means the kernel cannot capture directional effects like "points in the right half of space behave differently."RBF kernels underperform on sparse, high-dimensional data (like bag-of-words text). Linear kernels often beat RBF on text because the data is already nearly linearly separable in the high-dimensional sparse space.
Pitfalls.

    Not tuning . The default in some libraries is a starting point, not an optimum. Always cross-validate over a logarithmic grid (e.g., ).Gamma and are coupled. When you increase (more complex boundary). You often need to decrease (stronger regularization) to prevent overfitting. Tune them together with a grid search.Large gamma + many support vectors = slow predictions. With a large gamma. Each support vector influences only a tiny region, so the model uses many support vectors to cover the space. Prediction time scales linearly with the number of support vectors.Forgetting to normalize features. The RBF kernel uses Euclidean distance, which is dominated by features with large scales. Standardize all features to zero mean and unit variance before using RBF.
Recap. The RBF kernel measures local similarity — close points get near-1 similarity. Far points get near-0 similarity. Its Taylor expansion reveals it is equivalent to a weighted infinite sum of polynomial kernels of every degree. Gamma controls the "reach" of each point: small gamma means broad influence and smooth boundaries; large gamma means narrow influence and complex. Overfit boundaries.

Bridge. The RBF kernel is the gold standard in practice. But kernels need data where distance is meaningful. — the XOR problem on a number line shows perfectly how a kernel can fail in 1D but succeed in higher dimensions. Section 20.9 walks through a complete worked example of the kernel trick in action on a simple 1D-to-2D mapping.

Real-world connection. RBF-kernel SVMs were the state-of-the-art for image classification before deep learning took over (2000-2012). They still dominate in low-data regimes — bioinformatics (protein classification with few hundred samples). Chemoinformatics (drug activity prediction), and anomaly detection (one-class SVM with RBF). They are also the default kernel in scikit-learn's `SVC` class. In finance, RBF-SVMs predict credit defaults and fraud from tabular data with few features but complex non-linear interactions.

20.9 Kernel Trick: Worked Example

20.9.1 Problem Setup — 1D Non-Separable Data

Hook. The kernel trick sounds abstract until you see it in action. Here is the simplest possible non-separable dataset — three points on a 1D line. — and a feature map that makes them linearly separable in 2D. Every step is spelled out.

Problem. You have three points in one dimension:

PointCoordinateLabel
(positive)
(negative)
(positive)
On the number line, the negative point at is sandwiched between two positive points at and . No single threshold can separate them. Any cut at a threshold places both positive points on one side. The negative point ends up on the other side only if one positive point is on the wrong side. For example, cut at : positive at is below (wrong). Positive at 1 is above (correct), negative at 0 is above (wrong). The data is fundamentally not linearly separable in 1D.

20.9.2 Feature Mapping to 2D

Define the feature map . This lifts each 1D point into a 2D point:

Original Label
In the new 2D space, the two positive points both sit at height — one at . One at . The negative point sits at the origin . A horizontal line at cleanly separates the positive points (above the line) from the negative point (below the line). The data is now linearly separable.

Why ? The squared term folds the number line into a parabola. Points at and both map to the same value of because squaring loses the sign. The negative point at maps to . The sign-based distinction (both and are positive class) becomes a height-based distinction in 2D.

20.9.3 Formulating Hard Margin SVM in the New Space

The transformed points are 2D, so the hyperplane equation is:

The hard margin primal becomes:

subject to the constraints for each transformed point.

For with :

For with :

For with :

Look at the structure. The first two constraints together require (adding them: implies ). The third constraint pins . Since is unconstrained by sign, you can satisfy these — for instance, and works:

So , , is a feasible solution. Giving the hyperplane , or . This is exactly the horizontal line we identified geometrically. The margin is .

This is now a standard hard margin SVM in 2D. You can solve it using the same method as Section 20.3. The key takeaway: the feature map turned a 1D non-separable problem into a 2D separable one. The kernel trick would let you do this without ever computing — but for this simple case. Explicit mapping is easy to understand and verify.

Visual intuition. Three panels. Left panel: a horizontal number line with points at (blue, +1), (red, -1), and (blue, +1). A vertical dashed line attempts to separate them — no position works. Middle panel: an arrow labeled showing the mapping from the 1D line to a 2D coordinate system. Right panel: the plane with and as blue points at the top, and as a red point at the bottom. A solid horizontal line at cleanly separates them. The dashed line projects the 2D boundary back to the original 1D line. — it becomes two points marking where the decision boundary crosses the parabola's projection.

Scope.

    The feature map was chosen because we know the problem structure (positives at , negative at 0). In general, you do not know the right mapping in advance. That is why you use kernels like RBF that implicitly try an infinite family of mappings.This explicit mapping approach (compute . Then run linear SVM) works for low-dimensional feature maps, but it defeats the purpose of the kernel trick. Real kernelized SVMs replace with directly in the dual — no explicit mapping step.
Pitfalls.

    Choosing the wrong mapping. If you used instead. The positive points would map to and — one above, one below — destroying the linear separability. The feature map must be chosen to match the data structure.Forgetting the bias. Even in the transformed space, you still need a bias in the hyperplane equation. Without it, the decision boundary would be forced through the origin of the feature space, which may not separate the data.
Recap. Three 1D points are not linearly separable on a line. The feature map lifts them to 2D: . In 2D. The positives sit at height 1 and the negative at height 0 — a horizontal line at separates them. The SVM primal in the transformed space produces this line as the maximum-margin solution.

Bridge. This section showed a concrete feature map worked by hand. In practice, you rarely know the right map. The RBF kernel (Section 20.8) avoids this choice by implicitly using an infinite-dimensional feature space. Section 20.10 rounds out the lecture with exam-oriented practice problems that test your ability to solve SVM problems of each type.

Real-world connection. The "1D non-separable to 2D separable via squaring" pattern appears in real problems too. In signal processing. Audio features at frequencies and Hz may belong to the same class (symmetric harmonics) while the midpoint Hz belongs to the other. — exactly the same structure after centering. A quadratic kernel or RBF kernel handles this naturally without manual feature engineering.

20.10 Practice Problem Types

20.10.1 Problem Types to Expect

Hook. You have seen the theory, the derivations, and a worked example. Now: what kind of problems will actually appear on the exam? Here is the complete list of SVM problem types you should be able to solve, organized by what they test.

Several distinct problem types appear regularly. Practice each one — the patterns repeat:

1. Primal formulation problems. You are given a small dataset (typically 3-4 points in 2D) and a value for . Your task: write out the full soft-margin primal optimization problem.

Example structure:

    Objective: Constraint per point: Non-negativity: for all
This tests whether you can mechanically translate labeled data points into the standard SVM form. The constraints must be written explicitly — for each point, plug in its coordinates and label.

2. Hinge loss calculation. Given a weight vector, bias, data point, and label, compute the loss.

Three-step recipe:

    Compute (the raw linear output)Compute (the label-signed score)Compute
You may be asked to do this for multiple points and sum the losses. Remember: if , the loss is zero regardless of how large is.

3. Support vector identification. Given a trained SVM (you have , , and the data points with labels). Determine which points are support vectors.

    Hard margin: check if (exactly on margin boundary). If it equals 1, the point is a support vector. If it is greater than 1, it is not.Soft margin: a point is a support vector if (inside or on margin). Points with score less than 1 but on the correct side have and are still support vectors. Misclassified points (score negative) are also support vectors.
4. Margin calculation. The margin is . Compute and then divide 2 by it. Example: gives and margin .

5. Hard margin SVM with 2 points. Like the worked example in Section 20.3. With exactly two points of opposite class, you have three unknowns () and three equations. The solution path is always the same:

    Write margin conditions , Replace with in both equationsUse as the third equationCompute dot products, solve the linear system, and recover and
6. Kernel mapping problems. Given a feature mapping like , transform each data point into the new coordinates. Then formulate the hard-margin SVM in the new space. Write the primal or dual with the transformed points. This tests your ability to apply the kernel idea explicitly before seeing the implicit kernel trick.

20.10.2 Student Questions on Problem Types

Q: In exams, how many variables or data points will SVM problems have?

A: For finding the full linear hyperplane (solving for , . And ), you will typically get two data points — that makes the system solvable with three equations. You may also see problems with three or four points. In those, you are asked to write the primal formulation or identify which points are support vectors. You are not asked to solve the full optimization.

Q: Does the hard margin SVM always produce the perpendicular bisector for two opposite-class points?

A: Yes. With exactly two points of opposite classes, the maximum-margin hyperplane is always the perpendicular bisector of the segment joining them. The SVM math (the three-equation system) recovers this geometry exactly — a good sanity check after you solve. If your answer does not give the perpendicular bisector, you made an algebra mistake.

Pitfalls for exam problems.

    Mixing up the margin formula. The margin is , not . The factor of 2 comes from the two margin boundaries at . You lose a mark every time this is wrong.Forgetting the in the objective. The primal minimizes , not . If you write the objective without the . Your derivative will be off by a factor of 2, and your dual will not match.Writing the constraint wrong. The primal constraint is . Not . The inequality is crucial — points must be at least one unit away, not exactly one unit.Skipping the constraint. In soft margin. You need both AND . Forgetting the non-negativity is a common mistake.KKT sign errors. For equality constraints in a minimization problem, the Lagrangian term is . In a maximization problem, it is . The sign flips depending on whether you minimize or maximize. Many students get this wrong. For the SVM primal (minimization), the Lagrangian subtracts the constraints — see Section 20.1.3.
Exam priority order for SVM:

    Two-point hard margin solution (Section 20.3) — most likely full-credit problemSoft margin primal formulation from data points — tests structural understandingHinge loss computation — quick calculation, easy marksSupport vector identification / margin calculation — tests interpretationKernel mapping — given , transform and set up SVM

Exam Guidance Summary

The post-midterm material (lectures 9 through 16, covering modules M5, M6, M7) receives roughly 70-80% of the marks. The remaining 20-30% comes from pre-midterm topics (lectures 1 through 8).

Post-midterm core areas. Three major problem domains drive the exam:

    Gradient descent — RMSProp, momentum variants, convergence behaviorSVM — hard margin (2-point problems), soft margin primal formulation, hinge loss, support vector identification, margin computation, kernel trickPCA — principal component derivation, eigenvalue problems, variance explained
Exam problems typically combine two of these three areas. You may see gradient descent + PCA, or SVM + PCA. All three are unlikely to appear in a single exam.

SVM-specific exam notes:

    Hard margin 2-point problem: Expect a problem with two data points — solve for , , , and the decision boundary. Show every intermediate step. This is the most predictable SVM question. The solution always recovers the perpendicular bisector — use that fact to check your answer.Soft margin primal formulation: Given 3-4 points and a value for , write the full optimization problem with all constraints. Every point gets its own constraint and its own . Do not forget .Hinge loss: Be able to compute it for any given , , and data point. Three steps: dot product, multiply by label, .Margin formula: — know it without thinking. Also know that maximizing margin is equivalent to minimizing or .Kernel trick: Given a feature mapping , transform points and set up the SVM in the new space. Understand that implicit kernels compute the result without explicit mapping — the dual form reveals why.
Pre-midterm topics that matter for SVM context:

    Rank of a matrix — problems on rank appear in nearly every exam. The Gram matrix must be full rank for the SVM dual to have a unique solution.Hessian matrix — second derivative structure and positive definiteness. The SVM objective has Hessian (identity), which is positive definite — guaranteeing convexity and a unique minimum.Partial derivatives and the chain rule — used throughout the Lagrangian derivation. Know how to differentiate to get .Vector spaces — proving whether a set is a vector space. The dual variables live in with the linear constraint , forming an affine subspace.Taylor series — the expansion is required knowledge. And it connects directly to the RBF kernel's infinite-dimensional feature space interpretation (Section 20.8.3).
General exam advice:

    Work through every problem in the practice document — they mirror the type and difficulty of exam questions exactly.Show all work in a clear, step-by-step manner. Write assumptions explicitly. Partial credit is awarded generously when the reasoning is visible.For constrained optimization, know when to use KKT conditions. For equality constraints in a minimization problem, the Lagrangian term is . In a maximization problem, it becomes . The sign convention flips depending on the optimization direction.Check your answer dimensionally. Does have the right number of components? Is the bias a scalar? Does give a value near 1 for the support vectors you identified?The perpendicular bisector check: if your 2-point SVM solution does not produce the line perpendicular to the segment connecting the points and passing through its midpoint. Something went wrong. Re-check your algebra.

Key Industry Applications

SVM with RBF kernel as the standard baseline. SVM with the RBF kernel is a reliable. Well-understood classifier for tabular data, text classification, and bioinformatics. You tune exactly one hyperparameter — gamma — and get competitive results without the architecture search that neural networks demand. In credit scoring, SVMs classify loan applicants as low-risk or high-risk from structured financial features. In bioinformatics, SVMs with custom string kernels classify protein sequences into structural families. In spam detection, linear SVMs on bag-of-words features still achieve >99% accuracy on clean datasets.

The kernel trick beyond SVM. The kernel trick — replacing dot products with kernel evaluations. — applies to any algorithm whose computation depends only on pairwise similarities. This gives rise to:

    Kernel PCA: non-linear dimensionality reduction for visualizing high-dimensional dataKernel ridge regression: non-linear regression with L2 regularizationKernel k-means: non-linear clustering that can separate concentric ringsKernel canonical correlation analysis (CCA): finding non-linear relationships between two datasets
The same mathematical insight (Mercer's theorem guarantees that any positive semidefinite function corresponds to a dot product in some Hilbert space) unifies all these methods. If you understand the SVM dual and the kernel trick, you understand a design pattern that recurs across machine learning.

The combinatorial cost of explicit feature expansion. The formula for polynomial feature count is the reason feature engineering pipelines fail on high-dimensional data. A 100-feature dataset with degree-3 interactions generates ~176,851 features — more than the number of training examples in most tabular datasets. This "curse of dimensionality" in feature space is exactly what kernels avoid. The same combinatorial explosion affects polynomial regression, interaction-term models in statistics, and any explicit basis-function expansion. Recognizing this limit is essential for practical machine learning. — it tells you when to reach for kernels or deep learning instead of manual feature creation.

Hinge loss as a general-purpose classification loss. The hinge loss appears beyond SVM:

    Structured SVMs use hinge loss for predicting sequences, trees, and graphsRanking SVMs minimize hinge loss over pairwise preferences (document A should rank above document B)Maximum-margin neural networks combine hinge loss with neural architectures. Especially in few-shot learning and metric learning where the margin itself is the quantity of interest
The property that makes hinge loss special is the zero-loss zone for . Points that are "comfortably correct" generate no gradient signal and do not influence the optimizer. This sparsity is why SVM generalizes well — it actively ignores the majority of the data that is already well-classified. Compare this to cross-entropy loss (used in logistic regression and neural networks), which always produces non-zero gradients even for correctly classified points. — driving probabilities toward 0 or 1 but never being satisfied.

When to use SVM (and when not to). SVMs are the right choice when:

    Your dataset is small to medium (~100 to ~10,000 examples). Training time scales as to with the number of training examples.Your features are moderately dimensional and you do not have deep domain knowledge about feature interactions. — the RBF kernel handles non-linear relationships automatically.You need a deterministic. Reproducible baseline — SVMs with fixed random seeds and cross-validated hyperparameters produce identical results on reruns (unlike neural networks with random initialization).
SVMs are not ideal when:

    Your dataset has millions of examples — kernel methods become too slow. Use linear SVMs or logistic regression instead.Your data is raw pixels, audio waveforms, or text tokens — deep learning extracts hierarchical features that kernels cannot.You need probabilistic outputs (class membership probabilities) — SVM outputs raw scores that need Platt scaling to convert to probabilities. Adding an extra calibration step.

MFML Lecture 20 notes · Support Vector Machines

Mathematical Foundations for Machine Learning· postgraduate· 2026-07-11

Sections Breakdown

120.1 Hard Margin SVM — Review

20.1 Hard Margin SVM — Review

220.2 Support Vectors via Complementary Slackness

20.2 Support Vectors via Complementary Slackness

320.3 Hard Margin SVM: Worked Numerical Example

20.3 Hard Margin SVM: Worked Numerical Example

420.4 Soft Margin SVM

20.4 Soft Margin SVM

520.5 Hinge Loss

20.5 Hinge Loss

620.6 The Kernel Trick

20.6 The Kernel Trick

720.7 Polynomial Kernel

20.7 Polynomial Kernel

820.8 Radial Basis Function (RBF) Kernel

20.8 Radial Basis Function (RBF) Kernel

920.9 Kernel Trick: Worked Example

20.9 Kernel Trick: Worked Example

1020.10 Practice Problem Types

20.10 Practice Problem Types

11Exam Guidance Summary

Exam Guidance Summary

12Key Industry Applications

Key Industry Applications

Postgraduate students in Machine Learning

Exam Revision Notes

Below is the distilled, exam-ready core of this lecture. Every entry is built from the full textbook notes above. Use this section for rapid review — but if something doesn't make sense, go back to the full explanation in the main content.

Hard-Margin SVM

Must-know: SVM finds the hyperplane that separates the two classes with the widest possible margin. The margin equals ; maximizing it is the same as minimizing .

⚠️ Top pitfall: Writing the margin as instead of . The factor of 2 comes from the two boundaries at .

Self-check: Why does pinning the boundaries at not lose generality?

Connects to: Dual formulation, support vectors, soft margin.

Support Vectors & Complementary Slackness

Must-know: Complementary slackness forces only for points that sit exactly on the margin. Those are the support vectors; they alone build . All other points contribute nothing.

⚠️ Top pitfall: Assuming every point with is on the margin. In soft margin that is false — points inside or past the margin also have positive .

Self-check: If you delete a point far from the boundary, does the classifier change?

Connects to: Hard-margin SVM, the dual, sparsity, kernel trick.

Two-Point Worked Example

Must-know: With exactly two opposite-class points the max-margin line is the perpendicular bisector. Solve three equations: two margin conditions plus .

⚠️ Top pitfall: Forgetting to solve for the bias from the equations instead of assuming it is 1.

Self-check: Does your answer give the line perpendicular to the segment joining the two points, through its midpoint?

Connects to: Hard margin, support vectors, margin calculation.

Soft-Margin SVM

Must-know: Slack variables let points violate the margin at a cost . Large gives a narrow margin (overfitting); small gives a wide margin (better generalization).

⚠️ Top pitfall: Not normalizing features before tuning . is scale-sensitive, so the same behaves very differently after rescaling.

Self-check: What happens to the dual box constraint as ?

Connects to: Hinge loss, the dual, the hyperparameter.

Hinge Loss

Must-know: Eliminating the slacks gives the hinge loss , where is the label-signed score. It is zero for comfortably correct points and grows linearly otherwise.

⚠️ Top pitfall: Using the raw dot product as the score. You must multiply by the label first.

Self-check: For and , what is the hinge loss?

Connects to: Soft margin, regularization, support vector identification.

The Kernel Trick

Must-know: The dual depends only on dot products. So every can be replaced by a kernel that computes a high-dimensional inner product directly — no explicit mapping needed.

⚠️ Top pitfall: Thinking the kernel "auto-wins". A badly chosen kernel can do worse than a linear SVM; start with linear as a baseline.

Self-check: Which two properties must a kernel satisfy (Mercer's condition)?

Connects to: Polynomial kernel, RBF kernel, similarity-based prediction.

Polynomial Kernel

Must-know: computes the dot product of all polynomial features up to degree from a single number. Avoiding the feature explosion.

⚠️ Top pitfall: Choosing a degree too high. Degree-10 or 20 kernels almost always overfit; in practice most people skip straight to RBF.

Self-check: What does the constant control in the inhomogeneous polynomial kernel?

Connects to: Kernel trick, RBF kernel, feature explosion.

RBF (Gaussian) Kernel

Must-know: measures local similarity and is equivalent to an infinite sum of polynomial kernels (Taylor series). Small = smooth boundary; large = wiggly, overfit boundary.

⚠️ Top pitfall: Treating and as independent. Raising usually requires lowering to avoid overfitting; tune them together.

Self-check: Why does the RBF kernel correspond to an infinite-dimensional feature space?

Connects to: Kernel trick, polynomial kernel, gamma tuning.

Kernel Worked Example (1D → 2D)

Must-know: The map lifts three 1D points into a 2D space where a horizontal line at separates them — the maximum-margin solution.

⚠️ Top pitfall: Picking the wrong feature map. would scatter the positives to opposite sides and destroy separability.

Self-check: Why does squaring the number line fold and to the same height?

Connects to: Kernel trick, RBF, non-linear separability.

Exam Problem Types

Must-know: Expect: two-point hard-margin solutions, soft-margin primal formulation from data, hinge-loss computation, support-vector / margin identification, and kernel mapping. Show every algebra step.

⚠️ Top pitfall: Dropping the in the objective, or writing the constraint as an equality instead of .

Self-check: For two opposite-class points, what geometry must your answer always recover?

Connects to: Every concept in this lecture.

Was this lecture useful?

Loading comments…
🤖

BitsNotes AI Assistant

Subject Notes Assistant

Configure AI Chat

Choose how to access the chatbot
Have your own API key?

Switch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.

🔑 Enter API key above to fetch live models from provider, or enter model name manually.
OpenAI-Compatible API Support

Choose any provider preset (Gemini, DeepSeek, Kimi, GLM, MiniMax, Qwen, OpenAI, Groq, Ollama, etc.) or enter a custom endpoint URL.

Security & Privacy First

Your API key is sent directly from your browser to your specified provider. BitsNotes servers never store or see your key.