Thursday, August 14, 2025

Q8: What is a margin in SVM?

To See All Interview Preparation Articles: Index For Interviews Preparation
Other Ques From: Ch.1 from the 'Hundred-Page Machine Learning Book'

In Support Vector Machines (SVM), the margin is the distance between the decision boundary (the separating hyperplane) and the closest data points from each class.


๐Ÿ“Œ Key Points:

  1. Support Vectors

    • The data points that lie closest to the decision boundary.

    • They "support" or define the position and orientation of the boundary.

  2. Margin Definition

    • The margin is measured as the perpendicular distance from the decision boundary to the nearest support vector from either class.

    • In a maximum-margin classifier, SVM chooses the boundary that maximizes this distance.

  3. Why Maximize the Margin?

    • A larger margin means the decision boundary is farther from any training data point, which usually improves generalization on unseen data.

    • This aligns with the structural risk minimization principle: simpler decision boundaries generalize better.


๐Ÿ“ Formula for Margin

For a linear SVM, the margin MM is:

M=2∥w∥M = \frac{2}{\|w\|}

Where:

  • ww = weight vector defining the hyperplane w⋅x+b=0w \cdot x + b = 0


๐Ÿ–ผ Intuition Example:

Imagine two parallel lines enclosing the training points of both classes:

  • The middle line between them is the decision boundary.

  • The distance from this middle line to either parallel line is half the margin.

  • SVM’s goal is to push these lines as far apart as possible while still separating the classes.


If you want, I can create a visual diagram showing an SVM decision boundary with the margin and support vectors labeled. That usually makes this concept much clearer.
Do you want me to make it?

Tags: Technology,Machine Learning,Interview Preparation,

No comments:

Post a Comment