🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
Search courses…
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Support Vector Machines — Complete Guide

ML FoundationsClassification🟢 Free Lesson

Advertisement

Supervised Learning

Finding the Optimal Boundary — Maximum Margin Classification

SVM finds the hyperplane that maximizes the margin between classes. It is theoretically elegant and powerful in high-dimensional spaces.

  • Maximum Margin — The widest possible gap between classes
  • Kernel Trick — Nonlinear classification without explicit transformation
  • Support Vectors — The critical points that define the decision boundary

"The art of discovery consists of seeing what everyone has seen and thinking what nobody has thought."

Support Vector Machines — Complete Guide

SVM finds the optimal hyperplane that maximizes the margin between classes. It is one of the most theoretically elegant ML algorithms.


Maximum Margin Classifier

SVM: Maximum Margin Hyperplane and Support Vectorsw·x + b = 0w·x + b = −1w·x + b = +1margin = 2/‖w‖Class −1Class +1SVM OptimizationPrimal Problem:min ½‖w‖²s.t. y⁽ⁱ⁾(w·x⁽ⁱ⁾+b) ≥ 1Dual Problem (Lagrange):max Σαᵢ − ½ΣᵢΣⱼ αᵢαⱼy⁽ⁱ⁾y⁽ʲ⁾K(x⁽ⁱ⁾,x⁽ʲ⁾)s.t. 0 ≤ αᵢ ≤ C, Σαᵢy⁽ⁱ⁾ = 0Support Vectors:Points where αᵢ > 0 (margin boundary)Only SVs determine the decision boundary!

Soft Margin SVM


The Kernel Trick

The Kernel Trick: Mapping to Higher DimensionsOriginal Space (2D)Not linearly separableφ(x)Higher Dimension (3D)Now linearly separable!Separating plane

Kernel Decision Boundaries

SVM Kernel Comparison on Same DataLinearK(x,z) = x·zPolynomial (d=3)K(x,z) = (x·z + 1)³RBF (γ=1)K(x,z) = exp(-γ‖x-z‖²)Effect of CC=0.01Wide marginC=1.0BalancedC=100Narrow margin

Python Implementation

from sklearn.svm import SVC
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline

# Linear SVM
pipe_linear = Pipeline([
    ('scaler', StandardScaler()),
    ('svm', SVC(kernel='linear', C=1.0))
])
pipe_linear.fit(X_train, y_train)
print(f"Linear: {pipe_linear.score(X_test, y_test):.3f}")

# RBF SVM (default)
pipe_rbf = Pipeline([
    ('scaler', StandardScaler()),
    ('svm', SVC(kernel='rbf', C=1.0, gamma='scale'))
])
pipe_rbf.fit(X_train, y_train)
print(f"RBF: {pipe_rbf.score(X_test, y_test):.3f}")

Key Takeaways


What to Learn Next

-> Logistic Regression Classification with probability — from linear to sigmoid.

-> Naive Bayes Bayes' theorem in action — fast, simple, surprisingly powerful.

-> Dimensionality Reduction Reduce features while preserving information with PCA and t-SNE.

Need Expert Machine Learning Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement