AI / ML Theory
Chapter 1 · 20 min

1.4 — Geometric view: the separating hyperplane and the margin

Goal: Interpret a linear classifier geometrically: the decision boundary is a hyperplane, the weight vector is its normal, and the signed distance to the boundary is the margin.

1. Why this session exists

Every linear classifier — perceptron, logistic regression, SVM, the first layer of any neural net — predicts based on the sign of w⊤x+bw^\top x + b. Behind that sign is a single piece of geometry: a hyperplane that cuts Rn\mathbb{R}^n into two half-spaces. This session unpacks that picture and defines the margin, the quantity that the perceptron's convergence proof (1.5) and the SVM's margin-maximisation objective (Chapter 3) both control.


2. Hyperplanes

A hyperplane in Rn\mathbb{R}^n is the level set of an affine function:

H={x∈Rn:w⊤x+b=0},w∈Rn∖{0}, b∈R.H = \{x \in \mathbb{R}^n : w^\top x + b = 0\}, \qquad w \in \mathbb{R}^n \setminus \{0\},\ b \in \mathbb{R}.

It is a flat (n−1)(n-1)-dimensional affine subspace. The pair (w,b)(w, b) specifies it up to a nonzero scaling: if α>0\alpha > 0, then (αw,αb)(\alpha w, \alpha b) describes the same set. (Sign matters: (−w,−b)(-w, -b) flips which side is positive.)

ww is the normal vector to HH. For any two points x,y∈Hx, y \in H,

w⊤x+b=0,w⊤y+b=0  ⟹  w⊤(x−y)=0.w^\top x + b = 0, \qquad w^\top y + b = 0 \implies w^\top (x - y) = 0.

So ww is orthogonal to every direction within HH — it is the normal.


3. Signed distance to a hyperplane

For an arbitrary point x0∈Rnx_0 \in \mathbb{R}^n, decompose

x0=xH+t w∥w∥,xH∈H, t∈R,x_0 = x_H + t\, \frac{w}{\lVert w \rVert}, \qquad x_H \in H,\ t \in \mathbb{R},

choosing xHx_H as the foot of the perpendicular from x0x_0 to HH. Apply w⊤w^\top and add bb:

w⊤x0+b=(w⊤xH+b)+t w⊤w∥w∥=0+t ∥w∥.w^\top x_0 + b = (w^\top x_H + b) + t\, \frac{w^\top w}{\lVert w \rVert} = 0 + t\, \lVert w \rVert.

Solving for tt,

 t  =  w⊤x0+b∥w∥. \boxed{\ t \;=\; \frac{w^\top x_0 + b}{\lVert w \rVert}.\ }

This is the signed distance from x0x_0 to HH. Its sign tells which side x0x_0 lies on; its absolute value is the Euclidean distance. We will call

d(x):=w⊤x+b∥w∥d(x) := \frac{w^\top x + b}{\lVert w \rVert}

the distance function of the hyperplane.


4. The decision rule

A linear binary classifier predicts

y^(x)=sign⁡(w⊤x+b),\hat y(x) = \operatorname{sign}(w^\top x + b),

with the convention sign⁡(0)=+1\operatorname{sign}(0) = +1 (the measure-zero boundary case from 0.9 doesn't matter in practice). The two open half-spaces

{x:w⊤x+b>0},{x:w⊤x+b<0}\{x : w^\top x + b > 0\}, \qquad \{x : w^\top x + b < 0\}

are the decision regions. For logistic regression specifically, y^prob=σ(w⊤x+b)>1/2\hat y_{\text{prob}} = \sigma(w^\top x + b) > 1/2 is equivalent to w⊤x+b>0w^\top x + b > 0, so the decision boundary coincides with HH.


5. The margin of a dataset

Let {(xi,yi)}i=1m\{(x_i, y_i)\}_{i=1}^m with yi∈{−1,+1}y_i \in \{-1, +1\}. (We switch to ±1\pm 1 encoding here because it pairs cleanly with the sign rule and with 1.5.) The classifier (w,b)(w, b) correctly labels example ii iff

yi (w⊤xi+b)>0.y_i\, (w^\top x_i + b) > 0.

The geometric margin of (w,b)(w, b) on example ii is

γi=yi w⊤xi+b∥w∥.\gamma_i = y_i\, \frac{w^\top x_i + b}{\lVert w \rVert}.

Positive iff the example is correctly classified; magnitude = Euclidean distance from xix_i to the hyperplane.

The geometric margin on the dataset is

γ(w,b)=min⁡i=1,…,mγi.\gamma(w, b) = \min_{i = 1, \dots, m} \gamma_i.

The maximum margin of the dataset is

γ∗=max⁡(w,b)γ(w,b).\gamma^* = \max_{(w, b)} \gamma(w, b).

If γ∗>0\gamma^* > 0 the dataset is linearly separable and γ∗\gamma^* measures by how much. This single number controls the perceptron's convergence speed (1.5) and is what SVMs maximise.


6. Why this matters

Three places the margin re-appears in the course.

  1. 1.5 (Novikoff's theorem). The number of perceptron updates is bounded by R2/γ∗ 2R^2 / \gamma^{*\,2} with R=max⁡i∥xi∥R = \max_i \lVert x_i \rVert.
  2. SVMs (Chapter 3). The hard-margin SVM is arg⁡max⁡γ\arg\max \gamma subject to all γi≥γ\gamma_i \ge \gamma. The soft-margin version trades off margin against violations.
  3. Generalisation bounds. Large-margin classifiers generalise better; Rademacher and PAC-Bayes bounds tighten as γ\gamma grows. This is the formal version of the visual intuition that a wider gap separates classes more confidently.

7. Takeaways

  • A linear classifier's decision boundary is a hyperplane H={x:w⊤x+b=0}H = \{x : w^\top x + b = 0\}.
  • w/∥w∥w / \lVert w \rVert is the unit normal to HH; −b/∥w∥-b / \lVert w \rVert is the signed offset from the origin along that normal.
  • Signed distance from xx to HH: d(x)=(w⊤x+b)/∥w∥d(x) = (w^\top x + b) / \lVert w \rVert.
  • Geometric margin on example ii: γi=yid(xi)\gamma_i = y_i d(x_i). Dataset margin γ=min⁡iγi\gamma = \min_i \gamma_i. Maximum margin γ∗=max⁡(w,b)γ\gamma^* = \max_{(w,b)} \gamma.

Self-test

(a) Find the hyperplane in R2\mathbb{R}^2 defined by w=(1,1)w = (1, 1), b=−2b = -2. Sketch it. Compute the signed distance from the origin and from (3,1)(3, 1).

(b) Show that the signed distance d(x)d(x) is invariant under the positive rescaling (w,b)→(αw,αb)(w, b) \to (\alpha w, \alpha b) with α>0\alpha > 0, but flips sign under α<0\alpha < 0.

(c) For a dataset of two points x+=(1,0)x_+ = (1, 0), x−=(−1,0)x_- = (-1, 0) with labels ±1\pm 1, find the maximum-margin hyperplane and compute γ∗\gamma^*.

(d) Prove that if a dataset is linearly separable, the normalised parameters (w/∥w∥, b/∥w∥)(w / \lVert w \rVert,\, b / \lVert w \rVert) achieving the maximum margin satisfy yi(w∗⊤xi+b∗)≥γ∗y_i (w^{*\top} x_i + b^*) \ge \gamma^* for all ii. (This is the canonical normalisation used in the SVM formulation.)