# Support Vector Machines

Support vector machines (SVMs) are a set of related supervised learning methods that analyze data and recognize patterns, used for classification and regression analysis. The original SVM algorithm was invented by Vladimir Vapnik and the current standard incarnation (soft margin) was proposed by Corinna Cortes and Vladimir Vapnik. The standard SVM is a non-probabilistic binary linear classifier, i.e. it predicts, for each given input, which of two possible classes the input is a member of. Since an SVM is a classifier, then given a set of training examples, each marked as belonging to one of two categories, an SVM training algorithm builds a model that predicts whether a new example falls into one category or the other. Intuitively, an SVM model is a representation of the examples as points in space, mapped so that the examples of the separate categories are divided by a clear gap that is as wide as possible. New examples are then mapped into that same space and predicted to belong to a category based on which side of the gap they fall on.
More formally, a support vector machine constructs a hyperplane or set of hyperplanes in a high or infinite dimensional space, which can be used for classification, regression or other tasks. Intuitively, a good separation is achieved by the hyperplane that has the largest distance to the nearest training data points of any class (so-called functional margin), since in general the larger the margin the lower the generalization error of the classifier.
Whereas the original problem may be stated in a finite dimensional space, it often happens that in that space the sets to be discriminated are not linearly separable. For this reason it was proposed that the original finite dimensional space be mapped into a much higher dimensional space presumably making the separation easier in that space. SVM schemes use a mapping into a larger space so that cross products may be computed easily in terms of the variables in the original space making the computational load reasonable. The cross products in the larger space are defined in terms of a kernel function $K(x,y)$ which can be selected to suit the problem. The hyperplanes in the large space are defined as the set of points whose cross product with a vector in that space is constant. The vectors defining the hyperplanes can be chosen to be linear combinations with parameters $\alpha _{i}$ of images of feature vectors which occur in the data base. With this choice of a hyperplane the points x in the feature space which are mapped into the hyperplane are defined by the relation: $\sum _{i}{\alpha _{i}K(x_{i},x)}=constant$ Note that if $K(x,y)$ becomes small as $y$ grows further from $x$, each element in the sum measures the degree of closeness of the test point $x$ to the corresponding data base point $x_{i}$. In this way the sum of kernels above can be used to measure the relative nearness of each test point to the data points originating in one or the other of the sets to be discriminated. Note the fact that the set of points $x$ mapped into any hyperplane can be quite convoluted as a result allowing much more complex discrimination between sets which are far from convex in the original space.

## Motivation

Statistical classification|Classifying data is a common task in machine learning. Suppose some given data points each belong to one of two classes, and the goal is to decide which class a new data point will be in. In the case of support vector machines, a data point is viewed as a $p$-dimensional vector (a list of $p$ numbers), and we want to know whether we can separate such points with a $p-1$-dimensional hyperplane. This is called a linear classifier. 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.

## Formalization

We are given some training data ${\mathcal {D}}$, a set of n points of the form
    ${\mathcal {D}}=\left\{(\mathbf {x} _{i},c_{i})\mid \mathbf {x} _{i}\in \mathbb {R} ^{p},\,c_{i}\in \{-1,1\}\right\}_{i=1}^{n}$
where the c$_i$ is either 1 or -1, indicating the class to which the point $\mathbf {x} _{i}$ belongs. Each $\mathbf {x} _{i}$ is a $p$-dimensional real number|real vector. We want to find the maximum-margin hyperplane that divides the points having $c_{i}=1$ from those having $c_{i}=-1$. Any hyperplane can be written as the set of points $\mathbf {x}$ satisfying
    $\mathbf {w} \cdot \mathbf {x} -b=0,\,$
where $\cdot$ denotes the dot product. The vector ${\mathbf {w} }$ is a Surface normal | normal vector: it is perpendicular to the hyperplane. The parameter ${\tfrac {b}{\|\mathbf {w} \|}}$ determines the offset of the hyperplane from the origin along the normal vector ${\mathbf {w} }$.
We want to choose the ${\mathbf {w} }$ and $b$ to maximize the margin, or distance between the parallel hyperplanes that are as far apart as possible while still separating the data. These hyperplanes can be described by the equations
    $\mathbf {w} \cdot \mathbf {x} -b=1\,$
and
    $\mathbf {w} \cdot \mathbf {x} -b=-1.\,$
Note that if the training data are linearly separable, we can select the two hyperplanes of the margin in a way that there are no points between them and then try to maximize their distance. By using geometry, we find the distance between these two hyperplanes is ${\tfrac {2}{\|\mathbf {w} \|}}$, so we want to minimize $\|\mathbf {w} \|$. As we also have to prevent data points falling into the margin, we add the following constraint: for each $i$ either
    $\mathbf {w} \cdot \mathbf {x} _{i}-b\geq 1\qquad {\text{ for }}\mathbf {x} _{i}$ of the first class
or
    $\mathbf {w} \cdot \mathbf {x} _{i}-b\leq -1\qquad {\text{ for }}\mathbf {x} _{i}$ of the second.
This can be rewritten as:
    $c_{i}(\mathbf {w} \cdot \mathbf {x} _{i}-b)\geq 1,\quad {\text{ for all }}1\leq i\leq n.\qquad \qquad (1)$
We can put this together to get the optimization problem:
Minimize (in ${\mathbf {w} ,b}$)
    $\|\mathbf {w} \|$
subject to (for any $i=1,\dots ,n$)
    $c_{i}(\mathbf {w} \cdot \mathbf {x_{i}} -b)\geq 1.\,$

### Biased and unbiased hyperplanes

For simplicity reasons, sometimes it is required that the hyperplane passes through the origin of the coordinate system. Such hyperplanes are called unbiased, whereas general hyperplanes not necessarily passing through the origin are called biased. An unbiased hyperplane can be enforced by setting $b=0$ in the primal optimization problem. The corresponding dual is identical to the dual given above without the equality constraint
    $\sum _{i=1}^{n}\alpha _{i}c_{i}=0.$

### Transductive support vector machines

Transductive support vector machines extend SVMs in that they could also treat partially labeled data in semi-supervised learning. Here, in addition to the training set ${\mathcal {D}}$, the learner is also given a set
    ${\mathcal {D}}^{\star }=\{\mathbf {x} _{i}^{\star }|\mathbf {x} _{i}^{\star }\in \mathbb {R} ^{p}\}_{i=1}^{k}\,$
of test examples to be classified. Formally, a transductive support vector machine is defined by the following primal optimization problem:
Minimize (in ${\mathbf {w} ,b,\mathbf {c^{\star }} }$)
    ${\frac {1}{2}}\|\mathbf {w} \|^{2}$
subject to (for any $i=1,\dots ,n$ and any $j=1,\dots ,k$)
    $c_{i}(\mathbf {w} \cdot \mathbf {x_{i}} -b)\geq 1,\,$
    $c_{j}^{\star }(\mathbf {w} \cdot \mathbf {x_{j}^{\star }} -b)\geq 1,$
and
    $c_{j}^{\star }\in \{-1,1\}.\,$
Transductive support vector machines were introduced by Vladimir Vapnik in 1998.

## Properties

SVMs belong to a family of generalized linear classifiers. They can also be considered a special case of Tikhonov regularization. A special property is that they simultaneously minimize the empirical classification error and maximize the geometric margin; hence they are also known as maximum margin classifiers.
A comparison of the SVM to other classifiers has been made by Meyer, Leisch and Hornik.

## Extensions to the linear SVM
### Soft margin

In 1995, Corinna Cortes and Vladimir Vapnik suggested a modified maximum margin idea that allows for mislabeled examples. If there exists no hyperplane that can split the "yes" and "no" examples, the Soft Margin method will choose a hyperplane that splits the examples as cleanly as possible, while still maximizing the distance to the nearest cleanly split examples. The method introduces slack variables, $\xi _{i}$, which measure the degree of misclassification of the datum $x_{i}$
    $c_{i}(\mathbf {w} \cdot \mathbf {x_{i}} -b)\geq 1-\xi _{i}\quad 1\leq i\leq n.\quad \quad (2)$
The objective function is then increased by a function which penalizes non-zero $\xi _{i}$, and the optimization becomes a trade off between a large margin, and a small error penalty. If the penalty function is linear, the optimization problem becomes:
    $\min _{\mathbf {w} ,\mathbf {\xi } }\left\{{\frac {1}{2}}\|\mathbf {w} \|^{2}+C\sum _{i=1}^{n}\xi _{i}\right\}$
subject to (for any $i=1,\dots n$)
    $c_{i}(\mathbf {w} \cdot \mathbf {x_{i}} -b)\geq 1-\xi _{i},~~~~\xi _{i}\geq 0.$
This constraint in (2) along with the objective of minimizing $\|\mathbf {w} \|$ can be solved using Lagrange multipliers as done above. One has then to solve the following problem
    $\min _{\mathbf {w} ,\mathbf {\xi } ,b}\max _{{\boldsymbol {\alpha }},{\boldsymbol {\beta }}}\left\{{\frac {1}{2}}\|\mathbf {w} \|^{2}+C\sum _{i=1}^{n}\xi _{i}-\sum _{i=1}^{n}{\alpha _{i}[c_{i}(\mathbf {w} \cdot \mathbf {x_{i}} -b)-1+\xi _{i}]}-\sum _{i=1}^{n}\beta _{i}\xi _{i}\right\}$
with $\alpha _{i},\beta _{i}\geq 0$.
The key advantage of a linear penalty function is that the slack variables vanish from the dual problem, with the constant C appearing only as an additional constraint on the Lagrange multipliers. For the above formulation and its huge impact in practice, Corinna Cortes|Cortes and Vladimir Vapnik|Vapnik received the 2008 Paris Kanellakis Award|ACM Paris Kanellakis Award. Non-linear penalty functions have been used, particularly to reduce the effect of outliers on the classifier, but unless care is taken, the problem becomes non-convex, and thus it is considerably more difficult to find a global solution.

### Non-linear classification

The original optimal hyperplane algorithm proposed by Vladimir Vapnik in 1963 was a linear classifier. However, in 1992, Bernhard Boser, Isabelle Guyon and Vapnik suggested a way to create non-linear classifiers by applying the kernel trick (originally proposed by Aizerman et al. ) to maximum-margin hyperplanes. The resulting algorithm is formally similar, except that every dot product is replaced by a non-linear kernel (integral operator)|kernel function. This allows the algorithm to fit the maximum-margin hyperplane in a transformed feature space. The transformation may be non-linear and the transformed space high dimensional; thus though the classifier is a hyperplane in the high-dimensional feature space, it may be non-linear in the original input space.
If the kernel used is a Gaussian radial basis function also known as RBF, the corresponding feature space is a Hilbert space of infinite dimension. Maximum margin classifiers are well regularization (mathematics)|regularized, so the infinite dimension does not spoil the results. Some common kernels include,
* Homogeneous polynomial|Polynomial (homogeneous): $k(\mathbf {x_{i}} ,\mathbf {x_{j}} )=(\mathbf {x_{i}} \cdot \mathbf {x_{j}} )^{d}$
* Polynomial (inhomogeneous): $k(\mathbf {x_{i}} ,\mathbf {x_{j}} )=(\mathbf {x_{i}} \cdot \mathbf {x_{j}} +1)^{d}$
* Gaussian or Radial Basis Function: $k(\mathbf {x_{i}} ,\mathbf {x_{j}} )=\exp(-\gamma \|\mathbf {x_{i}} -\mathbf {x_{j}} \|^{2})$, for $\gamma >0$. Sometimes parametrized using $\gamma =1/{2\sigma ^{2}}$
* Hyperbolic function|Hyperbolic tangent: $k(\mathbf {x_{i}} ,\mathbf {x_{j}} )=\tanh(\kappa \mathbf {x_{i}} \cdot \mathbf {x_{j}} +c)$, for some (not every) $\kappa >0$ and $c<0$
The kernel is related to the transform $\varphi (\mathbf {x_{i}} )$ by the equation $k(\mathbf {x_{i}} ,\mathbf {x_{j}} )=\varphi (\mathbf {x_{i}} )\cdot \varphi (\mathbf {x_{j}} )$. The value w is also in the transformed space, with $\textstyle \mathbf {w} =\sum _{i}\alpha _{i}c_{i}\varphi (\mathbf {x} _{i}).$ Dot products with w for classification can again be computed by the kernel trick, i.e. $\textstyle \mathbf {w} \cdot \varphi (\mathbf {x} )=\sum _{i}\alpha _{i}c_{i}k(\mathbf {x} _{i},\mathbf {x} )$. However, there does not in general exist a value w' such that $\mathbf {w} \cdot \varphi (\mathbf {x} )=k(\mathbf {w'} ,\mathbf {x} ).$

### Parameter selection

The effectiveness of SVM depends on the selection of kernel, kernel's parameters and soft margin parameter C.
A common choice is a gaussian kernel, which has a single parameter ?. Best combination of C and ? is often selected by a grid-search with exponentially growing sequences of C and ?, for example, $C\in \{2^{-5},2^{-3},\dots ,2^{13},2^{15}\}$; $\gamma \in \{2^{-15},2^{-13},\dots ,2^{1},2^{3}\}$. Each pair of parameters is checked using cross validation, and the parameters with best cross validation accuracy are picked. The final model, which is used for testing and classifying new data, is then trained on the whole training set using the selected parameters.

## Issues

Potential drawbacks of the SVM are the following two aspects:
* Uncalibrated Class membership probabilities
* The SVM is only directly applicable for two-class tasks. Therefore, algorithms that reduce the multi-class task to several binary problems have to be applied, see the Multi-class SVM section.

## Multiclass SVM

Multiclass SVM aims to assign labels to instances by using support vector machines, where the labels are drawn from a finite set of several elements. The dominating approach for doing so is to reduce the single multiclass problem into multiple binary classification problems. Each of the problems yields a binary classifier, which is assumed to produce an output function that gives relatively large values for examples from the positive class and relatively small values for examples belonging to the negative class. Two common methods to build such binary classifiers are where each classifier distinguishes between (i) one of the labels to the rest (one-versus-all) or (ii) between every pair of classes (one-versus-one). Classification of new instances for one-versus-all case is done by a winner-takes-all strategy, in which the classifier with the highest output function assigns the class (it is important that the output functions be calibrated to produce comparable scores). For the one-versus-one approach, classification is done by a max-wins voting strategy, in which every classifier assigns the instance to one of the two classes, then the vote for the assigned class is increased by one vote, and finally the class with most votes determines the instance classification.

## Structured SVM

SVMs have been generalized to Structured SVM, where the label space is structured and of possibly infinite size.

## Regression

A version of SVM for regression analysis|regression was proposed in 1996 by Vladimir Vapnik, Harris Drucker, Chris Burges, Linda Kaufman and Alex Smola. This method is called support vector regression (SVR). The model produced by support vector classification (as described above) depends only on a subset of the training data, because the cost function for building the model does not care about training points that lie beyond the margin. Analogously, the model produced by SVR depends only on a subset of the training data, because the cost function for building the model ignores any training data close to the model prediction (within a threshold $\epsilon$). There is also a least squares version of support vector machine (SVM) called least squares support vector machine (LS-SVM) proposed in Suykens and Vandewalle.

## Implementation

The parameters of the maximum-margin hyperplane are derived by solving the optimization. There exist several specialized algorithms for quickly solving the QP problem that arises from SVMs, mostly reliant on heuristics for breaking the problem down into smaller, more-manageable chunks. A common method for solving the QP problem is Platt's Sequential Minimal Optimization (SMO) algorithm, which breaks the problem down into 2-dimensional sub-problems that may be solved analytically, eliminating the need for a numerical optimization algorithm.
Another approach is to use an interior point method that uses Newton-like iterations to find a solution of the Karush-Kuhn-Tucker conditions of the primal and dual problems. Instead of solving a sequence of broken down problems, this approach directly solves the problem as a whole. To avoid solving a linear system involving the large kernel matrix, a low rank approximation to the matrix is often used to use the kernel trick.

## SVM Platform

Currently there exist several data science platforms that provide implementation, training, validation and testing for SVM algorithm. The following are some examples:
* Anaconda (Python 2.7, 3.5) (scikit learn)
* Matlab (Statistics and Machine Learning Toolbox)

## References

* ↑ Corinna Cortes and V. Vapnik, "Support-Vector Networks", Machine Learning, 20, 1995. http://www.springerlink.com/content/k238jx04hm87j80g/
* ↑ David Meyer, Friedrich Leisch, and Kurt Hornik. The support vector machine under test. Neurocomputing 55(1-2): 169-186, 2003 http://dx.doi.org/10.1016/S0925-2312(03)00431-4
* ↑ Corinna Cortes and V. Vapnik, "Support-Vector Networks", Machine Learning, 20, 1995. http://www.springerlink.com/content/k238jx04hm87j80g/
* ↑ ACM Website, Press release of March 17th 2009. http://www.acm.org/press-room/news-releases/awards-08-groupa
* ↑ M. Aizerman, E. Braverman, and L. Rozonoer (1964). "Theoretical foundations of the potential function method in pattern recognition learning". Automation and Remote Control. 25: 821–837.{{cite journal}}: CS1 maint: multiple names: authors list (link)
* ↑ B. E. Boser, I. M. Guyon, and V. N. Vapnik. A training algorithm for optimal margin classifiers. In D. Haussler, editor, 5th Annual ACM Workshop on COLT, pages 144-152, Pittsburgh, PA, 1992. ACM Press
* ↑ Template:Cite techreport
* ↑ Harris Drucker, Chris J.C. Burges, Linda Kaufman, Alex Smola and Vladimir Vapnik (1997). "Support Vector Regression Machines". Advances in Neural Information Processing Systems 9, NIPS 1996, 155-161, MIT Press.
* ↑ Suykens J.A.K., Vandewalle J., Least squares support vector machine classifiers, Neural Processing Letters, vol. 9, no. 3, Jun. 1999, pp. 293-300.
* ↑ M. Ferris, and T. Munson (2002). "Interior-point methods for massive support vector machines". SIAM Journal on Optimization. 13: 783–804. doi:10.1137/S1052623400374379.

## External links

* A Tutorial on Support Vector Machines for Pattern Recognition by Christopher J. C. Burges. Data Mining and Knowledge Discovery 2:121–167, 1998
* www.kernel-machines.org (general information and collection of research papers)
* www.support-vector-machines.org (Literature, Review, Software, Links related to Support Vector Machines — Academic Site)
* videolectures.net (SVM-related video lectures)
* Animation clip: SVM with polynomial kernel visualization.
* A very basic SVM tutorial for complete beginners by Tristan Fletcher .
* svmtutorial.online A simple introduction to SVM, easily accessible to anyone with basic background in mathematics
* www.shogun-toolbox.org (Shogun (toolbox) contains about 20 different implementations of SVMs)
* libsvm libsvm is a library of SVMs which is actively patched
* liblinear liblinear is a library for large linear classification including some SVMs
* flssvm flssvm is a least squares svm implementation written in fortran
* Shark Shark is a C++ machine learning library implementing various types of SVMs
* dlib dlib is a C++ library for working with kernel methods and SVMs

## Bibliography

* Sergios Theodoridis and Konstantinos Koutroumbas "Pattern Recogntition", 4th Edition, Academic Press, 2009.
* Nello Cristianini and John Shawe-Taylor. An Introduction to Support Vector Machines and other kernel-based learning methods. Cambridge University Press, 2000. ISBN 0-521-78019-5 ( SVM Book)
* Huang T.-M., Kecman V., Kopriva I. (2006), Kernel Based Algorithms for Mining Huge Data Sets, Supervised, Semi-supervised, and Unsupervised Learning, Springer-Verlag, Berlin, Heidelberg, 260 pp. 96 illus., Hardcover, ISBN 3-540-31681-7
* Vojislav Kecman: "Learning and Soft Computing — Support Vector Machines, Neural Networks, Fuzzy Logic Systems", The MIT Press, Cambridge, MA, 2001.
* Bernhard Schölkopf and A. J. Smola: Learning with Kernels. MIT Press, Cambridge, MA, 2002. (Partly available on line: .) ISBN 0-262-19475-9
* Bernhard Schölkopf, Christopher J.C. Burges, and Alexander J. Smola (editors). "Advances in Kernel Methods: Support Vector Learning". MIT Press, Cambridge, MA, 1999. ISBN 0-262-19416-3.
* John Shawe-Taylor and Nello Cristianini. Kernel Methods for Pattern Analysis. Cambridge University Press, 2004. ISBN 0-521-81397-2 ( Kernel Methods Book)
* Ingo Steinwart and Andreas Christmann. Support Vector Machines. Springer-Verlag, New York, 2008. ISBN 978-0-387-77241-7 ( SVM Book)
* P.J. Tan and D.L. Dowe (2004), MML Inference of Oblique Decision Trees, Lecture Notes in Artificial Intelligence (LNAI) 3339, Springer-Verlag, pp1082-1088. (This paper uses minimum message length (Minimum Message Length|MML) and actually incorporates probabilistic support vector machines in the leaves of Decision tree learning|decision trees.)
* Vladimir Vapnik. The Nature of Statistical Learning Theory. Springer-Verlag, 1995. ISBN 0-387-98780-0
* Vladimir Vapnik, S.Kotz "Estimation of Dependences Based on Empirical Data" Springer, 2006. ISBN 0387308652, 510 pages [this is a reprint of Vapnik's early book describing philosophy behind SVM approach. The 2006 Appendix describes recent development].
* Dmitriy Fradkin and Ilya Muchnik "Support Vector Machines for Classification" in J. Abello and G. Carmode (Eds) "Discrete Methods in Epidemiology", DIMACS Series in Discrete Mathematics and Theoretical Computer Science, volume 70, pp. 13–20, 2006. . Succinctly describes theoretical ideas behind SVM.
* Kristin P. Bennett and Colin Campbell, "Support Vector Machines: Hype or Hallelujah?", SIGKDD Explorations, 2,2, 2000, 1-13. . Excellent introduction to SVMs with helpful figures.
* Ovidiu Ivanciuc, "Applications of Support Vector Machines in Chemistry", In: Reviews in Computational Chemistry, Volume 23, 2007, pp. 291–400. Reprint available:
* Catanzaro, Sundaram, Keutzer, "Fast Support Vector Machine Training and Classification on Graphics Processors", In: International Conference on Machine Learning, 2008