Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Support Vector Machines (SVM)

1. Geometric Intuition and the Margin

The goal of a Support Vector Machine is to find a hyperplane w⊤x+b=0w^\top x + b = 0 that separates two classes with the maximum margin.

1.1 Distance to the Hyperplane

For any point xix_i, the signed distance to the hyperplane is given by:

γi=w⊤xi+b∥w∥\gamma_i = \frac{w^\top x_i + b}{\|w\|}

To ensure the distance is always positive for correctly classified points, we define the functional margin as yi(w⊤xi+b)y_i(w^\top x_i + b). The geometric margin is then:

Margin=yi(w⊤xi+b)∥w∥\text{Margin} = \frac{y_i(w^\top x_i + b)}{\|w\|}

1.2 The Canonical Hyperplane

Since scaling ww and bb by a constant does not change the hyperplane, we can fix the functional margin of the points closest to the hyperplane (the support vectors) to be exactly 1:

yi(w⊤xi+b)=1y_i(w^\top x_i + b) = 1

Under this convention, the total margin between the two classes is 2∥w∥\frac{2}{\|w\|}.


2. Primal Optimization Problems

2.1 Hard-Margin SVM (Linearly Separable)

When the data is perfectly separable, we maximize the margin by minimizing the inverse:

min⁡w,b12∥w∥2s.t.yi(w⊤xi+b)≥1,i=1,…,m\begin{aligned} \min_{w, b} & \quad \frac{1}{2}\|w\|^2 \\ \text{s.t.} & \quad y_i(w^\top x_i + b) \ge 1, \quad i=1, \dots, m \end{aligned}

2.2 Soft-Margin SVM (Non-Separable)

To handle noise or overlapping distributions, we introduce slack variables ξi≥0\xi_i \ge 0.

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

3. Lagrange Duality and the Dual Problem

To solve the constrained optimization efficiently and enable the use of kernels, we derive the Wolfe Dual.

3.1 The Lagrangian

For the soft-margin case, we define the Lagrangian LL with multipliers αi≥0\alpha_i \ge 0 and μi≥0\mu_i \ge 0:

L(w,b,ξ,α,μ)=12∥w∥2+C∑i=1mξi−∑i=1mαi[yi(w⊤xi+b)−1+ξi]−∑i=1mμiξiL(w, b, \xi, \alpha, \mu) = \frac{1}{2}\|w\|^2 + C \sum_{i=1}^m \xi_i - \sum_{i=1}^m \alpha_i [y_i(w^\top x_i + b) - 1 + \xi_i] - \sum_{i=1}^m \mu_i \xi_i

3.2 Stationarity Conditions

To find the dual, we take the partial derivatives of LL and set them to zero:

  1. ∂L∂w=0  ⟹  w=∑i=1mαiyixi\frac{\partial L}{\partial w} = 0 \implies w = \sum_{i=1}^m \alpha_i y_i x_i

  2. ∂L∂b=0  ⟹  ∑i=1mαiyi=0\frac{\partial L}{\partial b} = 0 \implies \sum_{i=1}^m \alpha_i y_i = 0

  3. ∂L∂ξi=0  ⟹  C−αi−μi=0\frac{\partial L}{\partial \xi_i} = 0 \implies C - \alpha_i - \mu_i = 0

From (3), since μi≥0\mu_i \ge 0, we conclude that 0≤αi≤C0 \le \alpha_i \le C.

3.3 The Dual Objective

Substituting the stationarity results back into the Lagrangian yields the Dual Problem:

max⁡α∑i=1mαi−12∑i=1m∑j=1mαiαjyiyj(xi⊤xj)s.t.∑i=1mαiyi=00≤αi≤C,i=1,…,m\begin{aligned} \max_{\alpha} & \quad \sum_{i=1}^m \alpha_i - \frac{1}{2} \sum_{i=1}^m \sum_{j=1}^m \alpha_i \alpha_j y_i y_j (x_i^\top x_j) \\ \text{s.t.} & \quad \sum_{i=1}^m \alpha_i y_i = 0 \\ & \quad 0 \le \alpha_i \le C, \quad i=1, \dots, m \end{aligned}

4. KKT Conditions and Parameter Recovery

4.1 Complementary Slackness

The Karush-Kuhn-Tucker (KKT) conditions must hold at the optimum:

  1. αi[yi(w⊤xi+b)−1+ξi]=0\alpha_i [y_i(w^\top x_i + b) - 1 + \xi_i] = 0

  2. μiξi=(C−αi)ξi=0\mu_i \xi_i = (C - \alpha_i) \xi_i = 0

4.2 Support Vector Roles

4.3 Recovering b∗b^*

For any support vector xjx_j where 0<αj<C0 < \alpha_j < C, we know yj(w⊤xj+b)=1y_j(w^\top x_j + b) = 1. Multiplying by yjy_j:

b∗=yj−∑i=1mαiyi(xi⊤xj)b^* = y_j - \sum_{i=1}^m \alpha_i y_i (x_i^\top x_j)

To increase numerical stability, we typically average this over the set of all such support vectors MM:

b∗=1∣M∣∑j∈M(yj−∑i=1mαiyi(xi⊤xj))b^* = \frac{1}{|M|} \sum_{j \in M} \left( y_j - \sum_{i=1}^m \alpha_i y_i (x_i^\top x_j) \right)

5. The Kernel Trick

The dual objective and the prediction rule depend only on the inner product xi⊤xjx_i^\top x_j. This allows us to map data into a high-dimensional feature space ϕ(x)\phi(x) without explicitly computing the coordinates.

5.1 Kernel Function

We define a kernel K(xi,xj)=ϕ(xi)⊤ϕ(xj)K(x_i, x_j) = \phi(x_i)^\top \phi(x_j). Common kernels include:

5.2 Mercer’s Theorem

A function K(x,z)K(x, z) is a valid kernel if and only if for any finite set of points, the Kernel Matrix (Gram Matrix) Gij=K(xi,xj)G_{ij} = K(x_i, x_j) is symmetric and positive semi-definite.

5.3 Prediction Rule

The final decision function for a new point xx becomes:

f(x)=sign(∑i∈SVαiyiK(xi,x)+b)f(x) = \text{sign}\left( \sum_{i \in \text{SV}} \alpha_i y_i K(x_i, x) + b \right)