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.
“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.
- 1. Among separating lines, the hard-margin SVM chooses…
- 2. Support vectors are…
- 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:
- Encode labels as ±1 and (usually) standardise the features.
- 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.
- Among those, choose the smallest ‖w‖. Since the margin is 1/‖w‖, this maximises the margin.
- Solve the quadratic program (a QP solver, or the dual, D5.48).
- Predict sign(w·x + b). The support vectors are the points with value exactly 1.
- 1. Margin for w = (0.5, 0.5)?
- 2. Which point in the example is not a support vector?
- 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 indicesUse 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.
- 1. The hard-margin SVM objective is…
- 2. On non-separable data, the hard-margin problem is…
- 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.
- 1. The VC dimension of margin-γ separators in a radius-R ball is at most…
- 2. Leave-one-out error of a hard-margin SVM is at most…
- 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.
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
- V. N. Vapnik, A. Lerner (1963). “Pattern recognition using generalized portrait method.” Automation and Remote Control 24.
- B. E. Boser, I. M. Guyon, V. N. Vapnik (1992). “A training algorithm for optimal margin classifiers.” COLT.
- C. Cortes, V. Vapnik (1995). “Support-vector networks.” Machine Learning 20(3).
- V. N. Vapnik (1995). The Nature of Statistical Learning Theory. Springer.
- B. Schölkopf, A. J. Smola (2002). Learning with Kernels. MIT Press.