SVM Tutorial
SVM Tutorial
A portion (1/3) of the slides are taken from Prof. Andrew Moores SVM tutorial at http://www.cs.cmu.edu/~awm/tutorials
Mingyue Tan
The University of British Columbia Nov 26, 2004
Overview
Discussion
Linear Classifiers
denotes +1 denotes -1
x
w x + b>0
b= 0
yest
f(x,w,b) = sign(w x + b)
w x + b<0
Linear Classifiers
denotes +1 denotes -1
yest
f(x,w,b) = sign(w x + b)
Linear Classifiers
denotes +1 denotes -1
yest
f(x,w,b) = sign(w x + b)
Linear Classifiers
denotes +1 denotes -1
yest
f(x,w,b) = sign(w x + b)
Linear Classifiers
denotes +1 denotes -1
yest
f(x,w,b) = sign(w x + b)
Misclassified to +1 class
Classifier Margin
x
denotes +1 denotes -1
yest
f(x,w,b) = sign(w x + b)
Define the margin of a linear classifier as the width that the boundary could be increased by before hitting a datapoint.
Maximum Margin
denotes +1 denotes -1
x
1. Maximizing the margin is good accordingf(x,w,b) = sign(w x + b) to intuition and PAC theory 2. Implies that only support vectors are important; other The maximum training examples are ignorable.
yest
Support Vectors are those datapoints that the margin pushes up against
margin linear 3. Empirically it works very very well. classifier is the linear classifier with the, um, maximum margin. This is the simplest kind of SVM (Called an LSVM)
Linear SVM
x+
M =Margin Width
1 b= + 0 wx b= + wx -1 b= + wx
X-1 = ss la t C o ne c z edi Pr
(x x ) w 2 M = = w w
1 t w ww 2
1 t ( w) = w w Minimize 2
subject to
yi ( wxi + b) 1
(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: Find 1N such that Q() =i - ijyiyjxiTxj is maximized and (1) iyi = 0 (2) i 0 for all i
The solution has the form: w =iyixi b= yk- wTxk for any xk such that k 0
Each non-zero i indicates that corresponding xi is a support vector. Then the classifying function will have the form: f(x) = iyixiTx + b Notice that it relies on an inner product between the test point x and the support vectors xi we will return to this later. Also keep in mind that solving the optimization problem involved computing the inner products xiTxj between all pairs of training points.
OVERFITTING!
2
=1 +b wx =0 +b -1 wx b= + wx
11
1 w.w + C k 2 k =1
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 1N such that Q() =i - ijyiyjxiTxj 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? How about mapping data to a higher-dimensional space:
x2 0 x
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 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]
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:
K (x i , x j ) = exp(
xi x j 2
2
Find 1N such that Q() =i - ijyiyjK(xi, xj) is maximized and (1) iyi = 0 (2) i 0 for all i
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
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
SVM Applications
Patients P-1
g-1
Imbalanced
- less positive samples
p-2 . p-n
n+ K [ x , x ] = k ( x, x ) + N
FEATURE SELECTION In the linear case, wi2 gives the ranking of dim i
Weakness of SVM
It is sensitive to noise
- A relatively small number of mislabeled examples can dramatically decrease the performance
Task: The classification of natural text (or hypertext) documents into a fixed number of predefined categories based on their content.
- email filtering, web searching, sorting documents by topic, etc..
A document can be assigned to more than one category, so this can be viewed as a series of binary classification problems, one for each category
Representation of Text
IRs vector space model (aka bag-of-words representation) A doc is represented by a vector indexed by a pre-fixed set or dictionary of terms Values of an entry can be binary or weights
The distance between two documents is (x)(z) K(x,z) = (x)(z) is a valid kernel, SVM can be used with K(x,z) for discrimination. 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
Additional Resources
http://www.kernel-machines.org/
Reference
Support Vector Machine Classification of Microarray Gene Expression Data, Michael P. S. Brown William Noble Grundy, David Lin, Nello Cristianini, Charles Sugnet, Manuel Ares, Jr., David Haussler www.cs.utexas.edu/users/mooney/cs391L/svm.ppt Text categorization with Support Vector Machines: learning with many relevant features
T. Joachims, ECML - 98