Kernel SVM

A kernel SVM fits a linear SVM in a feature space without ever computing . Labels are . The dual problem uses the data only through inner products. The kernel trick replaces each with a kernel :

Here are the dual multipliers and is the slack penalty. The weight vector lives in feature space and is never formed. The score and the bias use kernel values only:

Here is a free support vector, with . The boundary is a hyperplane in feature space and a curved surface in input space.

The kernel must be symmetric and positive semidefinite. Every Gram matrix with entries must be PSD. The dual then stays a convex QP, and a feature map exists by Mercer’s theorem (3.10.1 Kernels). Four kernels are common:

  • Linear: , which gives the plain linear SVM.
  • Polynomial: with . For its features are all monomials of degree at most .
  • RBF (Gaussian): with . It is the squared-exponential kernel with for length-scale . Its feature space is infinite-dimensional.
  • Sigmoid: . It is not PSD for all and , so the dual can lose convexity.

The RBF kernel is the usual default. Its hyperparameters and are tuned together by cross-validation on a logarithmic grid. Training uses the Gram matrix and takes between and time. Prediction costs per query for the RBF and polynomial kernels, where is the number of support vectors.

Intuition

A hyperplane in the original inputs cannot separate some classes. A nonlinear map of the inputs can make them separable. For example, a ring of positives around a cluster of negatives becomes separable once is added as a feature. Adding all such features explicitly is expensive. A cubic map of inputs has monomial features. The SVM dual needs only the inner products of the features. A kernel computes each inner product in time. This substitution is the kernel trick.

A kernel value measures how similar two inputs are. The score is then a weighted vote of the support vectors. Each support vector votes for its own label, with weight times its similarity to the query. Boser, Guyon and Vapnik (1992) combined kernels with the maximum-margin classifier. Schölkopf and Smola (2002) and ESL ch. 12 cover the method in depth.

Properties

(Sparse Representer Form) The solution is a weighted sum of kernels centered at the support vectors, which is sparser than kernel ridge regression.

A regularized loss in feature space has a minimizer in the span of . This is the representer theorem (Kimeldorf and Wahba 1971; Schölkopf, Herbrich and Smola 2001). Kernel ridge regression has the same form with coefficients , and generically every coefficient is nonzero. The hinge loss is zero beyond the margin, so most SVM coefficients are exactly zero. Prediction then needs only the support vectors. On noisy data the sparsity is limited, because every misclassified training point is a support vector. The number of support vectors then grows roughly in proportion to (Steinwart 2003).

(Kernel Width) Small makes an RBF SVM nearly linear, and large makes it memorize the training set.

Each support vector affects the score mainly within a distance of about , where its kernel falls to . For large the Gram matrix approaches the identity, and every training point becomes a support vector. The Gaussian Gram matrix of distinct points is positive definite (Micchelli 1986). With large , an RBF SVM can therefore fit any labeling of the training set, which is the overfitting regime. For small the kernel varies slowly. As with growing like , the RBF SVM approaches a linear SVM (Keerthi and Lin 2003). and interact, so they are tuned jointly. A common grid is and (Hsu, Chang and Lin 2003). The scikit-learn default is , with the variance taken over all entries of . Standardized features keep such defaults sensible.

(Far From the Data) An RBF SVM predicts the bias for inputs far from every support vector.

Every RBF kernel value tends to as , so . Far from the data, the sign of alone decides the class. When is small, such queries also sit near the boundary. A query unlike any training input still receives a label, with no warning. A polynomial kernel has the opposite behavior. Its score can grow like far away, so its predictions become extreme. Neither kernel extrapolates reliably. Inputs far from the training data need a separate out-of-distribution check.

(Cost in n) Kernel SVMs become expensive when reaches about , because the Gram matrix has entries.

For the Gram matrix holds numbers, or GB in 64-bit floats. SMO avoids storing it by computing columns on demand and caching recent ones. Its running time still grows between quadratically and cubically in (Bottou and Lin 2007). Prediction is also slow. With support vectors and , each query needs kernel evaluations. That is about multiplications, against for a linear SVM. Two approximations restore linear cost in . Random Fourier features (Rahimi and Recht 2007) map inputs to random cosine features. Their inner products approximate the RBF kernel. The Nyström method (Williams and Seeger 2001) builds a low-rank Gram matrix from sampled points. A linear SVM then trains on either feature set.

Examples

(Easy) The Quadratic Kernel's Hidden Features

A sensor reports two scaled readings per sample. Two samples are and , and the SVM uses the kernel .

(Medium) Staircase Light Switches

A staircase light has one switch at the bottom and one at the top. Each switch is coded (up) or (down). The light is on () when the switches agree and off () when they differ. The training inputs are and with , and and with . No line separates them.

(Hard) Two Greenhouse Readings and the RBF Width

A greenhouse controller learns from two standardized humidity readings. The reading is labeled dry (), and is labeled wet (). The controller uses a hard-margin SVM with the RBF kernel.

See Also