∑GATE DA Atlas

Support Vector Machines

Maximum-margin linear classifiers — hyperplanes, functional and geometric margins, the hard-margin optimisation problem and its support vectors, soft margins with slack variables and the parameter C, the hinge-loss view, the dual problem, the kernel trick with polynomial and RBF kernels, hyperparameter effects, and multi-class strategies.

Section 610 practice questions

Maximum-margin classification

For linearly separable data there are infinitely many separating hyperplanes w⊤x+b=0\mathbf w^\top\mathbf x + b = 0. The SVM picks the one with the largest margin — the widest "street" between the classes — which generalises best and depends only on the hardest points.

wᵀx + b = 0wᵀx + b = −1wᵀx + b = +1 circled: support vectorsmargin = 2 / ‖w‖
The street between the dashed lines is as wide as possible; only the circled points touch it.

Geometry

  • Signed distance of x\mathbf x from the hyperplane: w⊤x+b∥w∥\dfrac{\mathbf w^\top\mathbf x + b}{\lVert\mathbf w\rVert}.
  • Scale w,b\mathbf w, b so the closest points satisfy yi(w⊤xi+b)=1y_i(\mathbf w^\top\mathbf x_i + b) = 1. Then the margin width is 2∥w∥\dfrac{2}{\lVert\mathbf w\rVert}.

Hard-margin SVM

min⁡w,b 12∥w∥2subject toyi(w⊤xi+b)≥1  ∀i.\min_{\mathbf w, b}\ \frac12\lVert\mathbf w\rVert^2 \quad\text{subject to}\quad y_i(\mathbf w^\top\mathbf x_i + b) \ge 1\ \ \forall i.

A convex quadratic program with a unique solution. The points with equality are the support vectors.

Soft margin: tolerating overlap

Real data overlaps. Introduce slack ξi≥0\xi_i \ge 0:

min⁡w,b,ξ 12∥w∥2+C∑iξis.t.yi(w⊤xi+b)≥1−ξi,  ξi≥0.\min_{\mathbf w, b, \boldsymbol\xi}\ \frac12\lVert\mathbf w\rVert^2 + C\sum_i\xi_i \quad\text{s.t.}\quad y_i(\mathbf w^\top\mathbf x_i + b) \ge 1 - \xi_i,\ \ \xi_i \ge 0.
  • 0<ξi≤10 < \xi_i \le 1: inside the margin but correctly classified; ξi>1\xi_i > 1: misclassified.
  • CC trades margin width against violations: large CC → hard-ish margin, low bias, high variance; small CC → wide margin, more violations, smoother.

The hinge-loss view

Eliminating ξ\xi gives regularised empirical risk minimisation:

min⁡w,b ∑imax⁡(0, 1−yi(w⊤xi+b))+12C∥w∥2.\min_{\mathbf w, b}\ \sum_i\max\big(0,\ 1 - y_i(\mathbf w^\top\mathbf x_i + b)\big) + \frac{1}{2C}\lVert\mathbf w\rVert^2.

The hinge loss is zero for points beyond the margin — which is why only support vectors matter — and grows linearly for violations (compare the log loss of logistic regression, which is never exactly zero).

The dual problem and support vectors

Using Lagrange multipliers αi\alpha_i:

max⁡α ∑iαi−12∑i,jαiαjyiyj xi⊤xjs.t.0≤αi≤C,  ∑iαiyi=0.\max_{\boldsymbol\alpha}\ \sum_i\alpha_i - \frac12\sum_{i,j}\alpha_i\alpha_jy_iy_j\,\mathbf x_i^\top\mathbf x_j \quad\text{s.t.}\quad 0 \le \alpha_i \le C,\ \ \sum_i\alpha_iy_i = 0.
  • w=∑iαiyixi\mathbf w = \sum_i\alpha_iy_i\mathbf x_i; only support vectors have αi>0\alpha_i > 0 — the solution is sparse.
  • The data appear only through inner products xi⊤xj\mathbf x_i^\top\mathbf x_j — the door to kernels.
  • Prediction: f(x)=sign⁡(∑iαiyi xi⊤x+b)f(\mathbf x) = \operatorname{sign}\left(\sum_i\alpha_iy_i\,\mathbf x_i^\top\mathbf x + b\right).

The kernel trick

Map inputs to a feature space ϕ(x)\phi(\mathbf x) where the classes are separable, and replace every inner product by a kernel K(x,z)=ϕ(x)⊤ϕ(z)K(\mathbf x, \mathbf z) = \phi(\mathbf x)^\top\phi(\mathbf z), computed without forming ϕ\phi.

KernelK(x,z)K(\mathbf x, \mathbf z)Notes
Linearx⊤z\mathbf x^\top\mathbf zhigh-dimensional sparse data (text)
Polynomial(x⊤z+c)d(\mathbf x^\top\mathbf z + c)^dall monomials up to degree dd
RBF (Gaussian)exp⁡(−γ∥x−z∥2)\exp(-\gamma\lVert\mathbf x - \mathbf z\rVert^2)infinite-dimensional feature space; default non-linear choice
Sigmoidtanh⁡(κ x⊤z+c)\tanh(\kappa\,\mathbf x^\top\mathbf z + c)not always a valid kernel

A function is a valid kernel iff every Gram matrix [K(xi,xj)][K(\mathbf x_i, \mathbf x_j)] is symmetric positive semi-definite (Mercer's condition). Sums, products and positive scalings of kernels are kernels.

Practical notes

  • Scale features — the margin is defined by distances.
  • Tune CC (and γ\gamma for RBF) by cross-validation on a log grid.
  • Training costs roughly O(n2)O(n^2)–O(n3)O(n^3) for kernel SVMs — fine for thousands of points, slow for millions (use linear SVMs or approximations there).
  • Multi-class: one-vs-rest (KK classifiers) or one-vs-one ((K2)\binom K2 classifiers, majority vote).
  • SVR (support vector regression) uses an ε\varepsilon-insensitive loss.

Quick revision

Practice questions

GATE-style questions: 5 one-mark and 5 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.

Q1NAT1 mark

A hard-margin linear SVM has weight vector w=(3,4)\mathbf w = (3, 4). The width of its margin, 2/∥w∥2/\lVert\mathbf w\rVert, is ______.

Q2NAT2 marks

The distance from the point (1,1)(1, 1) to the hyperplane 3x1+4x2−2=03x_1 + 4x_2 - 2 = 0 is ______.

Q3MCQ1 mark

In a trained SVM, the support vectors are

Q4MSQ2 marks

Which statements about SVMs are correct?

One or more options are correct.

Q5NAT2 marks

For the polynomial kernel K(x,z)=(x⊤z+1)2K(\mathbf x, \mathbf z) = (\mathbf x^\top\mathbf z + 1)^2 with x=(1,2)\mathbf x = (1, 2) and z=(3,1)\mathbf z = (3, 1), the kernel value is ______.

Q6NAT2 marks

For the RBF kernel K(x,z)=exp⁡(−γ∥x−z∥2)K(\mathbf x, \mathbf z) = \exp(-\gamma\lVert\mathbf x - \mathbf z\rVert^2) with γ=0.5\gamma = 0.5, x=(0,0)\mathbf x = (0, 0) and z=(1,1)\mathbf z = (1, 1), the kernel value is ______ (round to two decimals).

Q7NAT1 mark

For a training example with label y=+1y = +1 and SVM score f(x)=0.3f(\mathbf x) = 0.3, the hinge loss max⁡(0,1−yf(x))\max(0, 1 - y f(\mathbf x)) is ______.

Q8MCQ2 marks

A hard-margin SVM is trained on just two points: (1,1)(1, 1) with label +1+1 and (−1,−1)(-1, -1) with label −1-1. The learned classifier is

Q9MCQ1 mark

For an RBF-kernel SVM, a very large γ\gamma tends to

Q10NAT1 mark

A one-vs-one multi-class SVM for K=5K = 5 classes trains how many binary classifiers? ______