Support Vector Machines

Derivation of hard and soft margin SVMs from maximum-margin geometry, the dual formulation via Lagrangian optimization, KKT conditions, the kernel trick, and the representer theorem connecting SVMs to reproducing kernel Hilbert spaces.

Advanced

Table of Contents

  1. Learning Objectives
  2. Notation
  3. Core Intuition
  4. Hard-Margin SVM: Maximum Margin Classifier
  5. The Lagrangian Dual Problem
  6. KKT Conditions and Support Vectors
  7. Soft-Margin SVM
  8. The Kernel Trick
  9. Common Kernels
  10. The Representer Theorem
  11. Hinge Loss Interpretation
  12. Common Pitfalls
  13. Research Perspective
  14. Summary
  15. Exercises

Learning Objectives

  1. Derive the maximum-margin hyperplane for linearly separable data.
  2. Formulate the dual problem via Lagrange multipliers and interpret it geometrically.
  3. State and verify the KKT complementary slackness conditions.
  4. Extend to non-separable data via slack variables (soft-margin).
  5. Apply the kernel trick to obtain nonlinear decision boundaries without explicit feature maps.
  6. Connect hinge loss + L2 regularization to the SVM objective.

Notation

  • (xi,yi)i=1n(x_i, y_i)_{i=1}^n with yi{1,+1}y_i \in \{-1, +1\} — training data
  • wRd\mathbf{w} \in \mathbb{R}^d, bRb \in \mathbb{R} — weight vector and bias
  • γ=yi(wTxi+b)\gamma = y_i(\mathbf{w}^T\mathbf{x}_i + b) — functional margin
  • αi0\alpha_i \geq 0 — dual variables (Lagrange multipliers)
  • K(x,x)=ϕ(x),ϕ(x)K(\mathbf{x}, \mathbf{x}') = \langle\phi(\mathbf{x}), \phi(\mathbf{x}')\rangle — kernel function
  • ξi0\xi_i \geq 0 — slack variables
  • C>0C > 0 — misclassification penalty (inverse regularization)

Core Intuition

Among all hyperplanes that correctly classify the training data, the SVM selects the one with maximum margin — the largest distance to the nearest data point. This maximizes robustness to perturbations and, by VC-theory, yields favorable generalization bounds. The solution depends only on a few "support vectors" — the critical data points lying on the margin boundary.

Support Vector Machine

x₁
Angle°
-45
Offset
0.00
HyperplaneMarginSupport vector
Explore: SVM finds the maximum-margin separator. Only support vectors (gold ring) lie on the margin — moving other points does not change the boundary.

Hard-Margin SVM: Maximum Margin Classifier

For linearly separable data, we seek a hyperplane wTx+b=0\mathbf{w}^T\mathbf{x} + b = 0 such that:

yi(wTxi+b)1,i.(1)y_i(\mathbf{w}^T\mathbf{x}_i + b) \geq 1, \quad \forall i. \tag{1}

The geometric margin (distance from hyperplane to nearest point) is 2w\frac{2}{\lVert\mathbf{w}\rVert}. Maximizing the margin is equivalent to:

minw,b12w2subject toyi(wTxi+b)1,  i.(2)\min_{\mathbf{w}, b} \frac{1}{2}\lVert\mathbf{w}\rVert^2 \quad \text{subject to} \quad y_i(\mathbf{w}^T\mathbf{x}_i + b) \geq 1, \; \forall i. \tag{2}

This is a convex quadratic program (QP) with linear constraints.


The Lagrangian Dual Problem

Introduce multipliers αi0\alpha_i \geq 0:

L(w,b,α)=12w2i=1nαi[yi(wTxi+b)1].(3)\mathcal{L}(\mathbf{w}, b, \boldsymbol\alpha) = \frac{1}{2}\lVert\mathbf{w}\rVert^2 - \sum_{i=1}^n \alpha_i\bigl[y_i(\mathbf{w}^T\mathbf{x}_i + b) - 1\bigr]. \tag{3}

Setting L/w=0\partial\mathcal{L}/\partial\mathbf{w} = 0:

w=i=1nαiyixi.(4)\mathbf{w} = \sum_{i=1}^n \alpha_i y_i \mathbf{x}_i. \tag{4}

Setting L/b=0\partial\mathcal{L}/\partial b = 0:

i=1nαiyi=0.(5)\sum_{i=1}^n \alpha_i y_i = 0. \tag{5}

Substituting back into L\mathcal{L} yields the dual problem:

maxαi=1nαi12i,jαiαjyiyjxiTxj(6)\max_{\boldsymbol\alpha} \sum_{i=1}^n \alpha_i - \frac{1}{2}\sum_{i,j} \alpha_i\alpha_j y_i y_j \mathbf{x}_i^T\mathbf{x}_j \tag{6} subject toαi0,iαiyi=0.\text{subject to} \quad \alpha_i \geq 0, \quad \sum_i \alpha_i y_i = 0.

The dual depends on data only through inner products xiTxj\mathbf{x}_i^T\mathbf{x}_j — this is the entry point for kernelization.


KKT Conditions and Support Vectors

The KKT complementary slackness conditions state:

αi[yi(wTxi+b)1]=0,i.(7)\alpha_i\bigl[y_i(\mathbf{w}^T\mathbf{x}_i + b) - 1\bigr] = 0, \quad \forall i. \tag{7}

This means either αi=0\alpha_i = 0 (point is not a support vector, lies strictly beyond the margin) or yi(wTxi+b)=1y_i(\mathbf{w}^T\mathbf{x}_i + b) = 1 (point lies exactly on the margin — a support vector).

The solution w=iαiyixi\mathbf{w} = \sum_i \alpha_i y_i \mathbf{x}_i is a sparse linear combination of training points, with nonzero αi\alpha_i only for support vectors.


Soft-Margin SVM

For non-separable data, introduce slack variables ξi0\xi_i \geq 0:

minw,b,ξ12w2+Ci=1nξi(8)\min_{\mathbf{w}, b, \boldsymbol\xi} \frac{1}{2}\lVert\mathbf{w}\rVert^2 + C\sum_{i=1}^n \xi_i \tag{8} subject toyi(wTxi+b)1ξi,ξi0.\text{subject to} \quad y_i(\mathbf{w}^T\mathbf{x}_i + b) \geq 1 - \xi_i, \quad \xi_i \geq 0.

The dual becomes:

maxαiαi12i,jαiαjyiyjxiTxj(9)\max_{\boldsymbol\alpha} \sum_i \alpha_i - \frac{1}{2}\sum_{i,j}\alpha_i\alpha_j y_iy_j\mathbf{x}_i^T\mathbf{x}_j \tag{9} subject to0αiC,iαiyi=0.\text{subject to} \quad 0 \leq \alpha_i \leq C, \quad \sum_i\alpha_iy_i = 0.

The box constraint αiC\alpha_i \leq C is the only difference from the hard-margin dual.


The Kernel Trick

Replace inner products xiTxj\mathbf{x}_i^T\mathbf{x}_j with K(xi,xj)=ϕ(xi),ϕ(xj)K(\mathbf{x}_i, \mathbf{x}_j) = \langle\phi(\mathbf{x}_i), \phi(\mathbf{x}_j)\rangle where ϕ:XH\phi: \mathcal{X} \to \mathcal{H} maps to a (possibly infinite-dimensional) feature space:

maxαiαi12i,jαiαjyiyjK(xi,xj).(10)\max_{\boldsymbol\alpha} \sum_i \alpha_i - \frac{1}{2}\sum_{i,j}\alpha_i\alpha_j y_iy_j K(\mathbf{x}_i, \mathbf{x}_j). \tag{10}

The decision function becomes:

f(x)=i=1nαiyiK(xi,x)+b.(11)f(\mathbf{x}) = \sum_{i=1}^n \alpha_i y_i K(\mathbf{x}_i, \mathbf{x}) + b. \tag{11}

We never compute ϕ(x)\phi(\mathbf{x}) explicitly — only kernel evaluations.

Mercer's Theorem. KK is a valid kernel if and only if it is symmetric and positive semi-definite: i,jcicjK(xi,xj)0\sum_{i,j}c_ic_jK(\mathbf{x}_i,\mathbf{x}_j) \geq 0 for all {ci}\{c_i\} and {xi}\{\mathbf{x}_i\}.


Common Kernels

  • Linear: K(x,x)=xTxK(\mathbf{x}, \mathbf{x}') = \mathbf{x}^T\mathbf{x}'
  • Polynomial: K(x,x)=(xTx+c)pK(\mathbf{x}, \mathbf{x}') = (\mathbf{x}^T\mathbf{x}' + c)^p
  • RBF (Gaussian): K(x,x)=exp(γxx2)K(\mathbf{x}, \mathbf{x}') = \exp(-\gamma\lVert\mathbf{x} - \mathbf{x}'\rVert^2)
    • Corresponds to infinite-dimensional feature space.
    • γ\gamma controls the "locality" of influence.

The Representer Theorem

Theorem. For any regularized empirical risk minimization problem of the form:

minfH1ni=1n(f(xi),yi)+λfH2,\min_{f \in \mathcal{H}} \frac{1}{n}\sum_{i=1}^n \ell(f(\mathbf{x}_i), y_i) + \lambda\lVert f\rVert_\mathcal{H}^2,

the minimizer admits the representation f(x)=i=1nciK(xi,x)f^*(\mathbf{x}) = \sum_{i=1}^n c_i K(\mathbf{x}_i, \mathbf{x}).

This justifies the kernel SVM: even though H\mathcal{H} may be infinite-dimensional, the optimal solution lies in the nn-dimensional subspace spanned by K(xi,)K(\mathbf{x}_i, \cdot).


Hinge Loss Interpretation

The soft-margin SVM is equivalent to minimizing:

1ni=1nmax(0,1yif(xi))+12Cw2.(12)\frac{1}{n}\sum_{i=1}^n \max(0, 1 - y_if(\mathbf{x}_i)) + \frac{1}{2C}\lVert\mathbf{w}\rVert^2. \tag{12}

This is hinge loss + L2 regularization, connecting SVMs to the general framework of regularized loss minimization. The hinge loss is a convex upper bound on the 0-1 classification loss.


Common Pitfalls

Pitfall 1. Forgetting to scale features. SVMs use distances/inner products; features on different scales distort the geometry.

Pitfall 2. Using RBF kernel with incorrect γ\gamma. Too large γ\gamma → each point only influences itself (overfitting). Too small γ\gamma → all points look similar (underfitting).

Pitfall 3. Expecting SVMs to scale to very large datasets. The dual has nn variables; solving the QP is O(n2)O(n^2)O(n3)O(n^3) in practice. Use SGD on the primal hinge loss for large nn.


Research Perspective

SVMs were the dominant classification method from the mid-1990s to early 2010s (Vapnik, 1995; Cortes & Vapnik, 1995). Their theoretical appeal lies in the margin-based generalization bounds and the elegant kernel framework. The kernel trick has since been reinterpreted through the Neural Tangent Kernel lens, connecting SVMs to infinite-width neural networks. Modern large-scale kernel methods use random Fourier features (Rahimi & Recht, 2007) to approximate RBF kernels in linear time.


Summary

  • Hard-margin SVM finds the maximum-margin separating hyperplane via a convex QP.
  • The dual depends only on inner products → enables kernelization.
  • Support vectors are the only data points that determine the solution.
  • Soft-margin handles non-separable data via slack variables and penalty CC.
  • Kernel trick implicitly maps to high-dimensional spaces without computing the map.
  • SVM \Leftrightarrow hinge loss + L2 regularization.

Exercises

Exercise 1. Show that the distance from a point x0\mathbf{x}_0 to the hyperplane wTx+b=0\mathbf{w}^T\mathbf{x} + b = 0 is wTx0+bw\frac{|\mathbf{w}^T\mathbf{x}_0 + b|}{\lVert\mathbf{w}\rVert}.

Exercise 2. Derive the dual problem (equation 6) from the Lagrangian by eliminating w\mathbf{w} and bb.

Exercise 3. Verify the KKT conditions for a simple 2D example with 3 points.

Exercise 4. Show that the polynomial kernel K(x,x)=(xTx+1)2K(\mathbf{x}, \mathbf{x}') = (\mathbf{x}^T\mathbf{x}' + 1)^2 corresponds to a specific finite-dimensional feature map (write it explicitly for d=2d=2).

Exercise 5. Prove that the RBF kernel K(x,x)=eγxx2K(\mathbf{x}, \mathbf{x}') = e^{-\gamma\lVert\mathbf{x}-\mathbf{x}'\rVert^2} is positive semi-definite by expanding as an infinite series.