Skip to content
intermediate

Support Vector Machines: Derive the Maximum-Margin Classifier

Most explanations of support vector machines stop at the picture: two clouds of points, a line between them, a gap on either side. That picture is correct,…

Published 2026-10-02Updated 2026-10-0412 min read
Clear blue water of sea with ripples and wavy surface under bright blue sky
Clear blue water of sea with ripples and wavy surface under bright blue sky. Photo by Elle Hughes on Pexels.

Most explanations of support vector machines stop at the picture: two clouds of points, a line between them, a gap on either side. That picture is correct, and it is also useless the moment you need to know why changing one number flips a boundary, why only a handful of training points matter, or why unscaled features quietly wreck the result. The picture describes the answer. It does not describe the problem.

This article writes the problem down. We will build the maximum-margin classifier from a raw geometric goal into a constrained optimization objective, then relax it so it survives real, overlapping data. By the end you should be able to read any SVM formulation and name three things: its objective, its constraints, and its price of violation.

If margins, support vectors, and kernels are still fuzzy, the intuition-level treatment of margins and kernels is the right place to start. Here we assume you know what a margin looks like and want the mathematics behind it.

Notation and the Geometry We Are Optimizing

Fix the symbols first, because every later equation depends on them.

We have a dataset of nn samples. Each input is a vector xi∈Rdx_i \in \mathbb{R}^d, and each label is yi∈{−1,+1}y_i \in \{-1, +1\}. The two-class encoding matters: using −1-1 and +1+1 instead of 00 and 11 lets a single expression handle both classes.

A linear classifier is a hyperplane:

wTx+b=0w^T x + b = 0

Here w∈Rdw \in \mathbb{R}^d is the normal vector — it points perpendicular to the hyperplane and sets its orientation. The scalar bb is the bias, which shifts the hyperplane away from the origin.

The quantity wTxi+bw^T x_i + b is a signed score. Its sign tells you which side of the hyperplane the point falls on, and its magnitude grows with distance from the boundary. To convert that score into an actual distance, divide by the length of the normal vector:

signed distance=wTxi+b∥w∥\text{signed distance} = \frac{w^T x_i + b}{\|w\|}

The sign still encodes the predicted side. Multiply by the true label yiy_i, and you get a quantity that is positive when the point is correctly classified and negative when it is not:

yi(wTxi+b)y_i(w^T x_i + b)

This is the functional margin for a single point. It is positive on the correct side, and its size depends on the scale of ww and bb.

That last clause is the hinge the whole derivation turns on. Multiply ww and bb by any positive scalar and you get the same hyperplane — same orientation, same position, same predictions. The boundary is scale-invariant. The functional margin is not. This mismatch is not a bug to work around; it is the freedom we will spend to make the problem clean.

Knowledge check

Check your understanding

Answer this question before you continue.

If both $w$ and $b$ are multiplied by the same positive scalar, which statement describes the result?
Misconception Check

Focus: Distinguish the scale-invariant decision boundary from the scale-dependent functional margin.

From "Widest Street" to a Constrained Objective

A two-dimensional scatter plot shows two classes separated by a solid decision line, with parallel dashed margin lines. One point from each class touches a margin line and is marked as a support vector; a farther point lies beyond its class's margin. A perpendicular arrow spans the gap and is labeled 2/||w||, while the support boundaries are labeled yᵢ(wᵀxᵢ+b)=1.
Fixing the closest points’ functional margin at 1 turns the geometric goal of widening the gap into the hard-margin objective of minimizing ||w||²/2.

Start from the raw goal, stated without symbols: find the hyperplane that correctly separates the two classes and sits as far as possible from the nearest point of either class.

Two requirements are tangled together here. First, every point must land on the correct side: yi(wTxi+b)>0y_i(w^T x_i + b) > 0 for all ii. Second, the distance from the hyperplane to the closest point — the geometric margin — must be as large as possible.

Written directly, that objective is awkward:

max⁡w,b1∥w∥min⁡i∣wTxi+b∣subject toyi(wTxi+b)≥0\max_{w, b} \frac{1}{\|w\|} \min_i \left| w^T x_i + b \right| \quad \text{subject to} \quad y_i(w^T x_i + b) \geq 0

A minimum nested inside a maximum, with an absolute value, is unpleasant to optimize. The scale-invariance rescues us.

Because scaling ww and bb does not change the hyperplane, we are free to choose the scale. So choose the convenient one: fix the functional margin of the closest points to exactly 11. Concretely, require

yi(wTxi+b)≥1for all iy_i(w^T x_i + b) \geq 1 \quad \text{for all } i

This single constraint does two jobs at once. It enforces correct classification, because the left side is positive. And it pins down the scale, because the closest points now sit at a functional margin of exactly 11.

With the scale fixed, the geometric margin has a clean value. The two margin boundaries sit at wTx+b=+1w^T x + b = +1 and wTx+b=−1w^T x + b = -1. The distance between them is

2∥w∥\frac{2}{\|w\|}

So maximizing the margin means maximizing 2/∥w∥2/\|w\|, which means minimizing ∥w∥\|w\|. Squaring and halving changes nothing about where the minimum sits, but it gives a friendlier derivative:

min⁡w,b12∥w∥2subject toyi(wTxi+b)≥1,i=1,…,n\min_{w, b} \frac{1}{2}\|w\|^2 \quad \text{subject to} \quad y_i(w^T x_i + b) \geq 1, \quad i = 1, \dots, n

This is the hard-margin primal problem. The objective is convex and quadratic; the constraints are linear. That combination buys something specific: when the data is linearly separable, the solution is unique. There is exactly one widest street, and this problem finds it.

Note: The jump from "maximize the margin" to "minimize ∥w∥\|w\|" is where most derivations lose people. The step is not a trick. It is the direct consequence of fixing the functional margin to 11 and then measuring the real distance with ∥w∥\|w\| in the denominator.

Knowledge check

Check your understanding

Answer this question before you continue.

Why does the hard-margin formulation minimize $\frac{1}{2}\|w\|^2$ subject to $y_i(w^T x_i+b)\geq 1$?
Single Choice

Focus: Explain why the hard-margin objective minimizes the squared norm under normalized classification constraints.

Why Only Some Points Matter: Support Vectors and KKT

The constraint set has nn inequalities, one per training point. You might expect all nn to influence the answer. They do not, and the reason is the structure of constrained optimization.

Attach a Lagrange multiplier αi≥0\alpha_i \geq 0 to each constraint and form the Lagrangian. Solving it produces a condition known as complementary slackness, one of the Karush-Kuhn-Tucker (KKT) conditions:

αi[yi(wTxi+b)−1]=0\alpha_i \left[ y_i(w^T x_i + b) - 1 \right] = 0

Read this literally. The product is zero, so at least one factor must be zero.

  • If a point sits strictly outside the margin, then yi(wTxi+b)>1y_i(w^T x_i + b) > 1, the bracket is positive, and therefore αi=0\alpha_i = 0.
  • If a point sits exactly on the margin, then yi(wTxi+b)=1y_i(w^T x_i + b) = 1, the bracket is zero, and αi\alpha_i is free to be positive.

Points with αi>0\alpha_i > 0 are the support vectors. They are the only points that appear in the final decision function, which is a weighted sum over them:

f(x)=sign(∑i∈SVαiyi xiTx+b)f(x) = \text{sign}\left( \sum_{i \in SV} \alpha_i y_i \, x_i^T x + b \right)

Everything else has been multiplied by zero and dropped.

A Three-Point Example

Take three points in two dimensions. Two sit exactly on the margin boundaries — one at wTx+b=+1w^T x + b = +1, one at wTx+b=−1w^T x + b = -1. The third sits far away on the correct side.

The two margin points have tight constraints, so their brackets are zero and their αi\alpha_i can be positive. The distant point has a loose constraint, so its bracket is positive and its αi\alpha_i must be zero. The decision boundary is defined entirely by the two margin points. Move the distant point anywhere on its side of the boundary and nothing changes. Move either margin point and the boundary shifts.

That is the formal reason SVMs are memory-efficient at prediction time: the model stores the support vectors, not the dataset.

Knowledge check

Check your understanding

Answer this question before you continue.

In the three-point example, what happens if the distant point is moved farther away while remaining on the correct side and outside the margin?
Scenario Interpretation

Focus: Use complementary slackness to predict which points can influence the hard-margin decision boundary.

The Dual Problem and Why It Sets Up Kernels

The primal problem is solvable, but its dual form exposes something more useful. Substituting the stationarity conditions back into the Lagrangian yields the dual objective:

max⁡α∑iαi−12∑i,jαiαjyiyj xiTxj\max_{\alpha} \sum_i \alpha_i - \frac{1}{2} \sum_{i,j} \alpha_i \alpha_j y_i y_j \, x_i^T x_j

subject to

∑iαiyi=0,αi≥0\sum_i \alpha_i y_i = 0, \qquad \alpha_i \geq 0

Look at where the data appears. Every input vector shows up only inside the inner product xiTxjx_i^T x_j. Nowhere else. Not as a coordinate, not as a feature, only as a pairwise similarity.

That structural fact is the precondition for the kernel trick. If the algorithm depends on the data only through inner products, you can replace the inner product with a kernel function:

xiTxj  ⟶  K(xi,xj)x_i^T x_j \;\longrightarrow\; K(x_i, x_j)

The kernel computes the inner product in some richer representation without ever materializing coordinates in that space. A polynomial kernel, a radial basis function kernel, and others each define a different geometry of decision surface.

Be precise about what this buys you. A kernel changes the representation and therefore the shape of the boundary the model can express. It does not guarantee better generalization. A kernel that matches the structure of your data can help substantially; a poorly matched one can hurt, and it adds hyperparameters you now have to tune. The kernel trick is a change of geometry, not a promise of accuracy.

Soft Margins: When the Data Refuses to Separate

The hard-margin problem assumes a separating hyperplane exists. Real data often refuses. When classes overlap, the constraint set has no feasible solution at all. When they barely separate, a single mislabeled point can drag the boundary into a bad position, because that point becomes a support vector and the margin must accommodate it.

The fix is to let points violate the margin, but charge them for it. Introduce slack variables ξi≥0\xi_i \geq 0, one per point, measuring how far that point violates the margin:

yi(wTxi+b)≥1−ξiy_i(w^T x_i + b) \geq 1 - \xi_i

A point with ξi=0\xi_i = 0 respects the margin. A point with 0<ξi<10 < \xi_i < 1 sits inside the margin but on the correct side. A point with ξi≥1\xi_i \geq 1 is misclassified. Now add the total violation to the objective, scaled by a parameter CC:

min⁡w,b,ξ12∥w∥2+C∑iξisubject toyi(wTxi+b)≥1−ξi,ξi≥0\min_{w, b, \xi} \frac{1}{2}\|w\|^2 + C \sum_i \xi_i \quad \text{subject to} \quad y_i(w^T x_i + b) \geq 1 - \xi_i, \quad \xi_i \geq 0

This is the soft-margin primal. The parameter CC is the price of violation.

  • Large CC punishes violations hard. The model pushes toward a narrow margin with few errors.
  • Small CC tolerates violations. The model widens the margin and accepts more points inside it.

In the dual, the only change is an upper bound on each multiplier: 0≤αi≤C0 \leq \alpha_i \leq C. That bound is worth pausing on. It caps how much influence any single training point can have on the boundary. Under the hard-margin problem, one outlier could pull with unlimited force. Under the soft-margin problem, its pull is capped at CC.

There is a second way to read the same objective. The soft-margin problem is equivalent to minimizing

12∥w∥2+C∑imax⁡(0,1−yi(wTxi+b))\frac{1}{2}\|w\|^2 + C \sum_i \max\left(0, 1 - y_i(w^T x_i + b)\right)

The term max⁡(0,1−z)\max(0, 1 - z) is the hinge loss. It is zero once a point is correctly classified and outside the margin, and it grows linearly as the point moves toward and past the boundary. This connects the SVM to the loss-function view you have already seen for other linear models: a data-fit term plus a regularization term, traded off by a single constant.

That constant is not derived from the data. CC is a hyperparameter, tuned by validation.

Knowledge check

Check your understanding

Answer this question before you continue.

Which description best matches the role of $C$ in the soft-margin objective?
Single Choice

Focus: Interpret slack variables and the penalty parameter in the soft-margin formulation.

What the Derivation Predicts About Real Behavior

The mathematics is not decoration. It predicts specific failure modes, and knowing them saves debugging time.

Feature scaling is not optional. The margin depends on ∥w∥\|w\| and on distances measured in feature space. If one feature ranges over thousands and another over fractions, the constraint set is dominated by the large-scale dimension. The model will effectively ignore the small one. This is a direct consequence of the geometry, not a quirk of any library. Standardize your features before fitting.

Outlier sensitivity depends on which margin you chose. Hard-margin SVMs are fragile: one point inside the margin can make the problem infeasible or distort the boundary badly. Soft-margin SVMs absorb that point through its slack variable and cap its influence at CC. If your data has noise or label errors — and it does — you want the soft-margin formulation.

The number of support vectors is a rough complexity signal. More support vectors means more points are pressing against the margin, which usually means a more complex boundary. Lowering CC tends to increase the support-vector count and widen the margin; raising it does the opposite. Watching that count as you tune CC gives you a readable signal of what the model is doing.

When the derivation says an SVM is a reasonable choice: moderate sample sizes, high-dimensional or sparse representations, and problems where a clear margin is plausible. The method was built for exactly those conditions.

When it is not: very large datasets, where the underlying quadratic program becomes the bottleneck, or problems where calibrated probabilities and direct coefficient interpretation matter more than the boundary itself. An SVM gives you a decision, not a probability, and its support-vector expansion is not a coefficient table you can read like linear regression.

Where to Take This Next

You now have the full chain: geometry to functional margin, functional margin to normalized constraint, constraint to primal objective, primal to dual, dual to kernels, and hard margin to soft margin with slack and CC.

The way to make it stick is to rebuild it from memory. Write the hard-margin primal on a blank page — objective, constraints, and the reason the constraint is normalized to 11. Then re-derive the soft-margin version by adding slack variables and the penalty term. If you can do both without looking, you understand the model rather than recognizing it.

Then run the check that turns theory into evidence. Fit a linear SVM on a small dataset, pull out the support vectors, and compare them against the KKT condition: which points have nonzero multipliers, and do they sit on or inside the margin? The points the solver hands back should match the ones the complementary slackness condition predicted. When they do, the derivation stops being algebra and becomes something you can see in the output.

Knowledge check

Final check

Finish the article by checking the ideas you just learned.

A learner replaces each dual inner product $x_i^T x_j$ with a kernel $K(x_i,x_j)$. Which conclusion follows from the article's derivation?
Question 1 of 2Comparison Reasoning

Focus: Explain how the dual's inner-product structure enables kernels and distinguish representational change from guaranteed accuracy gains.

A single mislabeled training point sits inside the otherwise broad separating gap. Which comparison is supported by the article?
Question 2 of 2Scenario Interpretation

Focus: Compare hard- and soft-margin behavior when a training example conflicts with an otherwise useful separating boundary.

References

  1. Support Vector Machinessee.stanford.edu
  2. 1.4. Support Vector Machines — scikit-learn 1.9.0 documentationscikit-learn.org
Practical resource

Build stronger machine learning foundations

Use structured resources to connect theory, scikit-learn workflows, and evaluation practice.

Browse resources
Related sites

Continue across the AI learning path

Use LearnPyFast for Python foundations and LearnLLMFast when you are ready to move from classical ML into LLM applications.

Python tutorialstutorial

LearnPyFast

Beginner-friendly Python tutorials, examples, and learning paths for practical programming foundations.

PythonProgrammingBeginners
Visit LearnPyFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related machine learning tutorials

Continue with nearby concepts, model families, evaluation methods, and practical workflows.