SVM
machine learning
functional margin
support vector machines
classification

How to understand the functional margin in SVM ?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

Support Vector Machines (SVM) are powerful supervised learning models used for classification and regression tasks. One of the core concepts within SVM is the margin, which quantifies the distance between the decision boundary (hyperplane) and the nearest data points. Understanding the functional margin is crucial because it drives the optimization that determines the SVM model.

What Is the Functional Margin?

The functional margin measures the confidence of the classification made by the separating hyperplane. A larger functional margin means the data point is farther from the decision boundary and classified more confidently.

Mathematical Formulation

In a binary classification problem with labels yi1,1y_i \in {-1, 1}, let:

  • xi\mathbf{x}_i be the feature vector of data point ii
  • w\mathbf{w} be the normal vector to the hyperplane
  • bb be the bias term

The hyperplane is defined by all points x\mathbf{x} satisfying wx+b=0\mathbf{w} \cdot \mathbf{x} + b = 0.

For a data point xi\mathbf{x}_i with label yiy_i, the functional margin is:

γ(i)=yi(wxi+b)\gamma^{(i)} = y_i (\mathbf{w} \cdot \mathbf{x}_i + b)

Here, wxi\mathbf{w} \cdot \mathbf{x}_i is the dot product between the normal vector and the feature vector. The term wxi+b\mathbf{w} \cdot \mathbf{x}_i + b gives a signed distance from the point to the hyperplane (scaled by w\|\mathbf{w}\|). Multiplying by the true label yiy_i ensures that correct classifications yield a positive margin.

Interpreting the Functional Margin

  • Positive margin (γ(i)>0\gamma^{(i)} > 0): The point is classified correctly. The larger the value, the more confidently the point sits on the correct side of the boundary.
  • Negative margin (γ(i)<0\gamma^{(i)} < 0): The point is misclassified. It lies on the wrong side of the hyperplane.
  • Zero margin (γ(i)=0\gamma^{(i)} = 0): The point lies exactly on the decision boundary.

The Problem with Functional Margin: Scale Sensitivity

The functional margin has a critical flaw: it is not scale-invariant. If you multiply w\mathbf{w} and bb by a constant kk, the functional margin scales by kk as well:

γ(i)=yi(kwxi+kb)=kγ(i)\gamma'^{(i)} = y_i (k\mathbf{w} \cdot \mathbf{x}_i + kb) = k \cdot \gamma^{(i)}

This means you can make the functional margin arbitrarily large without actually changing the hyperplane or improving classification. To fix this, SVM uses the geometric margin.

Geometric Margin

The geometric margin normalizes the functional margin by the norm of w\mathbf{w}:

γ^(i)=γ(i)w\hat{\gamma}^{(i)} = \frac{\gamma^{(i)}}{\|\mathbf{w}\|}

This gives the true Euclidean distance from the data point to the hyperplane, which is invariant to scaling of w\mathbf{w} and bb. The SVM optimization objective is to maximize the minimum geometric margin across all training points:

maxw,b1wsubject toyi(wxi+b)1i\max_{\mathbf{w}, b} \frac{1}{\|\mathbf{w}\|} \quad \text{subject to} \quad y_i(\mathbf{w} \cdot \mathbf{x}_i + b) \geq 1 \quad \forall i

The constraint γ(i)1\gamma^{(i)} \geq 1 is a normalization convention. By fixing the functional margin of the closest points to 1, maximizing 1w\frac{1}{\|\mathbf{w}\|} is equivalent to maximizing the geometric margin.

Worked Example

Consider three data points:

  • x1=(1,2)\mathbf{x}_1 = (1, 2) with label y1=+1y_1 = +1
  • x2=(2,3)\mathbf{x}_2 = (2, 3) with label y2=1y_2 = -1
  • x3=(3,4)\mathbf{x}_3 = (3, 4) with label y3=+1y_3 = +1

With hyperplane parameters w=(0.5,1)\mathbf{w} = (0.5, 1) and b=3b = -3:

Functional margins:

  • γ(1)=(+1)(0.51+123)=(+1)(2.53)=0.5\gamma^{(1)} = (+1)(0.5 \cdot 1 + 1 \cdot 2 - 3) = (+1)(2.5 - 3) = -0.5
  • γ(2)=(1)(0.52+133)=(1)(43)=1\gamma^{(2)} = (-1)(0.5 \cdot 2 + 1 \cdot 3 - 3) = (-1)(4 - 3) = -1
  • γ(3)=(+1)(0.53+143)=(+1)(5.53)=2.5\gamma^{(3)} = (+1)(0.5 \cdot 3 + 1 \cdot 4 - 3) = (+1)(5.5 - 3) = 2.5

Interpretation:

  • x1\mathbf{x}_1 has a negative margin, so it is misclassified.
  • x2\mathbf{x}_2 also has a negative margin, so it is misclassified.
  • x3\mathbf{x}_3 has a positive margin of 2.5, so it is correctly classified with good confidence.

Geometric margins (with w=0.25+11.118\|\mathbf{w}\| = \sqrt{0.25 + 1} \approx 1.118):

  • γ^(1)=0.5/1.1180.447\hat{\gamma}^{(1)} = -0.5 / 1.118 \approx -0.447
  • γ^(2)=1/1.1180.894\hat{\gamma}^{(2)} = -1 / 1.118 \approx -0.894
  • γ^(3)=2.5/1.1182.236\hat{\gamma}^{(3)} = 2.5 / 1.118 \approx 2.236

Summary

ConceptFormulaKey Property
Functional Marginγ(i)=yi(wxi+b)\gamma^{(i)} = y_i(\mathbf{w} \cdot \mathbf{x}_i + b)Scale-dependent
Geometric Marginγ^(i)=γ(i)/w\hat{\gamma}^{(i)} = \gamma^{(i)} / |\mathbf{w}|Scale-invariant
SVM Objectivemax1w\max \frac{1}{|\mathbf{w}|} s.t. yi(wxi+b)1y_i(\mathbf{w} \cdot \mathbf{x}_i + b) \geq 1Maximizes geometric margin

The functional margin captures classification confidence but is sensitive to the scale of the weight vector. The geometric margin corrects for this by normalizing. SVM's optimization maximizes the geometric margin by convention fixing the minimum functional margin to 1, which leads to the elegant formulation of finding the weight vector with minimum norm that correctly separates the data.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.