Skip to content
GATEiit

GATE DA · Machine Learning

Support vector machine

The maximum-margin classifier: hard and soft margin SVMs, support vectors, hinge loss and the role of C, and the kernel trick for non-linear boundaries; GATE asks for margins, distances, hinge losses and kernel values.

Before you start

Concept notes

1. Margin and the hard-margin SVM

For labels yi∈{−1,+1}, a linear classifier predicts sign⁡(w⊤x+b). The distance of a point x from the hyperplane w⊤x+b=0 is ∣w⊤x+b∣∥w∥.

Many hyperplanes may separate the data. The SVM picks the one with the largest margin, the gap to the nearest points. Scale w,b so that the nearest points satisfy ∣w⊤x+b∣=1. Then the two margin hyperplanes are w⊤x+b=±1, and the margin width is margin=2∥w∥.

Maximising 2/∥w∥ is the same as minimising 12∥w∥2, so the hard-margin primal is min⁡w,b 12∥w∥2s.t.yi(w⊤xi+b)≥1  ∀i.

  • This is a convex quadratic program with a unique optimal w.
  • It has a solution only if the data are linearly separable.
  • The quantity yi(w⊤xi+b) is the functional margin of point i; it is positive when the point is correctly classified.
2/‖w‖ wᵀx + b = 0 wᵀx + b = +1 wᵀx + b = −1 ringed points are support vectors
Maximum-margin hyperplane: the margin hyperplanes pass through the support vectors

2. Support vectors and the dual

Using Lagrange multipliers αi≥0, the optimal weights are w=∑iαiyixi,∑iαiyi=0. The dual problem is max⁡α ∑iαi−12∑i,jαiαjyiyj xi⊤xjs.t. αi≥0, ∑iαiyi=0.

By complementary slackness, αi>0 only for points with yi(w⊤xi+b)=1, the points on the margin. These are the support vectors.

Consequences:

  • The solution depends only on the support vectors. Deleting or moving any other point (without crossing the margin) does not change w or b.
  • b is found from any support vector: b=ys−w⊤xs.
  • The data enter the dual only through dot products xi⊤xj. This is what makes the kernel trick possible.
  • Prediction is sign⁡(∑iαiyi xi⊤x+b), a sum over support vectors only.

For two points of opposite classes, the maximum-margin boundary is the perpendicular bisector of the segment joining them, and the margin equals the distance between them.

3. Soft margin, slack and hinge loss

Real data are rarely separable. The soft-margin SVM allows violations with slack variables ξi≥0: min⁡w,b,ξ 12∥w∥2+C∑iξis.t.yi(w⊤xi+b)≥1−ξi,  ξi≥0.

  • ξi=0: on or outside the correct margin. 0<ξi≤1: inside the margin but correctly classified. ξi>1: misclassified.
  • At the optimum ξi=max⁡(0, 1−yif(xi)), the hinge loss, with f(x)=w⊤x+b. So the SVM minimises 12∥w∥2+C∑imax⁡(0, 1−yif(xi)).
  • In the dual, the only change is 0≤αi≤C (box constraint).

The role of C:

Large C Small C
Penalty on violations heavy light
Margin narrow wide
Behaviour close to hard margin; fits training data, may overfit more errors allowed, smoother, may underfit
Bias / variance low bias, high variance high bias, low variance

As C→∞ the soft-margin SVM becomes the hard-margin SVM (on separable data). Points with yif(xi)>1 have zero hinge loss and do not affect the solution.

4. The kernel trick

To get a non-linear boundary, map x to features ϕ(x) and run a linear SVM there. Since the dual and the prediction use only dot products, replace xi⊤xj by a kernel K(xi,xj)=ϕ(xi)⊤ϕ(xj), computed without ever forming ϕ.

Common kernels:

  • Linear: K(x,z)=x⊤z.
  • Polynomial: K(x,z)=(x⊤z+c)p. For x,z∈R2, (x⊤z)2=ϕ(x)⊤ϕ(z) with ϕ(x)=(x12, 2x1x2, x22).
  • RBF (Gaussian): K(x,z)=exp⁡(−γ∥x−z∥2). Its feature space is infinite-dimensional; K(x,x)=1 and 0<K≤1.

A function is a valid kernel (Mercer's condition) when every Gram matrix [K(xi,xj)] is symmetric positive semidefinite. Sums, positive multiples and products of valid kernels are valid.

For RBF, large γ makes each support vector's influence very local, giving wiggly boundaries (overfitting); small γ gives smoother boundaries. Choose C and γ by cross-validation.

Multiclass SVMs use one-vs-rest or one-vs-one combinations of binary SVMs. Feature scaling matters, as with any distance- or dot-product-based method.

Formulas to remember

Distance to the hyperplane
∣w⊤x+b∣∥w∥
Margin width
2∥w∥
Hard-margin primal
min⁡w,b 12∥w∥2  s.t.  yi(w⊤xi+b)≥1
Weights from the dual
w=∑iαiyixi,∑iαiyi=0
Hinge lossy∈{−1,+1}, f=w⊤x+b
ℓ(y,f)=max⁡(0, 1−yf)
Polynomial kernel
K(x,z)=(x⊤z+c)p
RBF kernel
K(x,z)=exp⁡ ⁣(−γ∥x−z∥2)

Common mistakes

  • Writing the margin as 1/∥w∥; the full width between the margin hyperplanes is 2/∥w∥ (each side is 1/∥w∥).
  • Using labels 0 and 1 in hinge-loss or margin formulas; SVMs use y∈{−1,+1}.
  • Reversing the role of C: large C means a narrower margin and less tolerance for errors, not more.
  • Thinking every training point affects the SVM; only support vectors (points on or inside the margin) do.
  • Forgetting that a kernel must give a positive semidefinite Gram matrix; not every similarity function is a valid kernel.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Maximum margin for two points

numerical

Training set: (1,1) with label +1 and (−1,−1) with label −1. Find the hard-margin SVM w, b and the margin.

  1. Step 1: Guess the shape of $w$.

    Try it on paper first.

Example 2: Hinge loss of a given classifier

numerical

f(x)=x1−x2 (w=(1,−1), b=0). Points: (2,0) label +1; (1,0.5) label +1; (0,1) label −1; (1,0) label −1. Find each hinge loss and the total.

  1. Step 1: Compute $y f(x)$ for each point.

    Try it on paper first.

Example 3: Checking a polynomial kernel

numerical

For K(x,z)=(x⊤z)2 with x=(1,2), z=(3,1), compute K directly and through ϕ(x)=(x12,2x1x2,x22).

  1. Step 1: Use the kernel.

    Try it on paper first.

Example 4: What does C do?

conceptual

An RBF-kernel SVM gets 100% training accuracy but poor validation accuracy with C=1000. What should you change, and why?

  1. Step 1: Diagnose.

    Try it on paper first.

Previous year questions

2 official GATE DA questions on this topic, newest first.

Practise these 2 PYQs →

Topic test

10 questions: up to 2 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.