Developed by Vladimir Vapnik and Corinna Cortes in 1995 at AT&T Bell Laboratories, Support Vector Machines (SVMs) are among the most mathematically elegant and powerful supervised learning algorithms in computer science. Grounded in statistical learning theory and convex quadratic programming, SVMs find the single separating boundary that maximizes the geometric distance (margin) to the nearest data points.
For a linearly separable binary classification dataset, infinitely many hyperplanes can separate the two classes without error. However, a boundary that passes too close to training points will generalize poorly on noisy test data.
SVM selects the Maximum Margin Hyperplane — the decision boundary with the largest possible perpendicular distance to the closest training samples. The points that lie directly on the margins are called Support Vectors. Crucially, only the support vectors determine the decision boundary; removing all other data points would leave the hyperplane completely unchanged!
A separating hyperplane is defined by weight vector ( mathbf{w} ) and bias ( b ) as: ( mathbf{w}^T mathbf{x} + b = 0 ). For binary labels ( y in {-1, +1} ), all correctly classified points satisfy:
The total geometric margin between the two parallel bounding planes is ( rac{2}{|mathbf{w}|} ). Maximizing the margin is mathematically equivalent to minimizing ( rac{1}{2} |mathbf{w}|^2 ), formulated as a Convex Quadratic Optimization Problem:
Real-world data is rarely linearly separable. A single outlier can make hard-margin separation impossible. Soft-Margin SVM introduces slack variables ξi ≥ 0 allowing points to violate the margin, controlled by regularization parameter ( C ):
When data is not linearly separable in its original low-dimensional space ( mathbb{R}^d ), Cover's Theorem states that mapping it into a higher-dimensional space ( Phi(mathbf{x}) in mathbb{R}^D ) makes it linearly separable with high probability.
However, explicitly calculating high-dimensional coordinate vectors is computationally intractable. The Kernel Trick observes that SVM optimization depends only on the dot product between pairs of samples: ( langle Phi(mathbf{x}_i), Phi(mathbf{x}_j) angle ). A Kernel Function ( K(mathbf{x}_i, mathbf{x}_j) ) computes this dot product directly in low-dimensional space without ever calculating high-dimensional coordinates!
| Kernel Type | Mathematical Formula | Best Used For |
|---|---|---|
| Linear | ( K(mathbf{x}_i, mathbf{x}_j) = mathbf{x}_i^T mathbf{x}_j ) | High-dimensional data where features exceed samples (e.g., text categorization, genomics). |
| Polynomial | ( K(mathbf{x}_i, mathbf{x}_j) = (gamma mathbf{x}_i^T mathbf{x}_j + r)^d ) | Image recognition and polynomial feature interactions. |
| Radial Basis Function (RBF / Gaussian) | ( K(mathbf{x}_i, mathbf{x}_j) = exp(-gamma |mathbf{x}_i - mathbf{x}_j|^2) ) | Default general-purpose non-linear kernel; maps data into an infinite-dimensional Hilbert space! |
| Sigmoid (Hyperbolic Tangent) | ( K(mathbf{x}_i, mathbf{x}_j) = anh(gamma mathbf{x}_i^T mathbf{x}_j + r) ) | Simulates two-layer perceptron neural networks. |
The following script trains an RBF-Kernel SVM on non-linearly separable concentric circles:
from sklearn.datasets import make_circles
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
# 1. Generate non-linearly separable concentric circular data
X, y = make_circles(n_samples=500, noise=0.1, factor=0.4, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
# 2. Compare Linear Kernel vs Non-Linear RBF Kernel
linear_svm = SVC(kernel='linear')
linear_svm.fit(X_train, y_train)
lin_acc = accuracy_score(y_test, linear_svm.predict(X_test))
rbf_svm = SVC(kernel='rbf', C=1.0, gamma='scale')
rbf_svm.fit(X_train, y_train)
rbf_acc = accuracy_score(y_test, rbf_svm.predict(X_test))
print(f"Linear SVM Accuracy on Circular Data : {lin_acc:.2%} (Fails to separate)")
print(f"RBF Kernel SVM Accuracy (Infinite D) : {rbf_acc:.2%} (Flawless non-linear boundary!)")
print(f"Total Number of Support Vectors Found: {len(rbf_svm.support_)}")
Broaden your foundational and advanced AI knowledge across our curriculum:
Soft-margin SVM vs logistic regression loss formulations.
Compare global hyperplane boundaries with local instance-based learning.
How neural networks superseded kernel SVMs on large datasets.
Kernel trick, support vectors, and slack variable exam questions.