↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Loading the recording…

The widest margin

A support vector machine separates two classes with a boundary and, among all boundaries that separate them, picks the one with the widest empty band around it, the margin. A wide margin means small changes to a point do not change its label, which is why the boundary tends to hold on new data.

This page fits SVMs to a real problem that a straight line cannot solve: telling iris versicolor flowers from the other two species by their petal length and width (Fisher's iris data, as scikit-learn ships it, 105 flowers to fit and 45 held out). Versicolor's petals are bigger than setosa's and smaller than virginica's, so versicolor sits in the middle of the input plane. The linear kernel shows what that costs: the best line it finds calls every flower "not versicolor" and is right 66.7 % of the time, exactly the share of the other two species.

The soft margin and its dual

For points with labels , the SVM looks for a weight vector and offset so that , where the slack lets a point into the margin or across the boundary at a price:

The margin's width is , so the first term widens it and the second, weighted by , keeps points out of it. Solving instead for one multiplier per point gives the dual, which only ever needs dot products between points:

The decision function is , and most come out exactly zero. The points with are the support vectors, ringed on the page; the rest could move anywhere outside the margin without changing the boundary. The Who is a support vector chart shows the rule the solution obeys: right of the point is beyond its margin and ; on that line ; inside it . scikit-learn solves the dual with libsvm, an SMO solver that repeatedly picks the pair of s that most violate these conditions and moves them together; the drawer's PyTorch SMO, started from zero, reaches the same decision function.

The kernel trick

is the kernel: a dot product in a feature space where the points have been lifted by a map . A linear boundary in that space is a curved one in the input plane, and the dual never has to form , only .

For the degree-2 polynomial kernel the map is small enough to write down. With and two inputs it has six coordinates:

so the recorder can build explicitly. Its six numbers are on the page, and matches libsvm's kernel sum over the whole grid to about . The constant feature gets weight zero, because , and the three quadratic weights are negative, which makes largest in the middle of the plane, where versicolor is. The fit gets 95.6 % of the held-out flowers right with 14 support vectors.

Seeing the plane in the lifted space

The lifted space panel draws that six-dimensional space through three of its directions: the two linear coordinates, which are the input coordinates scaled by , and the direction of 's quadratic part. Because lies in this three-dimensional slice, the separating hyperplane is a genuinely flat plane there, and the margin planes are parallel to it. The flowers sit on a curved sheet, the image of the input plane. The plane cuts the sheet along a curve, and that curve, dropped onto the floor, is the boundary in the input plane.

The RBF kernel corresponds to a feature space with infinitely many dimensions, so the panel keeps the one that matters: each point's position along , which is and comes straight from the kernel. The plane is then flat at height and the sheet is a sum of bumps and dips, one per support vector.

What C and γ do

prices slack. A small lets many points into a wide margin, and they all become support vectors; a large narrows the margin until few points are inside it. On the polynomial kernel, uses 30 support vectors and uses 7.

sets the RBF kernel's reach, about in the standardized units. The C and γ grid shows all twenty fits: at with the kernel is so wide that the fit falls back to "never versicolor"; at every support vector's bump is narrow, the boundary wraps single flowers, training accuracy reaches 99 % and test accuracy drops to 88.9 %. In between, a broad range of settings gives the 95.6 % the polynomial kernel reaches.

An explicit map for the RBF kernel

Rahimi and Recht showed that the RBF kernel is an average of cosines: draw and , and satisfies for random features. A plain linear SVM on then approximates the kernel SVM. The RBF with explicit features card fits one for from 10 to 10,000: the largest kernel error on the training flowers falls from 0.75 to 0.016, and the boundary, overlaid in orange, agrees with the exact kernel's on 91.4 % and then 99.8 % of the grid.

Support vector machines grew out of Vapnik's statistical learning theory; Boser, Guyon and Vapnik introduced the kernel trick for them in 1992 and Cortes and Vapnik the soft margin in 1995. A Gaussian process with the same RBF kernel puts a probability on every function instead of one boundary, and an MLP learns its features instead of fixing them.

Papers

  1. Support-vector networks Corinna Cortes, Vladimir Vapnik · Machine Learning 1995 The soft-margin SVM: slack variables priced by C, solved through the dual with kernels.
  2. A training algorithm for optimal margin classifiers Bernhard E. Boser, Isabelle M. Guyon, Vladimir N. Vapnik · COLT 1992 The maximum-margin classifier with the kernel trick: polynomial and RBF kernels in place of explicit features.
  3. LIBSVM Chih-Chung Chang, Chih-Jen Lin · ACM Transactions on Intelligent Systems and Technology 2011 LIBSVM, a library for support vector machines: the SMO-type solver behind scikit-learn's SVC, which fits every model on this page.
  4. Sequential Minimal Optimization: A Fast Algorithm for Training Support Vector Machines John Platt · 1998 Solving the dual two multipliers at a time, in closed form, which the drawer's PyTorch SMO does.
  5. Random Features for Large-Scale Kernel Machines Ali Rahimi, Benjamin Recht · NeurIPS 2007 Random Fourier features: an explicit, finite map whose dot products approximate the RBF kernel.
  6. The use of multiple measurements in taxonomic problems R. A. Fisher · Annals of Eugenics 1936 The iris measurements this page classifies.

See also