SVM Tutorial
SVM Tutorial
SVM Tutorial
Applications
w x + b<0
a
Linear Classifiers
x f yest
f(x,w,b) = sign(w x + b)
denotes +1
denotes -1
Any of these
would be fine..
..but which is
best?
a
Linear Classifiers
x f yest
f(x,w,b) = sign(w x + b)
denotes +1
denotes -1
Misclassified
to +1 class
a
Classifier Margin
x f yest
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.
a
Maximum Margin
x f yest
1. Maximizing the margin is good
accordingf(x,w,b)
to intuition and PAC
= sign(w theory
x+ b)
denotes +1 2. Implies that only support vectors are
denotes -1 important; other The
training examples
maximum
are ignorable.
margin linear
3. Empirically it works very very
classifier iswell.
the
linear classifier
Support Vectors with the, um,
are those
datapoints that maximum margin.
the margin This is the
pushes up
against simplest kind of
SVM (Called an
LSVM)
Linear SVM
Linear SVM Mathematically
x+ M=Margin Width
X-
What we know:
(x x ) w 2
w . x+ + b = +1 M
w . x- + b = -1
w w
w . (x+-x-) = 2
Linear SVM Mathematically
Goal: 1) Correctly classify all training data
wxi b 1 if yi = +1
wxi b 1 if yi = -1
yi (wxi b) 1 for all i 2
2) Maximize the Margin M
1 t w
same as minimize ww
2
We can formulate a Quadratic Optimization Problem and solve for w and b
1 t
Minimize ( w) w w
2
subject to yi (wxi b) 1 i
Solving the Optimization Problem
Find w and b such that
(w) = wTw is minimized;
and for all {(xi ,yi)}: yi (wTxi + b) 1
Need to optimize a quadratic function subject to linear
constraints.
Quadratic optimization problems are a well-known class of
mathematical programming problems, and many (rather
intricate) algorithms exist for solving them.
The solution involves constructing a dual problem where a
Lagrange multiplier i is associated with every constraint in the
primary problem:
OVERFITTING!
Soft Margin Classification
Slack variables i can be added to allow
misclassification of difficult or noisy examples.
f(x) = iyixiTx + b
Non-linear SVMs
Datasets that are linearly separable with some noise
work out great:
0 x
0 x
Non-linear SVMs: Feature spaces
General idea: the original input space can always be
mapped to some higher-dimensional feature space
where the training set is separable:
: x (x)
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]
What Functions are Kernels?
For some functions K(xi,xj) checking that
K(xi,xj)= (xi) T(xj) can be cumbersome.
Mercers theorem:
Every semi-positive definite symmetric function is a kernel
Semi-positive definite symmetric functions correspond to a
semi-positive definite symmetric Gram matrix:
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.
Application 2: Text Categorization
Why SVM?
-High dimensional input space
-Few irrelevant features (dense concept)
-Sparse document vectors (sparse instances)
-Text categorization problems are linearly separable
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
http://www.kernel-machines.org/
Reference