What is Support Vector Machine (SVM), and how does it work in machine learning?
Updated Feb 20, 2026
Short answer
A hyperplane is the core idea behind Support Vector Machine (SVM): it finds the best boundary that separates classes by maximizing the margin between them. SVM works well for classification and can also handle regression by finding a boundary that keeps errors within a defined range.
Deep explanation
Support Vector Machine (SVM) is a supervised machine learning algorithm mainly used for classification problems. The goal of SVM is to find a decision boundary that separates different classes as clearly as possible.
For a simple two-class problem, imagine plotting data points on a graph:
- One class contains points labeled
0. - Another class contains points labeled
1. - SVM tries to draw a line that separates these two groups.
In higher dimensions, this line becomes a hyperplane. The best hyperplane is not just any separating boundary; it is the one with the largest possible distance from the nearest points of each class.
How SVM finds the best boundary
The points closest to the decision boundary are called support vectors. They are the most important data points because they determine the position of the hyperplane.
The main objective of SVM is to maximize the margin, which is the distance between the hyperplane and the nearest support vectors.
A larger margin usually means the model will generalize better to unseen data because it is less sensitive to small changes in the training data.
The basic process looks like this:
Training data | vFind possible separating hyperplanes | vMeasure margin size | vChoose hyperplane with maximum margin | vClassify new data pointsSVM intuition
Suppose two possible boundaries can separate cats and dogs in an image dataset:
| Boundary | Margin size | Expected performance |
|---|---|---|
| Very close to one class | Small | More likely to overfit |
| Far from both classes | Large | Usually better generalization |
SVM prefers the second boundary because it creates more separation between classes.
Linear SVM
A linear SVM works when data can be separated using a straight line or flat plane.
For example:
- Classifying emails as spam or not spam using word features.
- Predicting whether a transaction is legitimate or fraudulent using numerical features.
The decision function can be represented as:
score = weight_vector @ input_features + bias
if score >= 0: prediction = "Class A"else: prediction = "Class B"The sign of the score determines which side of the hyperplane a data point belongs to.
Non-linear SVM and kernels
Real-world data is often not linearly separable. SVM handles this using the kernel trick.
Instead of explicitly transforming data into a higher-dimensional space, kernels allow SVM to calculate relationships in that space efficiently.
Common kernels include:
| Kernel | Use case |
|---|---|
linear | Data already separates well with a line |
rbf | Complex patterns with curved boundaries |
polynomial | Relationships involving feature combinations |
The kernel trick lets SVM create complex decision boundaries without manually creating new features.
SVM workflow
Important hyperparameters
SVM performance depends heavily on choosing good parameters:
C: Controls the trade-off between a wider margin and correctly classifying training examples.
- Small
Callows more mistakes but creates a simpler boundary. - Large
Ctries harder to classify every training point.
kernel: Determines the type of boundary the model can create.
gamma: Controls how much influence individual points have when using kernels likerbf.
- High
gammacan create very complex boundaries and risk overfitting. - Low
gammacreates smoother boundaries.
SVM for regression
SVM is also used for regression through Support Vector Regression (SVR).
Instead of finding a separating boundary between classes, SVR finds a function where predictions can vary within a margin called the epsilon (ε) tube. Errors inside this tube are ignored, while larger errors affect the model.
SVM is powerful because it focuses on the hardest examples near the decision boundary instead of treating every training point equally.
Real-world example
Consider a bank building a model to detect fraudulent transactions.
Each transaction can be represented using features such as:
- Transaction amount
- Location difference from usual activity
- Number of transactions in a short period
- Device information
An SVM classifier learns a boundary separating normal transactions from fraudulent ones. Transactions near the boundary become support vectors because they are harder to classify.
A simplified implementation might look like:
from sklearn.svm import SVC
model = SVC(kernel="rbf", C=1.0)model.fit(transaction_features, fraud_labels)
result = model.predict(new_transaction)The trained model can then classify new transactions as likely fraud or normal.
Common mistakes
- * **Ignoring scaling** - SVM is sensitive to feature ranges, so normalize or standardize features before training.
- * **Choosing a complex kernel immediately** - Start with a linear model and increase complexity only when needed.
- * **Using default parameters blindly** - Tune `C`, `gamma`, and `kernel` because they strongly affect results.
- * **Assuming SVM works best for every dataset** - Very large datasets may train slowly, so tree-based models or neural networks may be more practical.
- * **Misunderstanding support vectors** - They are not all data points
- they are the critical points closest to the decision boundary.
Follow-up questions
- Why does SVM maximize the margin between classes?
- What happens when data is not linearly separable?
- How does the C parameter affect an SVM model?
- What are support vectors in SVM?
- When would you choose SVM over another machine learning algorithm?