Support Vector Machines

A support vector machine (SVM) is a linear classifier. Among all hyperplanes that separate two classes, it picks the one farthest from the nearest training points. SVMs use labels . The classifier scores an input with the linear discriminant

and predicts . Here is the weight vector, normal to the boundary , and is the bias. The signed distance of point to the boundary is . It is positive when the point is classified correctly.

Rescaling and together does not move the boundary. The SVM fixes the scale by requiring , with equality for the closest points. The planes then lie at distance on each side of the boundary. The strip between them is the margin, and its width is . Maximizing the width gives the hard-margin SVM, a quadratic program:

It has a solution only when the classes are linearly separable. The soft-margin SVM adds a slack for each point and a penalty :

The slack measures how far point falls short of the margin. is the price of one unit of slack. At the optimum , so the problem equals an unconstrained hinge-loss problem:

Here is the hinge loss at . Dividing by gives the average hinge loss plus the ridge penalty with .

Each training point falls in one of four groups:

  • Outside the margin: and . Moving the point a little does not change the solution.
  • On the margin: and .
  • Inside the margin: and . The point lies on the boundary or on the correct side, closer than the margin allows.
  • Misclassified: and . Hence is an upper bound on the number of training errors.

The support vectors are the points on the margin, inside it, or misclassified. Removing any other point leaves and unchanged. Large makes slack expensive, and the solution approaches the hard margin. Small allows a wider margin with more violations. is chosen by cross-validation, after standardizing the features. The dual problem is in 4.4a. SVM Dual, and nonlinear boundaries are in 4.4b. Kernel SVM.

Intuition

When a line separates two classes, infinitely many lines do. The perceptron stops at the first one it finds, which may pass close to some training points. A new point near those training points can then fall on the wrong side. The SVM picks the line with the widest empty strip between the classes. The closest training points then sit as far from the boundary as possible. The training points on the edges of the strip are the support vectors, and their positions alone fix the line. “Machine” is an old term for a learning algorithm.

Real data overlap, and one mislabeled point can make the widest strip very narrow or impossible. The soft margin lets some points enter the strip or cross the boundary. Each unit of violation costs . The hinge-loss form gives a second reading of the same model. An SVM is a regularized linear model, like logistic regression, whose loss is zero for every point beyond the margin. Boser, Guyon and Vapnik (1992) introduced the maximum-margin classifier, and Cortes and Vapnik (1995) added the slack variables. ISLR ch. 9, ESL ch. 12 and Bishop ch. 7 give textbook treatments.

Properties

(Hinge Versus Logistic Loss) The hinge loss is exactly zero beyond the margin, which makes the solution sparse but gives no probabilities.

Write . With labels in , logistic regression minimizes , and the SVM minimizes . Both are convex upper bounds on the 0-1 loss , after dividing the logistic loss by . Both grow linearly for very negative , so both tolerate outliers better than squared loss. The logistic loss is positive for every , so every point contributes to the logistic gradient. The hinge loss is zero once , so well-classified points contribute nothing, and only the support vectors remain. The function that minimizes the expected hinge loss is (Lin 2002). This is the Bayes decision, yet itself does not estimate the probability. Platt scaling (Platt 1999) fits a sigmoid to held-out scores when probabilities are needed.

(Choosing C) On separable data a finite reproduces the hard margin, and one outlier can make the hard margin very narrow.

The soft-margin solution equals the hard-margin solution once is at least the largest hard-margin dual multiplier (see 4.4a. SVM Dual). Below that value the soft margin trades training errors for width. A mislabeled point near the other class limits the hard-margin strip to the gap next to that point. The soft margin pays slack for that point instead and keeps a wide strip, as the Hard example shows. multiplies a sum over points, so the same regularizes less on a larger dataset. The parameter does not depend on this way, and stochastic solvers use it. Practitioners search on a logarithmic grid, such as , with cross-validation (Hsu, Chang and Lin 2003).

(Units Matter) Shifting or rotating all inputs leaves the SVM unchanged, while rescaling one feature moves the boundary.

Shifting every input by only changes to , and carries no penalty. A rotation preserves all distances and . Multiplying one feature by stretches distances along that axis, so the widest strip changes. Take a positive point at and a negative point at . The SVM boundary is , and the test point is positive. Now multiply the second feature by , as when it is recorded in other units. In the original units the boundary becomes , and the same test point is negative. Standardizing each feature with the training mean and standard deviation removes this dependence on units.

(Subgradient Training) The hinge-loss form can be minimized by stochastic subgradient descent, which scales to very large .

The hinge loss has a kink at with no gradient. A subgradient there is any slope between the left and right derivatives. Pegasos (Shalev-Shwartz, Singer and Srebro 2007) runs stochastic subgradient descent on . Each step uses one random point . If , the update is . Otherwise it is . Each step costs , and the number of steps for a fixed accuracy does not grow with . The perceptron update is the same step with , , and the threshold replaced by . Pegasos therefore acts like a perceptron that also requires a margin and shrinks its weights. LIBLINEAR (Fan et al. 2008) instead runs coordinate descent on the dual.

(More Than Two Classes) Multi-class SVMs are usually built from binary SVMs, either one class against the rest or one pair at a time.

One-versus-rest trains SVMs, each separating one class from all others, and predicts the class with the largest score . Separately trained SVMs have scores on different scales, so this argmax can be unreliable. The same ambiguity arises with linear discriminants. One-versus-one trains SVMs, one per pair of classes, and predicts by majority vote. For classes that is SVMs, each trained on about a fifth of the data. LIBSVM uses one-versus-one. Crammer and Singer (2001) give a single joint objective with one weight vector per class.

Derivation

The distance from to the hyperplane is , as shown in 4.2. Linear Discriminants. For a correctly classified point this equals . For separable data the maximum-margin problem is therefore

Multiplying and by any leaves every ratio unchanged. We may choose the scale so that the closest point has . All points then satisfy , and the inner minimum equals . Maximizing is the same as minimizing . The square makes the objective differentiable, and the factor removes a from its gradient. The planes and are apart.

For the soft margin, fix and and minimize over the slacks. Each enters the objective with the positive weight , so it takes its smallest feasible value. The constraints and give . Substituting this back yields the hinge-loss form. Each hinge term is a maximum of affine functions of , so it is convex. The penalty is strictly convex in (2.2 Convex Functions). The optimal is therefore unique. The optimal is unique in most problems, with exceptions described in 4.4a. SVM Dual.

Examples

(Easy) Widest Strip Between Four Sensor Readings

A plant monitors machines with two standardized sensor readings. Two faulty machines () read and . Two healthy machines () read and .

(Medium) Hinge Losses of a Spam Filter

A spam filter uses two scaled features and the classifier , with spam as . Five training emails are spam at , and , and legitimate at and .

(Hard) One Mislabeled Machine

Healthy machines () have standardized vibration readings and . Faulty machines () read and . A fifth machine at is labeled faulty, possibly by mistake.

See Also