Support Vector Machines
Support Vector Machines (SVMs) are supervised learning models that find the optimal separating hyperplane between classes by maximizing the geometric margin between the decision boundary and the nearest training points — called support vectors. They matter in modern AI as gold-standard baselines for tabular and text classification tasks, and as theoretical cornerstones of statistical learning theory that inform generalization bounds across all of ML. The counterintuitive fact: SVMs often generalize better with fewer training points than competitors, because only the support vectors — sometimes just 3–5 points — determine the entire decision boundary.
The aha moment for SVMs is that finding the best separating boundary is not about fitting all the data — it is about finding the boundary that is maximally far from the points closest to it on each side. Instead of minimizing training error, SVMs maximize a geometric margin, trading off fit against confidence. This makes the solution robust: move most training points around and the boundary does not change; only move a support vector and it shifts. The entire complexity of the model collapses into a sparse set of the hardest, most boundary-defining examples.
Practitioners frequently assume the kernel trick "transforms data into a higher-dimensional space and then runs a linear SVM there" — implying an explicit, expensive feature map is computed. This is wrong. The kernel function computes only the inner product in that high-dimensional (even infinite-dimensional) space directly from the original inputs, never materializing the transformed vectors. The correct mental model: the kernel is a similarity function that secretly measures angles in a richer geometry, and the SVM optimization never needs the coordinates in that space — only pairwise similarities. Confusing these leads engineers to unnecessarily pre-compute explicit feature maps (e.g., via random Fourier features) in settings where the exact kernel is affordable.
How It Works
The Hard-Margin Formulation
Assume data with and that is linearly separable. A separating hyperplane is defined by weight vector and bias such that . The signed distance from point to this hyperplane is . Maximizing the minimum such distance over all points — the margin — yields:
Explanation: Minimizing the squared norm of <strong>w</strong> while enforcing that every point lies at least one canonical unit from the boundary is exactly equivalent to maximizing the geometric margin . Here is the squared Euclidean norm of the weight vector; the factor is a convenient scaling that simplifies gradient expressions; the constraint places the positive class above and the negative class below in the canonical parameterization.
The Dual Problem and Lagrangian
Introducing Lagrange multipliers for each constraint and applying the KKT conditions converts equation [1] into its Lagrangian dual:
Explanation: The dual objective depends on training data only through pairwise inner products , which is the algebraic foothold that makes the kernel trick possible. Here are the dual variables; by complementary slackness, only for the support vectors (points on the margin boundary), making the solution sparse. The recovered primal solution is .
The Soft-Margin Extension
Real data is rarely separable. The soft-margin SVM introduces slack variables that allow points to violate the margin, penalized by hyperparameter :
Explanation: The regularization–loss tradeoff is made explicit: large tolerates almost no violations (high variance, low bias), while small allows many violations in exchange for a wider, more robust margin. measures how far point has penetrated the margin or crossed the boundary; is the single most important hyperparameter governing bias-variance tradeoff in practice.
The Hinge Loss Equivalence
Equation [3] can be rewritten as unconstrained empirical risk minimization, revealing the connection to loss functions familiar from PyTorch:
Explanation: The hinge loss is zero when a point is correctly classified beyond the margin and grows linearly as a point moves toward or past the wrong side — making SVMs robust to outliers compared to squared loss. This form is directly optimizable with subgradient methods or via PyTorch's `torch.nn.HingeEmbeddingLoss` or a manual implementation: ```python import torch def svm_loss(scores, labels, C=1.0): """ scores: (n,) raw dot-product outputs w^T x + b labels: (n,) in {-1, +1} """ hinge = torch.clamp(1.0 - labels scores, min=0.0) w_norm_sq = ... # pass in separately or track via nn.Linear weight return 0.5 w_norm_sq + C * hinge.mean() ```
The Kernel Trick
Replace every inner product in equation [2] with a kernel function , where maps inputs to a (possibly infinite-dimensional) Hilbert space . The prediction function then becomes:
Explanation: The prediction for a new point is a signed weighted sum of its similarities (under the kernel) to only the support vectors — the full training set never needs to be visited at inference. Common kernels and their PyTorch-friendly implementations: ```python import torch def rbf_kernel(X, Z, gamma=1.0):
# X: (n, d), Z: (m, d) → K: (n, m) diff = X.unsqueeze(1) - Z.unsqueeze(0) # (n, m, d) return torch.exp(-gamma * (diff2).sum(-1)) def polynomial_kernel(X, Z, degree=3, coef0=1.0): return (X @ Z.T + coef0) degree def linear_kernel(X, Z): return X @ Z.T ```
Vapnik was trained as a mathematician in the Soviet Union and worked at the Institute of Control Sciences in Moscow before emigrating to AT&T Bell Labs in 1990. He developed the theoretical foundations of SVMs through the 1960s–1990s, culminating in the soft-margin formulation with Corinna Cortes in 1995 and establishing the VC-dimension framework that gives SVMs their generalization guarantees. A surprising fact: Vapnik developed much of the foundational theory for SVMs in Russian in the 1960s and 1970s, but it remained largely unknown in the West until he could publish in English after emigrating.
Cortes holds a PhD in computer science from the University of Rochester and became head of Google Research New York. Her landmark 1995 paper with Vapnik, "Support-Vector Networks," introduced the slack variable formulation (equation [3]) that made SVMs practical on real, noisy data — the version virtually every practitioner uses today. Cortes was also an early pioneer of weighted SVMs for imbalanced classification, a contribution often overshadowed by the headline SVM result.
Intuition
Imagine you are a referee asked to draw a line separating two groups of players standing on a field — blue players on one side, amber on the other. A bad referee draws the line just barely separating them, hugging the nearest players as tightly as possible. A good referee walks to the exact middle of the "no man's land" between the two nearest players from each team, then draws the widest possible lane between them. The SVM is that wise referee: it finds the widest possible lane — the margin — so that even if players drift a little before the next game, they are still on the right side. Now imagine the players are arranged in a circle (one group inside, one outside) — no straight line can separate them. The kernel trick is like handing the referee a magic camera that photographs the field from the side: suddenly the inner circle lifts up in 3D above the outer ring, and a flat horizontal plane easily separates them. The referee still draws a flat plane; they just work in the transformed photograph, and the kernel function computes exactly the right photograph without anyone physically moving the players. The support vectors are the players closest to the lane boundaries — the ones who "matter." Trade or move any other player and the lane stays exactly where it is. This sparsity is what makes SVMs elegant, interpretable, and often surprisingly accurate on small datasets where deep networks would overfit.
Historical Development
Why It Matters
Prerequisites
What This Leads To
See Also
Logistic Regression · Kernel Methods · Gaussian Processes · Regularization · Quadratic Programming