Support Vector Machines
Jaya Sil
Department of Computer Science and Technology
Support Vector Machines (SVM)
■ SVM were introduced by Vladimir Vapnik (Vapnik, 1995).
■ The main objective in SVM is to find the hyperplane which
separates the d-dimensional data points perfectly into two
classes.
■ However, since example data is often not linearly separable,
SVM's introduce the notion of a “kernel induced feature
space" which casts the data points (input space) into a higher
dimensional feature space where the data is separable.
■ SVM's higher-dimensional space doesn't need to be dealt with
directly which eliminates overfitting.
Support Vector Machines - Linear classifier
■ Classification tasksare based on drawing separating lines to
distinguish between objects of different class labels are known
as hyperplane classifiers.
■ A decision plane is one that separates between a set of objects
having different class labels.
■ Any new object falling to the right is labeled, i.e., classified, as
GREEN (or classified as RED should it fall to the left of the
separating line).
■ The objects closest to the hyperplane is called support vectors
Input Space to Feature Space
• The original objects are transformed, using a set of mathematical
functions, known as kernels.
• Instead of constructing the complex curve, we find an optimal line
that can separate the objects.
We are given l training examples {xi, yi};
Linear Classifiers i = 1.. l , where each example has d
inputs (xi ∈ Rd), and a class label with
one of two values (yi ∈{-1, 1}.
denotes +1
denotes -1
• All hyperplanes in Rd
are parameterized by
a vector (w) and a
constant (b),
expressed using the
equation w . x + b = 0
• w is the vector
• Given such a hyperplane (w,b) that separates the orthogonal to the
data, using function f(x) = sign(w. x + b) hyperplane
Linear Classifiers
f(x,w,b) = sign(w x + b)
denotes +1 wx+b>0
denotes -1
0
b=
+
x
w
How would you
classify this data?
wx+b<0
Linear Classifiers
f(x,w,b) = sign(w x + b)
denotes +1
denotes -1
Any of these
would be fine..
..but which is
best?
Linear Classifiers
f(x,w,b) = sign(w x + b)
denotes +1
denotes -1
How would you
classify this data?
Misclassifie
d
to +1 class
Hyperplane Classifier
■ A given hyperplane represented by (w,b) is equally expressed
by all pairs {λw, λb} for λ ∈ R+.
■ We define the hyperplane which separates the data from the
hyperplane by a “distance” so that at least one example on
both sides has a distance of exactly 1.
■ That is, we consider those that satisfy:
■ w . xi + b ≥ 1 when yi = +1
■ w . xi + b ≤ 1 when yi = -1
yi (w . xi + b) ≥ 1 ∀i
• To obtain the geometric distance from the hyperplane to a data
point, we normalize by the magnitude of w.
• We want the hyperplane that maximizes the geometric distance
to the closest data points.
d( (w, b) , xi) = [yi(w. xi + b)] / ||w|| ≥ 1 / ||w||
Choosing the hyperplane that maximizes the margin
Classifier Margin f(x,w,b) = sign(w x + b)
denotes +1
denotes -1 Define the margin
of a linear
classifier as the
width that the
boundary could be
increased by
before hitting a
datapoint.
Maximum Margin
1. Maximizing the margin
2. f(x,w,b)are
support vectors = sign(w x + b)
important
denotes +1
denotes -1
The maximum
margin linear
classifier
Support Vectors
This is the
simplest kind of
SVM (Called an
LSVM)
Linear SVM
Linear SVM Mathematically
”
+ 1
ss
= x+ M=Margin Width
l a
i ct C one
ed z
“Pr
X- - 1”
b =1 s =
+ la s Two hyperplanes are parallel (they
wx =0 C e
+ b
d ict zon have the same normal) and that no
wx =-
1 re
+ b “P training points fall between them.
wx
What we know:
+
■ w . x + b = +1
-
■ w . x + b = -1
+ -)
■ w . (x -x = 2
Linear SVM Mathematically
■ Goal: 1) Correctly classify all training data
if yi = +1
if yi = -1
for all i
2) Maximize the Margin or same as minimize
■ We can formulate a constrained optimization Problem and solve for
w and b
■ Minimize
subject to
Lagrange Multipliers
• Consider a problem: minx f(x) subject to h(x) = 0
• We define the Lagrangian L (x, α ) = f(x) - α h (x)
• α is called “Lagrange multiplier”
• Solve: minx maxα L (x, α ) subject to α ≥ 0
Original Problem:
Find w and b such that
Φ(w) =½ wTw is minimized;
and for all i {(xi ,yi)}: yi (wTxi + b) ≥ 1
Construct the Lagrangian Function for
optimization
S. T. αi ≥ 0; ∀i
Our goal is to: OR
The derivative with respect to b
Substituting we get:
maxα :
Subject to
α is the vector of m non-negative Lagrange multipliers to be determined,
and C is a constant
Optimal hyperplane :
• The vector w is just a linear combination of the training examples.
• If we’ve found the αi’s, in order to make a prediction, we have
to calculate a quantity that depends only on the inner product
between x and the points in the training set.
•
Dataset with noise
denotes +1 ■ Hard Margin: So far we require
all data points be classified correctly.
denotes -1
- No training error
■ What if the training set is noisy?
- Solution 1: use very powerful
kernels
OVERFITTING!
Soft Margin Classification
Slack variables ξi can be added to allow
misclassification of difficult or noisy examples.
What should our quadratic
ε11 optimization criterion be?
ε2 Minimize
b=1
+
wx
b=
0 ε7
+
wx b=-1
+
wx
Hard Margin v.s. Soft Margin
■ The old formulation:
Find w and b such that
Φ(w) =½ wTw is minimized and for all {(xi ,yi)}
yi (wTxi + b) ≥ 1
■ The new formulation incorporating slack variables:
Find w and b such that
Φ(w) =½ wTw + λ Σξi is minimized and for all {(xi ,yi)}
yi (wTxi + b) ≥ 1- ξi and ξi ≥ 0 for all i
■ Parameter λ can be viewed as a way to control
overfitting.
Linear SVMs: Overview
■ The classifier is a separating hyperplane.
■ Most “important” training points are support vectors; they
define the hyperplane.
■ Quadratic optimization algorithms can identify which training
points xi are support vectors with non-zero Lagrangian
multipliers αi.
■ Both in the dual formulation of the problem and in the solution
training points appear only inside dot products:
Find α1…αN such that
Q(α) =Σαi - ½ΣΣαiαjyiyjxiTxj is maximized and
(1) Σαiyi = 0
(2) 0 ≤ αi ≤ C for all αi
f(x) = ΣαiyixiTx + b
Non-linear SVMs
■ Datasets that are linearly separable with some noise work out
great:
0 x
■ But what are we going to do if the dataset is just too hard?
0 x
■ How about… mapping data to a higher-dimensional space:
x2
0 x
Non-linear SVMs: Feature spaces
■ General idea: the original input space (nonlinear separable
data) can always be mapped to some higher-dimensional
feature space where the training set is linearly separable:
Φ: x → φ(x)
Mapping the Inputs to other dimensions - the
use of Kernels
• Finding the optimal curve to fit the data is difficult.
• There is a way to “pre-process" the data in such a way that the
problem is transformed into one of finding a simple hyperplane.
• We define a mapping z = φ(x) that transforms the d-dimensional
input vector x into a (usually higher) d*-dimensional vector z.
• We hope to choose a φ() so that the new training data {φ(xi),yi} is
separable by a hyperplane.
• How do we go about choosing φ()?
The “Kernel Trick”
■ The linear classifier relies on dot product between vectors K(xi,xj)=xiTxj
■ If every data point is mapped into high-dimensional space via some
transformation Φ: x → φ(x), the dot product becomes:
K(xi,xj)= φ(xi) Tφ(xj)
■ A kernel function is some function that corresponds to an inner product in
some expanded feature space.
■ Example:
2-dimensional vectors x=[x1 x2]; let K(xi,xj)=(1 + xiTxj)2,
Need to show that K(xi,xj)= φ(xi) Tφ(xj):
K(xi,xj)=(1 + xiTxj)2,
= 1+ xi12xj12 + 2 xi1xj1 xi2xj2+ xi22xj22 + 2xi1xj1 + 2xi2xj2
= [1 xi12 √2 xi1xi2 xi22 √2xi1 √2xi2]T [1 xj12 √2 xj1xj2 xj22 √2xj1 √2xj2]
= φ(xi) Tφ(xj), where φ(x) = [1 x12 √2 x1x2 x22 √2x1 √2x2]
Non-linear SVMs Mathematically
■ Dual problem formulation:
Find α1…αN such that
Q(α) =Σαi - ½ΣΣαiαjyiyjK(xi, xj) is maximized and
(1) Σαiyi = 0
(2) αi ≥ 0 for all αi
■ The solution is:
f(x) = ΣαiyiK(xi, xj)+ b
■ Optimization techniques for finding αi’s remain the same!
Examples of Kernel Functions
■ Linear: K(xi,xj)= xi Txj
■ Polynomial of power p: K(xi,xj)= (1+ xi Txj)p
■ Gaussian (radial-basis function network):
■ Sigmoid: K(xi,xj)= tanh(β0xi Txj + β1)
Nonlinear SVM - Overview
■ SVM locates a separating hyperplane in the
feature space and classify points in that
space
■ It does not need to represent the space
explicitly, simply by defining a kernel
function
■ The kernel function plays the role of the dot
product in the feature space.
Properties of SVM
■ Flexibility in choosing a similarity function
■ Sparseness of solution when dealing with large data
sets
- only support vectors are used to specify the separating
hyperplane
■ Ability to handle large feature spaces
- complexity does not depend on the dimensionality of the
feature space
■ Overfitting can be controlled by soft margin
approach
■ Nice math property: a simple convex optimization problem
which is guaranteed to converge to a single global solution
■ Feature Selection
Weakness of SVM
■ It is sensitive to noise
- A relatively small number of mislabeled examples can
dramatically decrease the performance
■ It only considers two classes
- how to do multi-class classification with SVM?
- Answer:
1) with output arity m, learn m SVM’s
❑ SVM 1 learns “Output==1” vs “Output != 1”
❑ SVM 2 learns “Output==2” vs “Output != 2”
❑ :
❑ SVM m learns “Output==m” vs “Output != m”
2)To predict the output for a new input, just predict with each
SVM and find out which one puts the prediction the furthest
into the positive region.
Some Issues
■ Choice of kernel
- Gaussian or polynomial kernel is default
- if ineffective, more elaborate kernels are needed
- domain experts can give assistance in formulating appropriate
similarity measures
■ Choice of kernel parameters
- e.g. σ in Gaussian kernel
- σ is the distance between closest points with different
classifications
- In the absence of reliable criteria, applications rely on the use
of a validation set or cross-validation to set such parameters.
■ Optimization criterion – Hard margin v.s. Soft margin
- a lengthy series of experiments in which various parameters
are tested
Additional Resources
■ An excellent tutorial on VC-dimension and Support
Vector Machines:
C.J.C. Burges. A tutorial on support vector machines for pattern
recognition. Data Mining and Knowledge Discovery,
2(2):955-974, 1998.
■ The VC/SRM/SVM Bible:
Statistical Learning Theory by Vladimir Vapnik,
Wiley-Interscience; 1998
[Link]