Foundations to Frontier
Tests
D. Classical Machine Learning › D5 Support Vector Machines and Kernel Methods

Hard-Margin SVM (Primal Derivation)

When two classes can be separated by a hyperplane, there are infinitely many separators. The hard-margin support vector machine picks the one with the largest margin, the widest empty corridor between the classes, by solving a convex quadratic program: minimise ½‖w‖² subject to yᵢ(w·xᵢ + b) ≥ 1. The solution is determined only by the few points on the corridor's edges, the support vectors, and wide margins come with generalisation guarantees. This page derives the primal problem from geometry, explains functional versus geometric margins and the canonical scaling, shows why the problem is convex with a unique solution, and discusses support vectors and margin-based bounds. In the exercises you solve the primal with a QP solver and verify its properties; then you compare the generalisation of the max-margin separator with other perfect separators as the training set grows.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Leave as much room as possible

If a straight line can separate satellites from debris in a radar-feature plot, many lines can. The perceptron stops at the first one it finds, which might pass very close to some points. The support vector machine picks the line with the widest empty corridor on both sides. A wide margin means small measurement errors or new points are less likely to land on the wrong side. Only the points touching the corridor matter; these are the support vectors.

Maximum margin: the widest empty road between the classes
your line: separates, margin 1.128 · SVM margin 1.414 · support vectors 3
Green: the maximum-margin separator and its corridor; orange: your line. The margin of a separating line is the distance to the closest training point. You cannot beat the SVM's margin; the best you can do is find its line. Moving any point that is not ringed (without crossing the corridor) does not change the SVM at all.
Why engineers care

“Keep the largest safety margin” is good engineering instinct, and the SVM makes it the training objective. It gives a unique, reproducible separator determined by a few critical cases, and it is the foundation of kernel methods (D5.49). These were among the most reliable classifiers for vision, text and sensing for two decades.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Among separating lines, the hard-margin SVM chooses…
  2. 2. Support vectors are…
  3. 3. In the demo, moving a non-ringed point inside its class region…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Margin by hand

The positive points are (1, 1), (2, 2) and (2, 0); the negative points are (−1, −1), (−2, 0) and (0, −2).

Try the separator w = (0.5, 0.5), b = 0, and compute yᵢ(w·xᵢ + b):

Point y w·x y(w·x + b)
(1, 1) + 1 1
(2, 2) + 2 2
(2, 0) + 1 1
(−1, −1) − −1 1
(−2, 0) − −1 1
(0, −2) − −1 1
  • Every constraint y(w·x + b) ≥ 1 holds. Five hold with equality: these are the support vectors. Only (2, 2) is inside its own region.
  • The geometric margin (distance from the boundary to the nearest point) is 1/‖w‖ = 1/0.707 = √2 ≈ 1.414.
  • The full corridor is 2/‖w‖ = 2√2 wide.

No other separating line has a wider margin: this is the hard-margin SVM.

The steps in plain English:

  1. Encode labels as ±1 and (usually) standardise the features.
  2. Look for w and b with yᵢ(w·xᵢ + b) ≥ 1 for every point. This fixes the scale so that the nearest points have value 1.
  3. Among those, choose the smallest ‖w‖. Since the margin is 1/‖w‖, this maximises the margin.
  4. Solve the quadratic program (a QP solver, or the dual, D5.48).
  5. Predict sign(w·x + b). The support vectors are the points with value exactly 1.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Margin for w = (0.5, 0.5)?
  2. 2. Which point in the example is not a support vector?
  3. 3. Minimising ‖w‖ with yᵢ(w·xᵢ + b) ≥ 1 maximises…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

The primal problem

Geometry. The signed distance from x to the hyperplane w·x + b = 0 is (w·x + b)/‖w‖.

The geometric margin of a separator is γ = minᵢ yᵢ(w·xᵢ + b)/‖w‖. Maximising γ is scale-invariant: (cw, cb) gives the same hyperplane. Fix the scale canonically by requiring minᵢ yᵢ(w·xᵢ + b) = 1. Then γ = 1/‖w‖, and maximising γ means minimising ‖w‖ (or ½‖w‖², which is smooth).

Hard-margin SVM (primal): minimise ½‖w‖² over w, b, subject to yᵢ(w·xᵢ + b) ≥ 1 for i = 1…n.

Properties:

  • It is a convex quadratic program: a strictly convex objective in w with linear constraints. So it has a unique optimal w (and b) when the data are separable, and no solution otherwise (the constraints are infeasible, which needs the soft margin, D5.47).
  • Support vectors: points with active constraints, yᵢ(w·xᵢ + b) = 1. Removing any other point leaves the solution unchanged (exercise 1).
  • Solvers: generic QP or SLSQP for small n; the dual (D5.48) and SMO (D5.50) for larger n.
from sklearn.svm import SVC
clf = SVC(kernel="linear", C=1e10).fit(X, y)          # huge C ≈ hard margin (on separable data)
clf.coef_, clf.intercept_, clf.support_                # w, b and support-vector indices

Use it on separable or nearly separable data with standardised features, and as the conceptual basis of soft-margin and kernel SVMs. Do not use the hard margin on noisy data: a single mislabelled point makes it infeasible, or forces a tiny margin.

🐍 Exercise 1: the hard-margin primal
Solve the hard-margin SVM primal with SLSQP, compute the geometric margin and support vectors; verify the hand example (w = (0.5, 0.5), margin √2), that removing the non-support vector leaves w unchanged, and that no random separating direction has a larger margin.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The hard-margin SVM objective is…
  2. 2. On non-separable data, the hard-margin problem is…
  3. 3. SVC.support_ returns…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Why a large margin generalises

Margin bounds.

  • For data in a ball of radius R separated with margin γ, the class of large-margin separators has VC dimension at most min(R²/γ², p) + 1 (Vapnik), independent of the input dimension when R/γ is small.
  • Equivalently, its Rademacher complexity scales like R/(γ√n) (D0, B2).
  • The perceptron’s mistake bound (R/γ)² (D2.21) is the online counterpart.

Leave-one-out bound. The leave-one-out error is at most (number of support vectors)/n, since removing a non-support vector changes nothing. Few support vectors mean good generalisation.

Exercise 2 evidence. At every sample size, the SVM’s training margin is more than twice the perceptron’s, and its test error is lower. For n = 100 it is 0.0000 against 0.0096.

Limits:

  • The margin is measured in the feature space you give it, so standardise the features.
  • One outlier near the other class can shrink the margin drastically, or make the problem infeasible. Hence the soft margin (D5.47).

Interview questions.

  • Why minimise ½‖w‖² instead of maximising 1/‖w‖? It is equivalent under the canonical constraints, and it gives a smooth convex QP with a unique solution.
  • What determines the SVM solution? Only the support vectors. Points strictly outside the margin have no influence.
📝 Quick check (Level 3)
0/3 answered
  1. 1. The VC dimension of margin-γ separators in a radius-R ball is at most…
  2. 2. Leave-one-out error of a hard-margin SVM is at most…
  3. 3. Why standardise features for an SVM?

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Do wider margins generalise better?

History.

  • Vapnik and Lerner (1963) introduced the “generalised portrait”, the optimal-margin hyperplane.
  • Vapnik and Chervonenkis (1964, 1974) developed the theory.
  • Boser, Guyon and Vapnik (1992) combined maximum margins with kernels.
  • Cortes and Vapnik (1995) introduced the soft margin.
  • Vapnik’s The Nature of Statistical Learning Theory (1995) made SVMs the dominant classifier until deep learning.

Exercise 1. The QP returns w = (0.5, 0.5), b = 0 and margin √2 = 1.414. Five points are support vectors. Deleting the sixth leaves w unchanged, and no random separating direction achieves a larger margin.

Exercise 2: four perfect separators. Setup: separable radar signatures in 5-D with a true gap; 15 repetitions; each cell shows training margin / test error.

n Hard-margin SVM Perceptron Averaged perceptron Midpoint of class means
10 0.747 / 0.107 0.278 / 0.133 0.242 / 0.146 −0.287 / 0.241
30 0.469 / 0.014 0.091 / 0.049 0.156 / 0.059 −0.619 / 0.171
100 0.341 / 0.000 0.083 / 0.010 0.161 / 0.004 −0.646 / 0.089
  • The max-margin separator has the lowest test error at every size. With 30 points its error is 3–4 times lower than either perceptron’s.
  • Perfect training accuracy is not enough. Every perceptron separator fits the training data, but its margin is narrow, so new points fall on the wrong side.
  • The midpoint rule does not even separate the training data (negative margin), because the classes are elongated along irrelevant directions.
🐍 Exercise 2 (research): does the margin predict generalisation?
Simulate separable radar signatures with a gap; for 10, 30 and 100 training points compare the hard-margin SVM, the perceptron, the averaged perceptron and the midpoint-of-means rule by training margin and test error.

Hard-margin SVMs in AI, robotics and aerospace

  • Safe separation: classifying clearly separable sensor states with maximal tolerance to measurement error.
  • Foundation for soft-margin and kernel SVMs used in vision and spectroscopy.
  • Margin thinking in neural networks: max-margin losses and large-margin training.
  • Interpretability: the support vectors are the critical, borderline cases worth reviewing.

References

  1. V. N. Vapnik, A. Lerner (1963). “Pattern recognition using generalized portrait method.” Automation and Remote Control 24.
  2. B. E. Boser, I. M. Guyon, V. N. Vapnik (1992). “A training algorithm for optimal margin classifiers.” COLT.
  3. C. Cortes, V. Vapnik (1995). “Support-vector networks.” Machine Learning 20(3).
  4. V. N. Vapnik (1995). The Nature of Statistical Learning Theory. Springer.
  5. B. Schölkopf, A. J. Smola (2002). Learning with Kernels. MIT Press.