Core ML Models Guide 5 of 6 · tap to switch
Support Vector Machines (SVM)
Carve the widest possible safety margin between classes, ignore interior clutter, and curve boundaries effortlessly using the Kernel Trick.
Suppose two rows of microchip test readings sit cleanly apart: green Pass chips in the top-right, coral Defect chips in the bottom-left. You could draw a thousand different straight lines that achieve 100% training accuracy. Which line will survive brand-new, slightly noisy chips tomorrow?
A Support Vector Machine (SVM) answers with brilliant geometric simplicity: build the widest possible empty highway between the two classes, and paint the decision boundary straight down the center!
Click through the 4 experiments below, starting from 1. Risky Thin Line: compare a tight, risky cut against the Maximum-Margin Highway, then watch what happens when you nudge a far-away interior dot versus one of the ringed dots touching the road curbs!
Look at Experiment 3 vs. Experiment 4: you could move every far-away interior dot across the room and the highway would stay frozen to the decimal. Only those few boundary dots sitting directly on the two road curbs hold the entire highway in place, which is literally why they are called Support Vectors.
Real data is messy: the Soft-Margin C dial
Real-world factories and hospitals rarely give you perfectly separated dots. Often one stray Defect chip lands inside Pass territory. If you demand a strict Hard Margin with zero mistakes, either no straight line exists or the highway twists into a razor-thin sliver.
Modern SVMs therefore use a Soft Margin tuned by a strictness dial called C. Think of C as the fine for letting dots step inside the buffer street: small C is forgiving and keeps the highway wide, while huge C is strict and bends the road to avoid every mistake. Switch between C = 0.1 (Forgiving), C = 1.0 (Balanced), and C = 50 (Strict) below!
The Kernel Trick: separating concentric circles with a flat cut
Wait: what if safe Pass microchips cluster inside a tight central voltage-temperature circle while overheating or undervolted Defect chips surround them in an outer ring? No straight 2D line can ever separate an inner circle from an outer ring!
Watch the famous Kernel Trick solve this in three clicks below: lift the outer dots upward by how far they sit from the center, like raising a trampoline rim while the center stays low (giving each dot a vertical height z). Instantly one flat horizontal sheet slices cleanly between the lifted outer ring and the low inner core, and projecting that flat cut back down onto the 2D chart gives a crisp closed loop!
The real magic of the Kernel Trick is that an SVM never actually builds and stores giant extra height columns in memory. Instead, it plugs any pair of 2D dots into a compact closeness shortcut called a Kernel Function. The most popular choice is the RBF (Radial Basis Function) Kernel, which imagines a smooth bell-shaped hill around every training dot and checks how close two dots sit on those hills, achieving smooth curved boundaries at low cost!
Tuning RBF Gamma (γ): smooth hills vs. sharp overfit bubbles
With an RBF (Radial Basis Function) kernel, every training dot radiates a smooth bell-shaped hill of influence around itself: nearby spots feel that dot’s pull strongly, while distant spots feel almost nothing. The gamma (γ) dial controls how wide or narrow each bell hill is:
- Small
γ(wide hills): broad, overlapping hills blend together into gentle, almost flat boundaries (risk of underfitting curved groups). - Balanced
γ(medium hills): smooth hills trace the natural curve between classes while ignoring stray noisy dots. - Huge
γ(narrow hills): needle-sharp hills wrap tiny private bubbles around every single training dot, including outliers (classic overfitting!).
Start on Small γ (Too Broad) below, then step through Balanced and Huge γ while watching the ringed green outlier in the bottom-right corner!
One golden rule before leaving this page: because an SVM measures highway widths and bell-hill distances directly across your chart axes, always rescale every feature column to the same range before training. Otherwise, a column with huge numbers (like salary in thousands) will completely dominate a small-number column (like voltage in single digits) and warp the highway!
See the Primal Quadratic Program, Hinge Loss & Dual Mercer KernelsThesis / Reference
1. Soft-Margin Primal Objective (Cortes & Vapnik, 1995): Given labeled pairs with , maximizing the geometric margin while allowing slack violations is equivalent to the strictly convex quadratic program:
Eliminating reveals the equivalent unconstrained L2-Regularized Hinge Loss formulation: . Notice that any point strictly outside the margin () incurs exact zero loss and zero gradient, proving why interior points never move the hyperplane!
2. Lagrangian Dual & Kernel Substitution: Introducing Lagrange multipliers , the optimal weight vector satisfies , where holds exclusively for Support Vectors. Because both training and prediction depend only on pairwise dot products , replacing them with any positive semi-definite Mercer Kernel implicitly operates in high (or infinite!) dimensional Hilbert space:
See Leak-Free StandardScaler + RBF SVM in PythonOptional Code
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV
# StandardScaler is mandatory before SVC so every axis shares unit scale!
pipe = make_pipeline(
StandardScaler(),
SVC(kernel="rbf", probability=True, random_state=42),
)
# Jointly tune margin strictness C and RBF reach gamma via Cross-Validation
grid = GridSearchCV(
pipe,
param_grid={
"svc__C": [0.1, 1.0, 10.0],
"svc__gamma": ["scale", 0.05, 0.5],
},
cv=5,
)
grid.fit(X_train, y_train)
print("Best SVM params:", grid.best_params_)
print("Support vectors used:", grid.best_estimator_.named_steps["svc"].n_support_)What if your dataset has NO labels at all?
Every model so far (Linear Regression, Logistic Regression, KNN, Decision Trees, Random Forests, Gradient Boosting, and SVMs) trained on labeled examples (Supervised Learning).
What happens when your company hands you 50,000 raw customer profiles or delivery addresses with zero labels and asks you to discover natural groups automatically?
Let’s finish Path 03 with the classic engine of Unsupervised Learning: K-Means Clustering.
Quick Intuition Check
Four quick real-world scenarios. No scores, just test your intuition.
You delete 10 training dots that sit far away from the decision boundary (deep inside their own class territories) and retrain a linear SVM. What happens to the decision boundary?
Your noisy dataset has a few mislabeled outliers near the boundary. Setting strictness C = 1,000 causes training accuracy to jump while unseen test accuracy drops sharply. Why?
You fit an RBF Kernel SVM with a huge gamma value and see tiny circular bubbles tightly hugging every single training dot (including a lone outlier). What is happening?
Because SVMs measure highway widths and bell-hill distances directly across your chart axes, skipping feature rescaling on mixed-unit columns (like salary in thousands vs. voltage in single digits) can distort the boundary severely.
Common Questions
What are Support Vectors in a Support Vector Machine (SVM)?
What does the C parameter do in an SVM?
What is the Kernel Trick in simple terms?
Do Support Vector Machines require feature scaling?
When should you use an SVM instead of Gradient Boosting or Logistic Regression?
Related Visual Guides
Logistic Regression
How a machine turns clues into clean 0% to 100% probabilities and makes yes/no decisions, from spam filters to bank fraud alerts.
Feature Scaling: Normalization vs Standardization
Why salary in pounds bullies age in years, how Min-Max, Standardization, and RobustScaler compare under outliers, and which models actually care.
Neural Networks & the Perceptron
Demystify neural networks from a single weighted switch to multi-layer perceptrons that solve XOR and approximate any curve.
Written & illustrated by Muhammad Aashir Irshad · Updated December 2026 · Free open-access reference
Cite this guide in a paper, thesis, or course (BibTeX & APA)
@misc{irshad2026supportvectormachines,
author = {Irshad, Muhammad Aashir},
title = {Support Vector Machines (SVM): Interactive Visual Guide},
howpublished = {SeeingML},
year = {2026},
month = {dec},
url = {https://seeingml.com/learn/support-vector-machines/},
note = {Interactive visual guide}
} Irshad, M. A. (2026). Support Vector Machines (SVM): Interactive Visual Guide. SeeingML. https://seeingml.com/learn/support-vector-machines/