Lesson 6.6 · 10 min read · about 55 min to master at a very slow pace

Hard-margin and Soft-margin SVM

The hard-margin optimisation problem, why it fails on overlapping data, slack variables and hinge loss, the soft-margin objective, and how hinge loss compares with logistic and 0–1 loss.

Not startedJump to quiz

Hard margin

Hard-margin SVM (perfectly separable data)

The constraint says every point is on the correct side and outside the margin. Minimising maximises the width (squaring and halving just make the maths easier).

The problem: real data are rarely separable. One overlapping point makes the constraints impossible, and a single outlier can force a very narrow margin.

Soft margin and hinge loss

Allow violations, but charge for them. For each point define the hinge loss (or slack):

Where the point is
Correct side, outside the margin0
between 0 and 1Correct side, inside the marginbetween 0 and 1
Misclassified

Soft-margin SVM

Equivalently: with . That's hinge loss plus an L2 penalty, the ridge idea applied to classification.

Hinge loss and the objective by hand

: ; ; . , : .

Suppose , and four points have . Then and .

: objective . : objective . A larger makes violations count more, pushing toward a narrower margin with fewer violations.

Hinge vs the other classification losses

Write each loss in terms of the margin (positive = correct):

0123-2-10123margin m = y·f(x) (negative = wrong side)loss
0–1 lossHinge max(0, 1 − m)Logistic (scaled) log(1 + e⁻ᵐ)
Hinge loss is exactly zero once a point is beyond the margin (m ≥ 1); logistic loss is smooth and never exactly zero. Both are convex stand-ins for the 0–1 loss, which is hard to optimise.

Because hinge loss is zero for points comfortably on the right side, only margin violators (the support vectors) influence the SVM. Logistic regression is influenced by every point.

Cheatsheet

Hard-margin SVM

s.t. .

Soft-margin SVM

, . ≡ hinge + L2, .

Hinge loss

. 0 beyond the margin; 0–1 inside; >1 if misclassified.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1calculateWhat is the hinge loss for a point with and ?
Q2calculateWhat is the hinge loss for a point with and ?
Q3calculateA soft-margin SVM has and slack values summing to 1.5. What is the objective with ?
Q4interpretA point's slack (hinge loss) is . Where is it?
Q5conceptWhy is a soft margin needed in practice?