What is a support vector machine (SVM)?
A support vector machine is a classifier that separates two classes with the hyperplane that leaves the widest possible margin to the nearest training points. Those nearest points are the support vectors, and they alone determine the boundary. A soft-margin version tolerates some errors, and kernels let the same method draw curved boundaries.
SVMs were among the most accurate general-purpose classifiers from the late 1990s through the 2000s, used for text categorization, handwritten digit recognition, and bioinformatics tasks such as protein classification. They still work well on small and medium datasets with many features. The ideas they introduced, margins, hinge loss, and kernels, appear across machine learning, from kernel ridge regression to the analysis of neural networks.
Key ideas
- An SVM chooses the separating hyperplane with the widest margin to the nearest points of each class.
- Only the support vectors, the points on or inside the margin, determine the boundary.
- The C parameter trades margin width against training errors in the soft-margin SVM.
- Kernels let an SVM learn nonlinear boundaries by replacing dot products with a similarity function.
- In the RBF kernel, γ sets how far each training point's influence reaches.
- Multi-class SVMs combine several binary classifiers, one-vs-rest or one-vs-one.
Common questions
Is an SVM better than logistic regression?
Neither wins in general. Both learn a linear boundary, but the hinge loss ignores points far from the boundary, while logistic loss uses every point and produces probabilities. With a kernel, an SVM can fit nonlinear boundaries that plain logistic regression cannot. On large tabular datasets, gradient-boosted trees often beat both.
Can an SVM output probabilities?
Not directly. The decision function gives a signed score proportional to the distance from the boundary. Platt scaling fits a sigmoid to those scores on held-out data to turn them into probabilities, and scikit-learn does this when probability=True, at extra training cost.
Do SVMs need feature scaling?
Yes. Both the margin and the RBF kernel depend on distances, so a feature with a large range dominates the rest. Standardizing every feature to zero mean and unit variance is a standard first step.
Can SVMs be used for regression?
Yes. Support vector regression (SVR) fits a function that keeps most points inside a tube of width ε around it and ignores errors smaller than ε. Points on or outside the tube become the support vectors, and the same kernels apply.
Related explainers
- Bias & Decision Boundaries — How bias terms shift activation and shape decision regions
- Constrained Optimization — Lagrange multipliers — optimization with constraints
- Convexity, Minima & Saddle Points — Why some optimization problems are harder than others
- Regularization — Dropout, L1, and L2 — keeping models honest
- K-Nearest Neighbors — Classification by proximity and distance metrics
- Classification vs Regression — Two kinds of prediction and when to use each
References
- Cortes & Vapnik (1995), "Support-Vector Networks", Machine Learning
- Boser, Guyon & Vapnik (1992), "A Training Algorithm for Optimal Margin Classifiers"
- James, Witten, Hastie & Tibshirani, "An Introduction to Statistical Learning", chapter 9: Support Vector Machines
Last updated