Skip to main content

Updated Aug 15, 2026

Support Vector Machines

Logistic regression finds a separating line. Support vector machines find the separating line furthest from every training point — and it turns out only a handful of points (the "support vectors") actually determine where that line goes. The rest of the training set could be deleted without changing the model at all.

Key idea

Only the support vectors matter — the rest of the training set could be deleted without changing the model.

The maximum-margin idea​

Two linearly separable classes with a maximum-margin separator, its two margin lines, and three circled support vectors
The separator is placed to maximise the distance to the nearest point of either class. Only the three circled points — the support vectors, which sit exactly on the margin — determine it; deleting any other point changes nothing.

Among the infinitely many lines that separate two classes, SVM picks the one maximising the distance to the nearest point of either class — intuitively, the line with the most "breathing room," which tends to generalise better to new points near the boundary.

Functional vs. geometric margin​

The functional margin yi(w⊤xi+b)y_i(w^\top x_i + b) scales with ∥w∥\|w\|; the geometric margin yi(w⊤xi+b)∥w∥\frac{y_i(w^\top x_i + b)}{\|w\|} is scale-invariant — the actual perpendicular distance from the point to the boundary, which is what SVM actually maximises.

The hard-margin primal​

min⁡w,b12∥w∥2s.t.yi(w⊤xi+b)≥1  ∀i\min_{w,b} \frac{1}{2}\|w\|^2 \quad \text{s.t.} \quad y_i(w^\top x_i + b) \ge 1 \; \forall i

Minimising ∥w∥2\|w\|^2 is equivalent to maximising the margin 2∥w∥\frac{2}{\|w\|}; the constraint requires every point correctly classified with at least unit functional margin. This only has a solution when the classes are perfectly separable.

The soft margin and C​

Real data is rarely perfectly separable. The soft-margin formulation introduces slack variables ξi≥0\xi_i \ge 0 allowing some points to violate the margin (or even be misclassified), penalised by a cost CC:

min⁡w,b,ξ12∥w∥2+C∑iξis.t.yi(w⊤xi+b)≥1−ξi,  ξi≥0\min_{w,b,\xi} \frac{1}{2}\|w\|^2 + C\sum_i \xi_i \quad \text{s.t.} \quad y_i(w^\top x_i + b) \ge 1 - \xi_i, \; \xi_i \ge 0

Hinge loss as the unconstrained view​

The soft-margin problem is equivalent to minimising hinge loss (from Loss Functions) plus an L2 penalty:

min⁡w,b12∥w∥2+C∑imax⁡(0,1−yi(w⊤xi+b))\min_{w,b} \frac{1}{2}\|w\|^2 + C\sum_i \max(0, 1 - y_i(w^\top x_i + b))
SymbolMeaning
w,bw, bthe separating hyperplane's normal vector and offset
ξi\xi_islack allowing point ii to violate the margin
CCcost of margin violations — the bias/variance dial
αi\alpha_ithe dual's Lagrange multipliers, one per training point

The dual formulation​

Lagrangian duality rewrites the problem entirely in terms of dot products between training points and a set of multipliers αi≥0\alpha_i \ge 0 (one per point). This matters because: (1) points with αi=0\alpha_i = 0 never influence the boundary at all — only points with αi>0\alpha_i > 0 (the support vectors) do; (2) the dual depends on data only through pairwise dot products, which is exactly the opening Kernel Methods needs to swap in a kernel and get a non-linear boundary for free.

Support vectors​

Points lying exactly on the margin, or violating it, are support vectors — everything else can be deleted from the training set post-training with zero effect on predictions.

SVM for regression (SVR)​

The same margin idea flipped: instead of separating classes, fit a function such that most points fall within an ϵ\epsilon-tube around it, penalising only points outside that tube.

Scaling requirements​

Like kNN, SVM's distance-based geometry requires standardised features — an unscaled feature with a large numeric range will dominate the margin computation.

C as the bias/variance dial​

Large CC penalises margin violations heavily — a narrow margin that fits training data tightly (low bias, high variance, risk of overfitting). Small CC tolerates more violations for a wider margin (higher bias, lower variance).

Code: LinearSVC, margins plotted, a C sweep​

svm_demo.py
import numpy as np
import matplotlib.pyplot as plt
from sklearn.svm import LinearSVC
from sklearn.datasets import make_blobs

X, y = make_blobs(n_samples=100, centers=2, cluster_std=1.2, random_state=6)

fig, axes = plt.subplots(1, 3, figsize=(15, 4))
for ax, C in zip(axes, [0.01, 1, 100]):
model = LinearSVC(C=C, max_iter=10000).fit(X, y)
w, b = model.coef_[0], model.intercept_[0]

xx = np.linspace(X[:, 0].min(), X[:, 0].max(), 100)
yy = -(w[0] * xx + b) / w[1]
margin = 1 / np.linalg.norm(w)
yy_up = yy + margin * np.sqrt(1 + (w[0]/w[1])**2)
yy_down = yy - margin * np.sqrt(1 + (w[0]/w[1])**2)

ax.scatter(X[:, 0], X[:, 1], c=y, edgecolors="k")
ax.plot(xx, yy, "k-")
ax.plot(xx, yy_up, "k--"); ax.plot(xx, yy_down, "k--")
ax.set_title(f"C={C}, margin width={2*margin:.2f}")
plt.savefig("svm_margins.png")

As CC grows from 0.01 to 100, the plotted margin width should visibly shrink — the model tightens its boundary around the training points instead of maximising breathing room.

When to reach for this​

Data sizesmall-to-medium (kernel SVMs scale poorly past tens of thousands of points)
Feature countworks well even when d>nd > n
Interpretabilitylinear SVM: moderate; kernel SVM: low
Training costquadratic-to-cubic in nn for kernel SVMs
Inference costproportional to number of support vectors

See also​

  • Kernel Methods — extending this to non-linear boundaries via the dual's dot-product structure.
  • Loss Functions — hinge loss, the unconstrained equivalent of the soft margin.