Support Vector Machine (SVM)
See:
- ML1 - Lezione 12 - Kernel Methods and Kuhn and Tucker’s Theorem, SVM prerequisite
- ML1 - Lecture 13-14 - Support Vector Machine, Optimal Hyperplane Problem, Mercer Kernel, Kernel Trick
- ML1 - Lecture 23 - SVM for Regression
It’s an algorithm used both for regression and classification.
An SVM classifier builds a model that assigns new data points to one of the given categories. Thus, it can be viewed as a non-probabilistic binary linear classifier.

-
Hyperplane → decision boundary.
-
Support Vectors → data points closer to the hyperplane
-
Margin → separation gap between data points
-
Maximum Margin Hyperplane → The SVM separates data points using a hyperplane with maximum amount of margine.
Support Vector Machine Intuition
The idea behind the kernel methods is to use algorithms that perform implicitly the data in a high dimensional space. For example with an input space of dimension 4 we can go in a space of dimensional 100 and so on.
The Support Vector Machine is the most well known algorithms

It can be summarized into two steps:
- Project implicitly onto a high-dimensional space by the kernel trick which consists in replacing the innter product between data vectors with a kernel function
- Apply a linear classification to the projected data
Note that data is projected in a nonlinear way in an higher dimension.
Support Vector Machine Preliminaries Knowledge
Kuhn Tucker Theorem
It is an extension of Lagrange Multipliers for inequality constraints. KTT is used to solve the convex optimization problem i.e., to minimize a convex objective function under certain convex constraints of inequality type, was proposed. There a function must be convex in order to be minimized through inequalities.
Convexness: recall that a set is convex if
Jensen Inequality: a function
Convex Optimization Problem: Let
The convex optimization problems state that we want to minimize
Let
- Minimum principle:
must minimize the Lagrangian such that - Non-negativeness of the conditions: so we cannot have negative values like before
- Kuhn Tucker Conditions: the product of
and called for
If
Slater condition: To get
Kuhn Tucker Theorem Corollary
If the Slater conditions are satisfied, then one can choose
Now the Lagrangian is defined as a function of
Optimal Hyperplane Algorithm
For simplicity consider a binary classification problem.
Class of hyperplanes: the general class is defined as:
Decision: a signum function is used to decide if a data point appartains to a class or the other. Recall that the signum (sgn) values are -1 if
Optimal Hyperplane: Vapnik and Lener observed that among all hyperplane separating the data exists only one optimal hyperplane that yield the maximum margin of separation between classess:
for all possible value
Maximum Margin: distance
Hence:
We need to consider an additional constraint: there must be no points between the white and black point that define the margin, expressed through constraint equation:
So respectively they are either in the upper zone, upper the dotted line or in belove zone belove the zone.
These constraints can be represented into one:
Summary: Optimal Hyperplane Problem
Minimize:
subject to the constraint:
Solution: define a Lagrangian function:
that must be minimizes with respect to weights
To solve this we use the Kuhn Tucker Theorem introduced before.
The Kuhn-Tucker Theorem want a minus, so the formula for the optimal hyperplane becomes:
Notice: the lagrangian function has
Support Vectors
Computing the derivative of the Lagrangian respect to the vector
So this implies that:
Now we compute the derivative respect to b:
the only things that remains is:
If
Our problem does not depends on the whole patterns of the dataset but the solution depends only by a particular subset or dataset for by the pattern whose respective Lagrange Multipliers are larger than 0. The other pattern for which the lagrange multiplier are null, in reality, are completely negletted by the algorithm since they don’t influence the value of the weights.
Since we want that:
then the value multiplied by
So in reality we are not interested by all the points, but only by the two points on the dotted line.
These two points are the only points that influences our solution. If you find the support vector,
KKT allow us to say that the support vectors, the vectors for which the respective lagrange multipliers is different from zero, lies on the margin, and the other samples of the training set are null.
So, hyperplane is completely determined by the patterns closest to it, the solution should not depend on other patterns of the training set.
We want to get a formula independent from weights: Therefore, the weight can be written as:
Substituting the previous two equations:
in
Now, consider the term:
(We consider a subset)
Then we obtain:
Then we get the final form by simplfying:
subject to
Instead of minimizing
Note: we did these computations to get a formula independent from
Hyperplane Decision function
we replace
Now, this is a linear classifier that can solve only linear problems. It cannot solve simple nonlinear problems as XOR.
In order to solve non-linear problem, we need to project data into higher dimension in a nonlinear manner.
Intuition: If the dimension of the new space is high, means that the points are sparse and if the points are sparse, it is more likely that it can be separated by an hyperplane classifier rather than in a smaller space. So we want to project into an higher dimensional space.
So the idea is to substitute this with an appropriate function that we call kernel, Mercel Kernel.
Mercer Kernel
The Mercel Kernel that corresponds to a positive semidefinite function.
Let
Mercer Kernel Example: Inner Product
An example of mercel kernel is the inner product, defined as:
that is equal to:
Norm is always greater than 0, so the equations holds true and the inner product is a mercer kernel.
The kernel trick consists in this: replacing the inner product with another mercer kernel.
that is always larger than 0, the conseguence is the inner product is a mercer kernel
This is called the kernel trick: replace the inner product with the mercer kernel.
At the start of the course we saw the covariance matrix with the proof that is semidefinite positive. And it’s the same, if you compute
Mercer Kernel Properties
Cauchy-Swartz Inequality:
Hilbert Space:
A mercer kernel must also respect the following properties:
- Additive property:
the sum is again a mercel kernel - multiplicity:
with note strictly positive, cannot be negative otherwise it doesn’t hold anymore the property saw last lesson - If you take two mercel kernel, the product is again a mercel kernel - If you make the tensorial product of a mercel kernel you get again a mercel kernel.
Where
Example of Mercer with explicit mapping
- Consider the homogenous kernel of degree 2, i.e:
- Assume the two vectors
and are bidimensional vectors - They can be expressed as:
and - Apply definition to kernel:
- Apply rule of square:
Equation where rule of square is applied is equivalent to:
This is equivalent to using 2 coordinate to make a 6-dimensional space.
Property: this result is generalizable:
Combining Optimal Hyperplane and Mercer Kernel
Implicit mapping
If we consider the Gaussian Kernel, the kernel has an implicit mapping since
Kernel Trick applied to decision function: Consider the Hyperplane Decision function that i rewrite here for convenience:
Applying the kernel trick means replacing
Support Vector Machine Construction
Putting together everything from previous section (Support Vector Machine Preliminaries Knowledge) we can construct the SVM.
To construct a SVM, an optimal hyperplane in some Feature Space has to be computed.
The classification of the output
In the Support Vectors section we saw how weight equation can be written as:
Problem:
Since
This is justified by Mercer Kernel Properties:
Recall the function to minimize defined in Support Vectors. We replace inner product with mercer kernel
Then we get the final form by simplfying:
subject to constraints:
for
Slack Variables
In real word problems, there is noise in data (i.e. mislabelled samples), and classes may be partially overlapped. Therefore it is necessary to allow the possibility that some examples can violate the constraint:
A slack variable
If we introduce these slack variables, the constraints change to this form:
Support Vector Machine objective function
The SVM classifier allows use to control the margin
subject to constraints:
- Higher
penalizes more misclassification, leading to a smaller margin - Lower
allows a larger margin with more tolerance for errors
Notice how with slack variables, we have to minimize
The function to minimize is:
subject to constraints:
with
Sequential Minimal Optimization: That is a quadratic optimization problem, there isn’t an exact solution in numerical analysis and the only way is to use an approximate solution. A greedy approach called sequential minimal optimization consists in optimization using two Lagrange multipliers each time. Since it’s a greedy approach, there is no guarantee that you find an optimal solution.
The number of iterations must be fixed since no convergence is guaranteed.
SVM are binary classifiers: to use it when the number of classes
Support Vector Machine for Regression
SVM is born as binary classifier, but in the recent years it is more popular for regression, as classification is done with neural networks.
Assume that the output values are
Given a data set

Any data point outside this tube, the white circles, has a loss function not null and can be viewed as a training error.
Assumption: assume that
Take the same function to minimize from classification:
Here, we have replaced the term that expresses the number of errors in the classification with the quadratic
Now, introducing Slack Variables and constraints we obtain:
Subject to the constraints:
Slack Variables in SVM for regression:
In particular:
is stricly positive when the respective pattern is such that is strictly positive when the respective pattern is such that

Lagrange Multipliers The usual technique of combining Lagrange variables with Kuhn Tucker Theorem can solve this constrainted optimization problem.
The previous constraints induce two kind of Lagrange multipliers
Objective Functions Hence we get the following objective function to maximize
is the kronecker symbol
subject to constraints:
both for
The corresponding Kuhn Tucker Conditions are:
for for for for
Improving the formula: introduce
- subject to
for
Finally, replace the dot product with the Mercer Kernel:
- subject to
for
Regression Estimate: the regression estimates, i.e. the function
- where
has to be choosen such that:
for any support vector