In
machine learning
Machine learning (ML) is a field of study in artificial intelligence concerned with the development and study of Computational statistics, statistical algorithms that can learn from data and generalise to unseen data, and thus perform Task ( ...
, support vector machines (SVMs, also support vector networks
) are
supervised max-margin models with associated learning
algorithm
In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
s that analyze data for
classification
Classification is the activity of assigning objects to some pre-existing classes or categories. This is distinct from the task of establishing the classes themselves (for example through cluster analysis). Examples include diagnostic tests, identif ...
and
regression analysis. Developed at
AT&T Bell Laboratories
Nokia Bell Labs, commonly referred to as ''Bell Labs'', is an American industrial research and development company owned by Finnish technology company Nokia. With headquarters located in Murray Hill, New Jersey, Murray Hill, New Jersey, the compa ...
,
SVMs are one of the most studied models, being based on statistical learning frameworks of
VC theory proposed by
Vapnik
Vladimir Naumovich Vapnik (; born 6 December 1936) is a statistician, researcher, and academic. He is one of the main developers of the Vapnik–Chervonenkis theory of statistical learning and the co-inventor of the support-vector machine method a ...
(1982, 1995) and
Chervonenkis (1974).
In addition to performing
linear classification, SVMs can efficiently perform non-linear classification using the
''kernel trick'', representing the data only through a set of pairwise similarity comparisons between the original data points using a kernel function, which transforms them into coordinates in a higher-dimensional
feature space
Feature may refer to:
Computing
* Feature recognition, could be a hole, pocket, or notch
* Feature (computer vision), could be an edge, corner or blob
* Feature (machine learning), in statistics: individual measurable properties of the phenom ...
. Thus, SVMs use the kernel trick to implicitly map their inputs into high-dimensional feature spaces, where linear classification can be performed. Being max-margin models, SVMs are resilient to noisy data (e.g., misclassified examples). SVMs can also be used for
regression tasks, where the objective becomes
-sensitive.
The support vector clustering
algorithm, created by
Hava Siegelmann and
Vladimir Vapnik, applies the statistics of support vectors, developed in the support vector machines algorithm, to categorize unlabeled data. These data sets require
unsupervised learning approaches, which attempt to find natural
clustering of the data into groups, and then to map new data according to these clusters.
The popularity of SVMs is likely due to their amenability to theoretical analysis, and their flexibility in being applied to a wide variety of tasks, including
structured prediction problems. It is not clear that SVMs have better predictive performance than other linear models, such as
logistic regression
In statistics, a logistic model (or logit model) is a statistical model that models the logit, log-odds of an event as a linear function (calculus), linear combination of one or more independent variables. In regression analysis, logistic regres ...
and
linear regression
In statistics, linear regression is a statistical model, model that estimates the relationship between a Scalar (mathematics), scalar response (dependent variable) and one or more explanatory variables (regressor or independent variable). A mode ...
.
Motivation
Classifying data is a common task in
machine learning
Machine learning (ML) is a field of study in artificial intelligence concerned with the development and study of Computational statistics, statistical algorithms that can learn from data and generalise to unseen data, and thus perform Task ( ...
.
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
-dimensional vector (a list of
numbers), and we want to know whether we can separate such points with a
-dimensional
hyperplane
In geometry, a hyperplane is a generalization of a two-dimensional plane in three-dimensional space to mathematical spaces of arbitrary dimension. Like a plane in space, a hyperplane is a flat hypersurface, a subspace whose dimension is ...
. 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
Margin may refer to:
Physical or graphical edges
*Margin (typography), the white space that surrounds the content of a page
* Continental margin, the zone of the ocean floor that separates the thin oceanic crust from thick continental crust
*Leaf ...
, 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
In geometry, the hyperplane separation theorem is a theorem about Disjoint sets, disjoint convex sets in ''n''-dimensional Euclidean space. There are several rather similar versions. In one version of the theorem, if both these sets are Closed se ...
'' and the linear classifier it defines is known as a ''maximum-
margin classifier
In machine learning (ML), a margin classifier is a type of classification model which is able to give an associated distance from the decision boundary for each data sample. For instance, if a linear classifier is used, the distance (typically Eu ...
''; or equivalently, the ''
perceptron of optimal stability''.
More formally, a support vector machine constructs a
hyperplane
In geometry, a hyperplane is a generalization of a two-dimensional plane in three-dimensional space to mathematical spaces of arbitrary dimension. Like a plane in space, a hyperplane is a flat hypersurface, a subspace whose dimension is ...
or set of hyperplanes in a high or infinite-dimensional space, which can be used for
classification
Classification is the activity of assigning objects to some pre-existing classes or categories. This is distinct from the task of establishing the classes themselves (for example through cluster analysis). Examples include diagnostic tests, identif ...
,
regression, or other tasks like outliers detection. Intuitively, a good separation is achieved by the hyperplane that has the largest distance to the nearest training-data point of any class (so-called functional margin), since in general the larger the margin, the lower the
generalization error of the classifier. A lower
generalization error means that the implementer is less likely to experience
overfitting
In mathematical modeling, overfitting is "the production of an analysis that corresponds too closely or exactly to a particular set of data, and may therefore fail to fit to additional data or predict future observations reliably". An overfi ...
.

Whereas the original problem may be stated in a finite-dimensional space, it often happens that the sets to discriminate are not
linearly separable in that space. 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. To keep the computational load reasonable, the mappings used by SVM schemes are designed to ensure that
dot product
In mathematics, the dot product or scalar productThe term ''scalar product'' means literally "product with a Scalar (mathematics), scalar as a result". It is also used for other symmetric bilinear forms, for example in a pseudo-Euclidean space. N ...
s of pairs of input data vectors may be computed easily in terms of the variables in the original space, by defining them in terms of a
kernel function selected to suit the problem. The hyperplanes in the higher-dimensional space are defined as the set of points whose dot product with a vector in that space is constant, where such a set of vectors is an orthogonal (and thus minimal) set of vectors that defines a hyperplane. The vectors defining the hyperplanes can be chosen to be linear combinations with parameters
of images of
feature vectors
that occur in the data base. With this choice of a hyperplane, the points
in the
feature space
Feature may refer to:
Computing
* Feature recognition, could be a hole, pocket, or notch
* Feature (computer vision), could be an edge, corner or blob
* Feature (machine learning), in statistics: individual measurable properties of the phenom ...
that are mapped into the hyperplane are defined by the relation
Note that if
becomes small as
grows further away from
, each term in the sum measures the degree of closeness of the test point
to the corresponding data base point
. 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
mapped into any hyperplane can be quite convoluted as a result, allowing much more complex discrimination between sets that are not convex at all in the original space.
Applications
SVMs can be used to solve various real-world problems:
* SVMs are helpful in
text and hypertext categorization, as their application can significantly reduce the need for labeled training instances in both the standard inductive and
transductive settings. Some methods for
shallow semantic parsing are based on support vector machines.
*
Classification of images can also be performed using SVMs. Experimental results show that SVMs achieve significantly higher search accuracy than traditional query refinement schemes after just three to four rounds of relevance feedback. This is also true for
image segmentation systems, including those using a modified version SVM that uses the privileged approach as suggested by Vapnik.
* Classification of satellite data like
SAR data using supervised SVM.
* Hand-written characters can be
recognized using SVM.
* The SVM algorithm has been widely applied in the biological and other sciences. They have been used to classify proteins with up to 90% of the compounds classified correctly.
Permutation tests based on SVM weights have been suggested as a mechanism for interpretation of SVM models. Support vector machine weights have also been used to interpret SVM models in the past. Posthoc interpretation of support vector machine models in order to identify features used by the model to make predictions is a relatively new area of research with special significance in the biological sciences.
History
The original SVM algorithm was invented by
Vladimir N. Vapnik and
Alexey Ya. Chervonenkis in 1964. In 1992, Bernhard Boser,
Isabelle Guyon and
Vladimir Vapnik suggested a way to create nonlinear classifiers by applying the
kernel trick to maximum-margin hyperplanes.
The "soft margin" incarnation, as is commonly used in software packages, was proposed by
Corinna Cortes and Vapnik in 1993 and published in 1995.
Linear SVM

We are given a training dataset of
points of the form
where the
are either 1 or −1, each indicating the class to which the point
belongs. Each
is a
-dimensional
real vector. We want to find the "maximum-margin hyperplane" that divides the group of points
for which
from the group of points for which
, which is defined so that the distance between the hyperplane and the nearest point
from either group is maximized.
Any
hyperplane
In geometry, a hyperplane is a generalization of a two-dimensional plane in three-dimensional space to mathematical spaces of arbitrary dimension. Like a plane in space, a hyperplane is a flat hypersurface, a subspace whose dimension is ...
can be written as the set of points
satisfying
where
is the (not necessarily normalized)
normal vector to the hyperplane. This is much like
Hesse normal form, except that
is not necessarily a unit vector. The parameter
determines the offset of the hyperplane from the origin along the normal vector
.
Warning: most of the literature on the subject defines the bias so that
Hard-margin
If the training data is
linearly separable, we can select two parallel hyperplanes that separate the two classes of data, so that the distance between them is as large as possible. The region bounded by these two hyperplanes is called the "margin", and the maximum-margin hyperplane is the hyperplane that lies halfway between them. With a normalized or standardized dataset, these hyperplanes can be described by the equations
:
(anything on or above this boundary is of one class, with label 1)
and
:
(anything on or below this boundary is of the other class, with label −1).
Geometrically, the distance between these two hyperplanes is
, so to maximize the distance between the planes we want to minimize
. The distance is computed using the
distance from a point to a plane equation. We also have to prevent data points from falling into the margin, we add the following constraint: for each
either
or
These constraints state that each data point must lie on the correct side of the margin.
This can be rewritten as
We can put this together to get the optimization problem:
The
and
that solve this problem determine the final classifier,
, where
is the
sign function
In mathematics, the sign function or signum function (from '' signum'', Latin for "sign") is a function that has the value , or according to whether the sign of a given real number is positive or negative, or the given number is itself zer ...
.
An important consequence of this geometric description is that the max-margin hyperplane is completely determined by those
that lie nearest to it (explained below). These
are called ''support vectors''.
Soft-margin
To extend SVM to cases in which the data are not linearly separable, the ''
hinge loss'' function is helpful
Note that
is the ''i''-th target (i.e., in this case, 1 or −1), and
is the ''i''-th output.
This function is zero if the constraint in is satisfied, in other words, if
lies on the correct side of the margin. For data on the wrong side of the margin, the function's value is proportional to the distance from the margin.
The goal of the optimization then is to minimize:
where the parameter
determines the trade-off between increasing the margin size and ensuring that the
lie on the correct side of the margin (Note we can add a weight to either term in the equation above). By deconstructing the hinge loss, this optimization problem can be formulated into the following:
Thus, for large values of
, it will behave similar to the hard-margin SVM, if the input data are linearly classifiable, but will still learn if a classification rule is viable or not.
Nonlinear kernels

The original maximum-margin hyperplane algorithm proposed by Vapnik in 1963 constructed a
linear classifier. However, in 1992,
Bernhard Boser,
Isabelle Guyon and
Vladimir Vapnik suggested a way to create nonlinear classifiers by applying the
kernel trick (originally proposed by Aizerman et al.) to maximum-margin hyperplanes.
The kernel trick, where
dot product
In mathematics, the dot product or scalar productThe term ''scalar product'' means literally "product with a Scalar (mathematics), scalar as a result". It is also used for other symmetric bilinear forms, for example in a pseudo-Euclidean space. N ...
s are replaced by kernels, is easily derived in the dual representation of the SVM problem. This allows the algorithm to fit the maximum-margin hyperplane in a transformed
feature space
Feature may refer to:
Computing
* Feature recognition, could be a hole, pocket, or notch
* Feature (computer vision), could be an edge, corner or blob
* Feature (machine learning), in statistics: individual measurable properties of the phenom ...
. The transformation may be nonlinear and the transformed space high-dimensional; although the classifier is a hyperplane in the transformed feature space, it may be nonlinear in the original input space.
It is noteworthy that working in a higher-dimensional feature space increases the
generalization error of support vector machines, although given enough samples the algorithm still performs well.
Some common kernels include:
*
Polynomial (homogeneous):
. Particularly, when
, this becomes the linear kernel.
*
Polynomial
In mathematics, a polynomial is a Expression (mathematics), mathematical expression consisting of indeterminate (variable), indeterminates (also called variable (mathematics), variables) and coefficients, that involves only the operations of addit ...
(inhomogeneous):
.
* Gaussian
radial basis function:
for
. Sometimes parametrized using
.
*
Sigmoid function
A sigmoid function is any mathematical function whose graph of a function, graph has a characteristic S-shaped or sigmoid curve.
A common example of a sigmoid function is the logistic function, which is defined by the formula
:\sigma(x ...
(
Hyperbolic tangent):
for some (not every)
and
.
The kernel is related to the transform
by the equation
. The value is also in the transformed space, with
. Dot products with for classification can again be computed by the kernel trick, i.e.
.
Computing the SVM classifier
Computing the (soft-margin) SVM classifier amounts to minimizing an expression of the form
We focus on the soft-margin classifier since, as noted above, choosing a sufficiently small value for
yields the hard-margin classifier for linearly classifiable input data. The classical approach, which involves reducing to a
quadratic programming problem, is detailed below. Then, more recent approaches such as sub-gradient descent and coordinate descent will be discussed.
Primal
Minimizing can be rewritten as a constrained optimization problem with a differentiable objective function in the following way.
For each
we introduce a variable
. Note that
is the smallest nonnegative number satisfying
Thus we can rewrite the optimization problem as follows
This is called the ''primal'' problem.
Dual
By solving for the
Lagrangian dual of the above problem, one obtains the simplified problem
This is called the ''dual'' problem. Since the dual maximization problem is a quadratic function of the
subject to linear constraints, it is efficiently solvable by
quadratic programming algorithms.
Here, the variables
are defined such that
Moreover,
exactly when
lies on the correct side of the margin, and
when
lies on the margin's boundary. It follows that
can be written as a linear combination of the support vectors.
The offset,
, can be recovered by finding an
on the margin's boundary and solving
(Note that
since
.)
Kernel trick
Suppose now that we would like to learn a nonlinear classification rule which corresponds to a linear classification rule for the transformed data points
Moreover, we are given a kernel function
which satisfies
.
We know the classification vector
in the transformed space satisfies
where, the
are obtained by solving the optimization problem
The coefficients
can be solved for using quadratic programming, as before. Again, we can find some index
such that
, so that
lies on the boundary of the margin in the transformed space, and then solve
Finally,
Modern methods
Recent algorithms for finding the SVM classifier include sub-gradient descent and coordinate descent. Both techniques have proven to offer significant advantages over the traditional approach when dealing with large, sparse datasets—sub-gradient methods are especially efficient when there are many training examples, and coordinate descent when the dimension of the feature space is high.
Sub-gradient descent
Sub-gradient descent algorithms for the SVM work directly with the expression
Note that
is a
convex function
In mathematics, a real-valued function is called convex if the line segment between any two distinct points on the graph of a function, graph of the function lies above or on the graph between the two points. Equivalently, a function is conve ...
of
and
. As such, traditional
gradient descent (or
SGD) methods can be adapted, where instead of taking a step in the direction of the function's gradient, a step is taken in the direction of a vector selected from the function's
sub-gradient. This approach has the advantage that, for certain implementations, the number of iterations does not scale with
, the number of data points.
Coordinate descent
Coordinate descent algorithms for the SVM work from the dual problem
For each
, iteratively, the coefficient
is adjusted in the direction of
. Then, the resulting vector of coefficients
is projected onto the nearest vector of coefficients that satisfies the given constraints. (Typically Euclidean distances are used.) The process is then repeated until a near-optimal vector of coefficients is obtained. The resulting algorithm is extremely fast in practice, although few performance guarantees have been proven.
Empirical risk minimization
The soft-margin support vector machine described above is an example of an
empirical risk minimization
In statistical learning theory, the principle of empirical risk minimization defines a family of learning algorithms based on evaluating performance over a known and fixed dataset. The core idea is based on an application of the law of large num ...
(ERM) algorithm for the ''
hinge loss''. Seen this way, support vector machines belong to a natural class of algorithms for statistical inference, and many of its unique features are due to the behavior of the hinge loss. This perspective can provide further insight into how and why SVMs work, and allow us to better analyze their statistical properties.
Risk minimization
In supervised learning, one is given a set of training examples
with labels
, and wishes to predict
given
. To do so one forms a
hypothesis
A hypothesis (: hypotheses) is a proposed explanation for a phenomenon. A scientific hypothesis must be based on observations and make a testable and reproducible prediction about reality, in a process beginning with an educated guess o ...
,
, such that
is a "good" approximation of
. A "good" approximation is usually defined with the help of a ''
loss function,''
, which characterizes how bad
is as a prediction of
. We would then like to choose a hypothesis that minimizes the ''
expected risk:''
In most cases, we don't know the joint distribution of
outright. In these cases, a common strategy is to choose the hypothesis that minimizes the ''empirical risk:''
Under certain assumptions about the sequence of random variables
(for example, that they are generated by a finite Markov process), if the set of hypotheses being considered is small enough, the minimizer of the empirical risk will closely approximate the minimizer of the expected risk as
grows large. This approach is called ''empirical risk minimization,'' or ERM.
Regularization and stability
In order for the minimization problem to have a well-defined solution, we have to place constraints on the set
of hypotheses being considered. If
is a
normed space
The Ateliers et Chantiers de France (ACF, Workshops and Shipyards of France) was a major shipyard that was established in Dunkirk, France, in 1898.
The shipyard boomed in the period before World War I (1914–18), but struggled in the inter-war p ...
(as is the case for SVM), a particularly effective technique is to consider only those hypotheses
for which
. This is equivalent to imposing a ''regularization penalty''
, and solving the new optimization problem
This approach is called ''
Tikhonov regularization.''
More generally,
can be some measure of the complexity of the hypothesis
, so that simpler hypotheses are preferred.
SVM and the hinge loss
Recall that the (soft-margin) SVM classifier
is chosen to minimize the following expression:
In light of the above discussion, we see that the SVM technique is equivalent to empirical risk minimization with Tikhonov regularization, where in this case the loss function is the
hinge loss
From this perspective, SVM is closely related to other fundamental
classification algorithms such as
regularized least-squares and
logistic regression
In statistics, a logistic model (or logit model) is a statistical model that models the logit, log-odds of an event as a linear function (calculus), linear combination of one or more independent variables. In regression analysis, logistic regres ...
. The difference between the three lies in the choice of loss function: regularized least-squares amounts to empirical risk minimization with the
square-loss,
; logistic regression employs the
log-loss,
Target functions
The difference between the hinge loss and these other loss functions is best stated in terms of ''target functions -'' the function that minimizes expected risk for a given pair of random variables
.
In particular, let
denote
conditional on the event that
. In the classification setting, we have:
The optimal classifier is therefore:
For the square-loss, the target function is the conditional expectation function,