CS 460G Midterm Hub / Lectures / Week 5 Lecture 1
Week 5 · Lecture 1

Support Vector Machines I

Maximum margin, the 2/||w|| derivation, hard vs soft margin, and C.

mathguaranteed Q

The derivations on slides 23–26 are literally a practice-sheet question ("Derive the margin formula for SVM"). Learn the six lines.

The motivating problem

Given linearly separable data there are infinitely many hyperplanes that separate the classes, and they all have the same empirical risk (zero training error). They differ only in test loss.

Infinitely many separating hyperplanes
Infinitely many separating hyperplanes · slide 13

So empirical risk cannot choose between them. The extra criterion is geometric: pick the one whose margin is largest, on the argument that large-margin boundaries have lower generalisation error.

Support vectors, positive and negative hyperplanes, decision boundary
Support vectors, positive and negative hyperplanes, decision boundary · slide 22

Definitions, in the deck's words:

  • Margin — the distance between the separating hyperplane and the training samples (support vectors) closest to the hyperplanes.
  • Support vectors — the training points lying on the positive/negative hyperplanes. Everything else is irrelevant to the fit.

Derivation of the margin — memorise these lines

The full margin derivation
The full margin derivation · slide 25

1. Write the two support hyperplanes. Scale $w,w_0$ so that

$$w_0 + w^T x_{pos} = +1, \qquad w_0 + w^T x_{neg} = -1$$

2. Subtract the second from the first — the bias cancels:

$$w^T(x_{pos} - x_{neg}) = 2 \qquad \text{[subtracting two linear equations]}$$

3. Normalise by the length of $w$:

$$\|w\| = \sqrt{\sum_{j=1}^{m} w_j^2}$$

4. Divide — the projection of the gap onto the unit normal is the geometric distance between the hyperplanes:

$$\frac{w^T(x_{pos}-x_{neg})}{\|w\|} \qquad \text{[distance between positive and negative hyperplanes]}$$

5. Substitute step 2:

$$\boxed{\;\text{margin} = \frac{2}{\|w\|}\;}$$

Maximising $\frac{2}{\|w\|}$ is the same as minimising $\|w\|$, which is the same as minimising $\frac12\|w\|^2$ — and that is why the SVM objective has the square and the half. They make the derivative clean; they change nothing about the solution.

Hard margin

$$\min_{w,w_0} \tfrac12\|w\|^2 \quad \text{subject to} \quad y_i\big(w^Tx_i + w_0\big) \ge 1 \;\;\forall i$$

The constraint says: every point is on the correct side and outside the margin. This is only feasible when the data is perfectly separable.

Hard-margin constrained optimisation
Hard-margin constrained optimisation · slide 26

Soft margin

Real data is not separable, so relax each constraint with a slack variable $\xi_i \ge 0$:

$$\boxed{\;\min_{w,w_0,\xi}\; \tfrac12\|w\|^2 + C\sum_{i=1}^{N}\xi_i \quad \text{s.t.}\quad y_i\big(w^Tx_i+w_0\big)\ge 1-\xi_i,\;\; \xi_i \ge 0\;}$$

Soft-margin objective and constraints
Soft-margin objective and constraints · slide 38

The four scenarios, keyed to $\xi$ — this table is the question "distinguish hard and soft margin":

Position of the point$\xi_i$Note
correct side, far outside the margin$0$contributes nothing
correct side, exactly on the margin$0$a support vector
correct side, but inside the margin$0<\xi_i<1$tolerated at a cost
wrong side of the boundary (misclassified)$\xi_i>1$tolerated at a higher cost
Inside the margin — 0 < ξ < 1
Inside the margin — 0 < ξ < 1 · slide 34

What C does

$$\min \underbrace{\tfrac12\|w\|^2}_{\text{maximise margin}} + \; C\underbrace{\sum\xi_i}_{\text{penalise violations}}$$

$C$ is the inverse regularisation strength — it prices margin violations.

  • Small $C$ — violations are cheap, so the optimiser happily ignores constraints in exchange for a wide margin. More bias, less variance; can underfit.
  • Large $C$ — violations are expensive, so the optimiser forces every point to the correct side. Narrow margin, more variance; can overfit.
  • $C \to \infty$ recovers the hard margin.
Effect of C — large C versus small C
Effect of C — large C versus small C · slide 39

That is the answer to "What is the role of C in SVM?" — and note the direction, because it is the opposite of what people assume: larger C = less regularisation.

Hinge loss

SVM can be written as unconstrained ERM with the hinge loss:

$$L_{\text{hinge}}(y, f(x)) = \max\big(0,\; 1 - y\,f(x)\big)$$

Hinge loss
Hinge loss · slide 40
  • $y f(x) \ge 1$ — correct and outside the margin → loss $0$
  • $y f(x) < 1$ — inside the margin or wrong side → loss $1 - y f(x)$, growing linearly

It is the tightest convex upper bound on 0-1 loss, which is exactly why it can be optimised while 0-1 cannot. That comparison is practice question 18.

"Distinguish hard and soft margin." Hard margin requires every training point to satisfy $y_i(w^Tx_i+w_0)\ge 1$ — it only exists when the data is linearly separable, and a single outlier makes the problem infeasible. Soft margin introduces slack $\xi_i\ge0$ and minimises $\frac12\|w\|^2 + C\sum\xi_i$ subject to $y_i(w^Tx_i+w_0)\ge1-\xi_i$: it tolerates violations, is always feasible, and the trade-off between margin width and violation count is controlled by $C$. Add the extreme case: as $C\to\infty$ the soft margin converges to the hard margin.