In this post we will explore a class of machine learning methods called Support Vector Machines also known commonly as SVM.
SVM is a supervised machine learning algorithm which can be used for both classification and regression.
In the simplest classification problem, given some data points each belonging to one of the two classes, the goal is to decide which class a new data point will be in. A simple linear solution to this problem can be viewed in a framework where a data point is viewed as a p-dimensional vector, and we want to know whether we can separate such points with a (p−1)-dimensional hyperplane.
There are many hyperplanes that might classify the data. One reasonable choice as the best hyperplane is the one that represents the largest separation, or margin, between the two classes. So we choose the hyperplane so that the distance from it to the nearest data point on each side is maximized. If such a hyperplane exists, it is known as the maximum-margin hyperplane and the linear classifier it defines is known as a maximum margin classifier; or equivalently, the perceptron of optimal stability.
The figure on the right is a binary classification problem (points labeled yi=±1) that is linearly separable in space defined by the vector x. Green and purple line separate two classes with a small margin, whereas yellow line separates them with the maximum margin.
Mathematically, for the linearly separable case, any point x lying on the separating hyperplane satisfies: xTw+b=0, where w is the vector normal to the hyperplane, and b is a constant that describes how much plane is shifted relative to the origin. The distance of the hyperplane from the origin is ∥w∥b.
Now draw parallel planes on either side of the decision boundary, so we have what looks like a channel, with the decision boundary as the central line, and the additional planes as gutters. The margin, i.e. the width of the channel, is (d++d−) and is restricted by the data points closest to the boundary, which lie on the gutters. The two bounding hyperplanes of the channel can be represented by a constant shift in the decision boundary. In other words, these planes ensure that all the points are at least a signed distance d away from the decision boundary. The channel region can be also represented by the following equations:xiTw+b≥+a,for yi=+1xiTw+b≤−a,for yi=−1
These conditions can be put more succinctly as:yi(xiTw+b)≥a,∀i
Using the formulation of distance from origin of three hyper planes, we can show that, the margin, M is equivalent to d_++d−=2a/∥w∥. Without any loss of generality, we can set a=1, since it only sets the scale (units) of b and w. So to maximize the margin, we have to maximize 1/∥w∥. Such a non-convex objective function can be avoided if we choose in stead to minimize ∥w∥2.
In summary, for a problem with m numbers of training data points, we need to solve the following quadratic programming problem:maximize Msubject to yi(xiTw+b)≥M,∀ i=1…m
This can be more conveniently put as:minimize f(w)≡21∥w∥2subject to g(w,b)≡−yi(xiTw+b)+1≤0,i=1…m
The maximal margin classifier is a very natural way to perform classification, if a separating hyper plane exists. However, in most real-life cases no separating hyper plane exists, and so there is no maximal margin classifier.
We can extend the concept of a separating hyper plane in order to develop a hyper plane that almost separates the classes, using a so-called soft margin. The generalization of the maximal margin classifier to the non-separable case is known as the support vector classifier.
Assuming the classes overlap in the given feature space. One way to deal with the overlap is to still maximize M, but allow for some points to be on the wrong side of the margin. In order to allow these, we can define the slack variables as, ξ=(ξ1,ξ2…ξm). Now, keeping the above optimization problem as a convex problem, we can modify the constraints as:yi(xiTw+b)≥M(1−ξi),∀ i=1…m,ξi≥0 and i=1∑mξi≤C ∀ i=1…m,
We can think of this formulation in the following context. The value ξi in the constraint yi(xiTw+b)≥M(1−ξi) is the proportional amount by which the prediction f(xi)=xiTw+b is on the wrong side of its margin. Hence by bounding the sum ∑ξi, we can bound the total proportional amount by which predictions fall on the wrong side of their margin. Mis-classifications occur when ξi>1, so bounding ∑ξi at a value K say, bounds the total number of training mis-classifications at K.
Similar to the case of maximum margin classifier, we can rewrite the optimization problem more conveniently as,minimize 21∥w∥2+Ci∑mξisubject to yi(xiTw+b)≥1−ξi, and ξi≥0, i=1…m
Now, the question before us is to find a way to solve this optimization problem efficiently.
The problem above is quadratic with linear constraints, hence is a convex optimization problem. We can describe a quadratic programming solution using Lagrange multipliers and then solving using the Wolfe dual problem.
The Lagrange (primal) function for this problem is:LP=21∥w∥2+Ci∑mξi−i=1∑mαi[yi(xiTw+b)−(1−ξi)]−i=1∑mμiξi,
which we can minimize w.r.t. w, b, and ξi. Setting the respective derivatives to zero, we get,w=i=1∑mαiyixi0=i=1∑mαiyiαi=C−μi,∀i,
as well as the positivity constraints, αi, μi, ξi≥0, ∀i. By substituting these conditions back into the Lagrange primal function, we get the Wolfe dual of the problem as,LD=i=1∑mαi−21i=1∑mj=1∑mαiαjyiyjxiTxj
which gives a lower bound on the original objective function of the quadratic programming problem for any feasible point. We maximize LD subject to 0≤αi≤C and ∑i=1mαiyi=0. In addition to above constraints, the Karush-Kuhn-Tucker (KKT) conditions include the following constraints,αi[yi(xiTw+b)−(1−ξi)]=0,μiξi=0,yi(xiTw+b)−(1−ξi)≥0,
for i=1…m. Together these equations uniquely characterize the solution to the primal and the dual problem.
Let us look at some special properties of the solution. We can see that the solution for w has the forw^=i=1∑mαi^yixi
with nonzero coefficients α^i only for those i for which yi(xiTw+b)−(1−ξi)=0. These i observations are called "support vectors" since w is represented in terms of them alone. Among these support points, some will lie on the edge of the margin (ξ^i=0), and hence characterized by 0<α^i<C; the remainder (ξ^i>0) have α^i=C. Any of these margin points can be used to solve for b. Typically, once can use an average value from all of the solutions from the support points.
In this formulation, C is model hyper parameter and can be used as a regularizer to control the capacity and generalization error of the model.
The support vector classifier described so far finds linear boundaries in the input feature space. As with other linear methods, we can make the procedure more flexible by enlarging the feature space using basis expansions such as polynomials or splines. Generally linear boundaries in the enlarged space achieve better training-class separation, and translate to nonlinear boundaries in the original space. Once the basis functions hi(x),i=1…m are selected, the procedure remains same as before.
Now recall that in calculating the actual classifier, we needed only support vector points, i.e. we need smaller amount of computation if data has better training-class separation. Furthermore, if one looks closely, we can find an additional trick. The separating plane can be given by the function:f(x)=xTw+b=xTi=1∑mαi^yixi+b=i=1∑mαi^yixTxi+b=i=1∑mαi^yi⟨xxi⟩+b
where, ⟨xy⟩ denotes inner product of vectors x and y. This shows us that we can rewrite training phase operations completely in terms of inner products!
If we were to replace linear terms with a predefined non-linear operation h(x), the above formulation of the separating plane will simply modify into:f(x)=h(x)Tw+b=h(x)Ti=1∑mαi^yih(xi)+b=i=1∑mαi^yih(x)Th(xi)+b=i=1∑mαi^yi⟨h(x)h(xi)⟩+b
As before, given αi^, b can be determined by solving yif(xi)=1 for any (or all) xi for which 0<α^i<C. More importantly, this tells us that we do not need to specify the exact nonlinear transformation h(x) at all, rather only the knowledge of the Kernel function K(x,x′)=⟨h(x)h(x′)⟩ that computes inner products in the transformed space is enough. Note that for the dual problem to be convex quadratic programming problem, K would need to be symmetric positive semi-definite.
Some common choices of kernels are:
dth degree polynomial: K(x,x′)=(1+⟨xx′⟩)d
Radial basis: K(x,x′)=exp(−γ∥x−x′∥2)
Neural network: K(x,x′)=tanh(κ1⟨xx′⟩+κ2)
The role of the hyper-parameter C is clearer in an enlarged feature space, since perfect separation is often achievable there. A large value of C will discourage any positive ξi, and lead to an over-fit wiggly boundary in the original feature space; a small value of C will encourage a small value of ∥w∥, which in turn causes f(x) and hence the boundary to be smoother, potentially at the cost of more points as support vectors.
With m training examples, p predictors and M support vectors, the SVM requires M3+Mm+mpM operations. This suggests the choice of the kernel and hence number of support vectors M will play a big role in feasibility of this method. For a really good choice of kernel that leads to very high training-class separation, i.e. M<<<m, the method can be viewed as linear in m. However, for a bad choice case, M≈m we will be looking at an O(m3) algorithm.
The modern incarnation of deep learning was designed to overcome these limitations (large order of computations and clever problem-specific choice of kernels) of kernel machines. We will look at the details of a generic deep learning algorithm in a future post.