Support Vector Machines & the Kernel Trick
An SVM chooses a separating surface with maximum margin, trading margin violations against model norm when data overlap. Kernel functions express nonlinear similarity through inner products, but scaling, kernel validity, regularization, and probability calibration remain explicit responsibilities.
A support vector machine (SVM) classifies by the sign of a score . Many hyperplanes may separate training classes; the SVM chooses the one with the widest normalized gap to the nearest points. That margin encodes a robustness preference: small perturbations of non-boundary points should not change the decision.
Hard margin geometry #
For labels , scale so the nearest training points satisfy . The hard-margin problem is
The two supporting planes are separated by . Minimizing norm maximizes this width. Only points on the margin constrain the optimum; these are the support vectors.
In one dimension, negative points at and positive points at yield boundary . The support vectors are and , and the margin spans the empty interval between them. Moving farther left changes nothing; moving changes the solution.
Soft margin handles overlap #
Real classes overlap and labels contain errors. Introduce slack variables :
prices violations relative to a wide margin. Large aggressively fits training cases and permits a larger norm; small accepts more violations for a smoother boundary. Equivalent formulations may scale with sample count, so numeric values are not portable across implementations without checking the exact objective.
The unconstrained view uses hinge loss . Correct points outside the margin have zero loss; points inside or beyond the wrong side contribute linearly.
The kernel trick #
The dual optimization depends on feature vectors only through inner products . Replacing them with a kernel
fits a linear separator in an implicit feature space without explicitly constructing . The resulting score is
The radial-basis kernel
makes influence local. Large creates narrow neighbourhoods and a highly flexible boundary; small makes points broadly similar and the boundary smoother. and interact and must be tuned together inside validation.
Not every similarity function is a valid kernel. A valid Gram matrix must satisfy the positive-semidefinite conditions needed to represent inner products and preserve convexity.
Scaling is load-bearing #
RBF distance and linear model norm depend on units. A feature with a large numeric range dominates and changes what “wide margin” means. Fit scaling on training folds only. Sparse text often uses linear SVMs with normalized count features because nonlinear kernel matrices are computationally unnecessary.
Kernel SVM training scales poorly with the number of samples because it operates on pairwise relationships; memory can approach quadratic. Prediction cost grows with the number of support vectors. Linear primal or approximate-kernel methods are more practical for very large datasets.
Scores are not probabilities #
Distance from the decision boundary is a ranking score, not a posterior probability. Probability outputs require a separate fitted calibration mapping and therefore additional held-out or cross-validated data. Calibrate under deployment prevalence; a score calibrated on balanced resampling will not remain a deployment probability automatically.
Multiclass SVMs commonly combine one-vs-rest or one-vs-one binary problems. The choice affects training cost and how scores are reconciled; there is no single native multiclass maximum-margin probability model hidden underneath.
Counterexamples and diagnostics #
- XOR is not linearly separable in its raw coordinates; an interaction feature or nonlinear kernel is required.
- A large-margin separator can still use a leaked feature and fail completely in deployment.
- One mislabeled remote point can distort a large- solution; inspect support vectors and sensitivity to .
- High-dimensional RBF tuning can become meaningless when distances concentrate.
- Kernel flexibility does not provide extrapolation semantics outside observed support.
- “Only support vectors matter” describes the fitted solution, not data governance: preprocessing statistics and hyperparameter choices used other samples too.
SVMs are strongest when margin geometry matches the task, sample size is manageable, and a carefully validated kernel supplies useful structure. The kernel is an assumption about similarity, not a free nonlinear upgrade.