Given a supervised classification problem with the set of N training examples along with the class labels , i.e. , we need to build a model to predict the class label for an unseen example. Some of the algorithms we have already encountered and some we will encounter in later posts such as the Logistic Regression, Naive Bayes, Adaboost, Gradient Boosting, KNN, Support Vector Machines, Neural Networks etc. In this post we will discuss about the Support Vector Machine (SVM) methodology.

Given a binary classification problem, , intuitively think of the SVM method as a geometric model of constructing an M dimensional hyperplane (M being the dimension of each training example ) that separates the examples belonging to one class from another, obviously assuming that the training examples could be separated with an M-dimensional hyperplane. In scenarios where the training examples cannot be separated in the original M-dimensional hyperspace, the training examples are transformed into a higher dimensional hyperspace through Kernel transformation, where the examples becomes separable.

Above is diagrammatic representation of the SVM . For purpose of simplicity, we are showing a 2-D space. The solid dots represent one class of examples whereas the hollow dots represents the other class of examples. The solid line represents the separating hyperplane. The confidence of classification for an example is proportional to the distance of the example from the separating hyperplane, i.e. examples which are far away from the separating hyperplane are classified more confidently compared to examples near the hyperplane.

The goal is to find the optimal hyperplane given the training examples, such that the margins from the closest training examples on either side to the hyperplane is maximized. In the above example, the dashed lines on either side of the separating hyperplane represents the margins on either side. The training examples closest to the hyperplane on either side are known as the Support Vectors. We will see later that only the support vectors matter for prediction unlike in K-Nearest Neighbors which requires all the training examples for predicting unseen examples.

The equation of the hyperplane :

where is the M-dimensional non-zero vector perpendicular to the hyperplane. Thus the model for a binary classification problem is defined to be :

where denotes the sign of , i.e.

if 0" /> and if

Given this definition, the classification confidence or the margin is defined to be :

0" />

The above quantity is always greater than 0 for a correct prediction, moreover the corresponding exact value of the quantity gives an estimate of confidence in the prediction. Choose the hyperplane in a way such that the equation of the margins on either side becomes :

or

Using the formula to find the distance between two planes (the hyperplane and the margin), we get that the distance of any training example lying on one of the margins i.e. support vectors from the hyperplane :

The goal is to maximize this margin. Since the margins are given by the equation , thus the classification confidence for any instance is now lower bounded by 1, i.e.

.

Since the objective function is non-convex, we notice that maximizing amounts to minimizing (w is a non-zero vector, hence is defined at all points). Thus we now have a convex optimization problem (Quadratic Programming) :

minimize

subject to for i=1 to N

The above convex optimization problem has a global solution if the N training examples are linearly separable by the optimal hyperplane. The Lagrangian of the QP is defined to be :

for

To minimize the Lagrangian w.r.t. w and b, we need to take the derivative of the Lagrangian for each variable and set them to zero, i.e. and .

Setting , we get :

which implies that, .

Similarly setting , we get :

Substituting back the values into the Lagrangian, we get :

W.r.t. the Lagrange parameters, we can formulate the dual optimization problem as :

maximize " />

subject to : and

where the term " /> in the dual objective function represents the inner product of the vectors and .

To satisfy the KKT conditions, we also need that:

for optimal solutions and for all i=1 to N. If 0" /> for any training example, then we need to have for these examples. This is only possible if these examples lies on the margin i.e. the support vectors. Or in other words only for support vectors, we have 0" />. For any other examples, we have 0" /> or and hence for these examples .

In order to predict the class label for any unseen example X, we compute . From the above, we have seen that to satisfy the KKT conditions, for training examples . Thus

+ b" />

Since 0" /> only for being the support vectors and 0 otherwise, hence we compute the inner product of the test example with only the support vectors and then take the sign of it to determine the class label. This is unlike in KNN where we compute the inner product of the test example with all other training examples. Thus SVM prediction is much faster.

We have not yet solved for the dual optimization problem. There is a technique called the Sequential Minimal Optimization (SMO) which is used to solve the dual optimization problem and find out the optimal values for , and . We will discuss about the algorithm in a later post. In the meantime we will explore SVM for the cases where the training examples are not linearly separable in the original M-dimensional input space. The following two methods are popularly used :

- Kernel transformation to higher dimensional feature space.
- Regularization.

In Kernel transformation, the training examples are transformed from the original M-dim input space to a higher dimensional feature space . The assumption is that examples which are not linearly separable in the original input space, becomes linearly separable when transformed to a higher dimension. In the transformed feature space, the SVM model is defined to be :

+ b)=sgn(\sum_{i=1}^N\alpha^*_iy_iK(X_i, X) + b)" />

where is the Kernel function.

Notice that we are working with the inner product of the transformed features. It is much easier to compute the kernel functions compared to computing the individual transformations and and then computing their inner product.

For example consider the Kernel function :

Assuming that and are M-dim vectors, finding requires O(M) operations. Notice that if the transformation function is defined as :

Then the inner product :

which is the same as computing the kernel directly. Computing using the above method requires operations. The commonly used kernel functions in SVM are the polynomial kernel and radial kernels. Whereas polynomial kernels takes the form :

where 'd' is the degree of the polynomial,

radial basis kernels are represented as :

Among the two, the radial basis kernel is the preferred choice in most difficult classification problems whereas for applications with hard bounds on running time, the polynomial kernel is generally chosen and speed is given priority over accuracy. Although with a lower degree polynomial kernel, the time complexity is less, but since the radial basis function represents a infinite degree polynomial (Taylor expansion of ), most difficult to separate classes in the input space are quite well separated by a hyperplane in the transformed feature space given by the radial basis kernels.

But how to know whether a chosen function is a valid kernel function or not. If is a valid kernel function then for any two examples and ,we have

i.e. if we create the Kernel Matrix K, where then it must be symmetric, . Also for any vector , we have :

i.e. the symmetric matrix K must also be positive semidefinite. Thus the necessary and sufficient condition for the function to be a valid kernel function is that the matrix must be symmetric positive semidefinite. This is known as Mercer's theorem. Thus we can experiment with different kernel functions as long as they satisfy the above conditions.

Whereas kernel transformation of the examples from the original input space to a higher dimensional feature space can help us to find a separating hyperplane, but many times in order to model examples not separable by hyperplanes in lower dimensions, we tend to model noise with high dimensional hyperplanes. To effectively handle this situation, we use the regularization technique.

The regularized Quadratic programming problem is formulated as :

minimize for some constant C > 0

subject to : for i=1 to N

and

The margins are now soft margins as it allows examples (possible noises and outliers) to have margins less than 1. For each example whose margin is less than 1, i.e. 0" />, the objective loss function is penalized by an additional term of .

Categories: MACHINE LEARNING