The Support Vector Machine (SVM) is a linear classifier that can be viewed as an extension of the Perceptron developed by Rosenblatt in 1958. The Perceptron guaranteed that you find a hyperplane if it exists. The SVM finds the maximum margin separating hyperplane.
Setting: We define a linear classifier: h(x)=sign(wTx+b) and we assume a binary classification setting with labels {+1,−1}.
![]()
Figure 1: (Left:) Two different separating hyperplanes for the same data set. (Right:) The maximum margin hyperplane. The margin, γ, is the distance from the hyperplane (solid line) to the closest points in either class (which touch the parallel dotted lines).
We already saw the definition of a margin in the context of the Perceptron. A hyperplane is defined through w,b as a set of points such that H={x|wTx+b=0}. Let the margin γ be defined as the distance from the hyperplane to the closest point across both classes.
What is the distance of a point x to the hyperplane H?
Consider some point x. Let d be the vector from H to x of minimum length. Let xP be the projection of x onto H. It follows then that:
xP=x−d.
d is parallel to w, so d=αw for some α∈R.
xP∈H which implies wTxP+b=0
therefore wTxP+b=wT(x−d)+b=wT(x−αw)+b=0
which implies α=wTx+bwTw
The length of d:
‖d‖2=√dTd=√α2wTw=|wTx+b|√wTw=|wTx+b|‖w‖2
Margin of H with respect to D:
γ(w,b)=minx∈D|wTx+b|‖w‖2
By definition, the margin and hyperplane are scale invariant: γ(βw,βb)=γ(w,b),∀β≠0
Note that if the hyperplane is such that γ is maximized, it must lie right in the middle of the two classes. In other words, γ must be the distance to the closest point within both classes. (If not, you could move the hyperplane towards data points of the class that is further away and increase γ, which contradicts that γ is maximized.)
These constraints are still hard to deal with, however luckily we can show that (for the optimal solution) they are equivalent to a much simpler formulation. (Makes sure you know how to prove that the two sets of constraints are equivalent.) minw,bwTws.t. ∀i yi(wTxi+b)≥1
This new formulation is a quadratic optimization problem. The objective is quadratic and the constraints are all linear. We can be solve it efficiently with any QCQP (Quadratically Constrained Quadratic Program) solver. It has a unique solution whenever a separating hyper plane exists. It also has a nice interpretation: Find the simplest hyperplane (where simpler means smaller w⊤w) such that all inputs lie at least 1 unit away from the hyperplane on the correct side.
For the optimal w,b pair, some training points will have tight constraints, i.e. yi(wTxi+b)=1.
If the data is low dimensional it is often the case that there is no separating hyperplane between the two classes. In this case, there is no solution to the optimization problems stated above. We can fix this by allowing the constraints to be violated ever so slight with the introduction of slack variables: minw,bwTw+C∑ni=1ξis.t. ∀i yi(wTxi+b)≥1−ξi∀i ξi≥0
Let us consider the value of ξi for the case of C≠0. Because the objective will always try to minimize ξi as much as possible, the equation must hold as an equality and we have: ξi={ 1−yi(wTxi+b) if yi(wTxi+b)<10 if yi(wTxi+b)≥1
![]()
Figure 2: The five plots above show different boundary of hyperplane and the optimal hyperplane separating example data, when C=0.01, 0.1, 1, 10, 100.