The margin it maximises
Many lines separate two classes. An SVM picks the one that stands furthest from both.
- : the weight vector, perpendicular to the boundary.
- : its length.
The boundary is , and the two edges of the margin are where that expression equals and .
Maximising is the same as minimising , which is where the optimisation problem comes from.
The problem, written out
- : the label, written as or rather than 1 or 0.
That constraint says every point sits on the correct side of its own margin edge, which is only possible if the classes are perfectly separable.
Real data is not, so a slack variable lets a point violate its margin and sets the price of doing so.
Large buys a narrow margin that misclassifies little. Small buys a wide margin that tolerates errors, which usually generalises better.
Hinge loss is the same thing unconstrained
A point that is correct and past the margin costs exactly zero, which is what makes the solution depend on so few points.
Those points, the ones sitting on or inside the margin, are the support vectors. Move any other point and the boundary does not shift.
The kernel trick
Solved in its dual form the problem never needs the coordinates of a point, only inner products between pairs of points.
So an inner product in a higher dimensional space can be substituted directly, and the RBF kernel above corresponds to a space with infinitely many dimensions.
The features are never computed. Only the kernel values are, which is why a curved boundary costs no more than a straight one.
sets how far one training point's influence reaches: large makes each point a narrow island and overfits.
One fit, in order
- Choose a kernel and the values of and .
- Solve the dual problem for the coefficients .
- Keep the points whose is greater than zero, which are the support vectors.
- Predict the sign of for a new point.
What it costs
Training is between and in the number of samples, so an SVM is the wrong tool above a few hundred thousand rows.
Distances sit inside the kernel, so unscaled features break it the same way they break k-NN.
It outputs a distance from a boundary and not a probability, so anything calibrated has to be fitted afterwards.