# Support Vector Machines (SVM): Margin Duality, KKT Conditions & Kernel Trick
Exam: GATE Data Science & Artificial Intelligence (DA) (GATE DA)
Subject: Machine Learning & Deep Learning
Canonical URL: https://gateandnet.com/exams/gate-da/machine-learning-and-ai/svm-margin-duality-and-kernel-trick

> Geometric margin 2/||w|| derivation, Soft-Margin slack variables & hinge loss, Lagrangian dual formulation, KKT complementary slackness, and Mercer RBF/Polynomial kernels.

## 1. Geometric Margin & Hard-Margin Primal Optimization

Given linearly separable binary data $\{(x_i, y_i)\}_{i=1}^n$ with $y_i \in \{-1, +1\}$, fix the scale of $(w, b)$ so the closest points lie on the **canonical margin boundaries** $w^T x + b = \pm 1$.
The perpendicular distance between parallel hyperplanes $w^T x + b = +1$ and $w^T x + b = -1$ is:

$$
\gamma = \frac{|1 - (-1)|}{\|w\|_2} = \frac{2}{\|w\|_2}
$$

Maximizing $\frac{2}{\|w\|_2}$ yields the strictly convex quadratic program (QP):

$$
\min_{w, b} \; \frac{1}{2}\|w\|_2^2 \quad \text{subject to} \quad y_i(w^T x_i + b) \ge 1 \quad \forall i \in \{1, \dots, n\}
$$

## 2. Soft-Margin SVM, Slack Variables & Hinge Loss

For noisy or non-separable data, introduce non-negative **slack variables** $\xi_i \ge 0$:

$$
\min_{w, b, \xi} \; \frac{1}{2}\|w\|_2^2 + C \sum_{i=1}^{n} \xi_i \quad \text{s.t. } y_i(w^T x_i + b) \ge 1 - \xi_i, \; \xi_i \ge 0
$$

Eliminating $\xi_i = \max\big(0, 1 - y_i(w^T x_i + b)\big)$ reveals **Hinge Loss + $L_2$ Regularization**:

| Dual Multiplier $\alpha_i$ | Slack $\xi_i$ | Geometric Location of Point $x_i$ |
| :--- | :---: | :--- |
| $\alpha_i = 0$ | $\xi_i = 0$ | Strictly outside margin ($y_i f(x_i) > 1$) — **Non-Support Vector** |
| $0 < \alpha_i < C$ | $\xi_i = 0$ | **Exact Margin Boundary** ($y_i f(x_i) = 1$) — used to solve for $b^*$ |
| $\alpha_i = C$ | $0 < \xi_i \le 1$ | Inside margin but **correctly classified** |
| $\alpha_i = C$ | $\xi_i > 1$ | **Misclassified** ($y_i f(x_i) < 0$) — Bounded Support Vector |

> [!TRAP]
> **Moving Non-Support Vectors:** Perturbing or deleting any training point with $\alpha_i = 0$ (so long as it remains strictly outside the margin $y_i f(x_i) > 1$) causes **ZERO change** to the optimal hyperplane $(w^*, b^*)$!

## 3. Mercer’s Theorem & Common Kernel Functions

A symmetric function $K: \mathcal{X} \times \mathcal{X} \to \mathbb{R}$ is a valid kernel $K(x, z) = \langle \phi(x), \phi(z) \rangle$ iff the **Gram Matrix** $G_{ij} = K(x_i, x_j)$ is **Positive Semi-Definite (PSD)** ($v^T G v \ge 0$) for every finite sample:

- **Polynomial Kernel (degree $d$):** $K(x, z) = (x^T z + c)^d$ ($c \ge 0$). For $x \in \mathbb{R}^p$, inhomogeneous $(x^T z + 1)^d$ spans $\binom{p + d}{d}$ monomial features in $\mathcal{O}(p)$ dot-product time!
- **Gaussian RBF Kernel:** $K(x, z) = \exp(-\gamma \|x - z\|_2^2)$. As $\gamma \to \infty$ (tiny bandwidth $\sigma \to 0$), $K(x_i, x_j) \to \mathbb{I}[i = j]$, causing severe **overfitting** (island decision boundaries around each training sample).

## Solved Practice Questions & PYQs

### [GATE DA ML | MCQ]
A hard-margin linear SVM in $\mathbb{R}^2$ learns the decision hyperplane $3x_1 + 4x_2 - 2 = 0$ with canonical margin boundaries $3x_1 + 4x_2 - 2 = \pm 1$. What is the **total geometric margin** $\gamma$ between the two class support hyperplanes?
**Correct Answer:** B
**Solution:** Here $w = [3, 4]^T \implies \|w\|_2 = \sqrt{3^2 + 4^2} = 5$. The total geometric margin between $w^T x + b = +1$ and $w^T x + b = -1$ is $\gamma = \frac{2}{\|w\|_2} = \frac{2}{5} = \mathbf{0.40}$.

### [GATE DA ML | MCQ]
In a trained Soft-Margin SVM, suppose a training point $(x_k, y_k)$ has dual Lagrange multiplier $\alpha_k = 0$. If $(x_k, y_k)$ is **removed** from the training set and the SVM is retrained, what happens to the optimal decision boundary?
**Correct Answer:** C
**Solution:** Since $w^* = \sum_i \alpha_i y_i x_i$, any point with $\alpha_k = 0$ is a **non-support vector** lying strictly outside the margin ($y_k(w^{*T}x_k + b^*) > 1$). Removing it leaves the KKT optimality system and $(w^*, b^*)$ **completely unchanged**!
