Skip to main content
Practice

Support Vector Machine - Finding the Optimal Separating Line

Support Vector Machine (SVM) is a machine learning algorithm that finds the best decision boundary to separate data.

For example, suppose we need to classify emails as spam or not spam.

If spam and regular emails form clearly distinguishable groups, SVM finds the best line (Hyperplane) that separates them.


πŸ“Œ What is the best line to separate two groups?​

SVM doesn’t just classifyβ€”it finds the decision boundary that maximizes the margin, the distance between the closest points from each class.

DataMail TypeWord CountDomain Trust
ASpam100Low
BSpam90Low
CRegular30High
DRegular40High

When plotting this data, the X-axis can represent Word Count and the Y-axis Domain Trust.


thumbnail-public

In the graph above, each element signifies:

  • Red βœ– β†’ Spam email
  • Blue βœ– β†’ Regular email
  • X-axis: Word Count
  • Y-axis: Domain Trust
  • Bold black line β†’ Decision Boundary (optimal line separating spam and regular emails)
  • Two dashed lines β†’ Margin (distance between the decision boundary and support vectors)

SVM finds the line that optimally separates spam from regular emails.

The data points closest to this line are referred to as Support Vectors.

Support Vectors are the critical data points that define the decision boundary; if they change, the boundary changes.


How the Support Vector Machine Works​

The process by which SVM classifies data is as follows.


1. Finding the Hyperplane​

SVM identifies the hyperplane that best divides the data.

In 2D, this hyperplane is a line, and in 3D, it becomes a plane.


2. Maximizing the Margin​

Maximizing the distance between the hyperplane and the nearest data (Support Vectors).

This ensures more accurate classification when new data is introduced.


SVM uses the learned decision boundary to classify new data, such as determining whether an email is spam or not.


Support Vector Machines are powerful algorithms for finding clear boundaries and are used in various fields such as image classification, text classification, and more.

In the next session, we'll explore the k-means clustering algorithm.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.