Support Vector Machines
Download
Report
Transcript Support Vector Machines
Last lecture summary
Information theory
β’ mathematical theory of the measurement of
the information, quantifies information
β’ Information is inherently linked with
uncertainty and surprise.
β’ Consider a random variable π and ask how
much information is received when a specific
value ππ for this variable is observed.
β The amount of information can be viewed as the
βdegree of surpriseβ on learning the value of π.
β’ Definition of information due to Shannon
1948.
I ο¨ X i ο© ο½ ο log ο¨ P ο¨ X i ο© ο©
where π(ππ) is probability that random
variable gains its values (evaluate it from
data set from the number of cases π has
value ππ , or try to find the probability
distribution function of π)
β’ units: depend on the base of the log
β log2 β bits, ln β nats, log10 β dits
β’ What average information content you
miss when you do not know the value of
the random variable π?
β’ This is given by the Shannonβs entropy
π»(π)
β It is a measure of the uncertainty associated
with a random variable π.
H ο¨X
N
ο© ο½ ο ο₯ ο¨ pi ο I ο¨ ai ο© ο©
i ο½1
β’ properties
β π»(π) β₯ 0, π»(π) = 0 if π = 1, π = 1
β π»(π) β€ log(π), π»(π) = log(π) if and only if
1
ππ = (equiprobable case)
π
β’ Consider two random variable π and π.
β’ Quantify the remaining entropy (i.e.
uncertainty) of a random variable π given
that the value of π is known.
β’ Conditional entropy of a random variable
π given that the value of other random
variable π is known β π»(π|π)
H ο¨ X | Y ο© ο½ οο₯
y
ο₯ P ο¨Y ο© P ο¨ X
x
| Y ο© log 2 P ο¨ X | Y
ο©
β’ Uncertainty associated with the variable π is
given by its entropy π»(π).
β’ Once you know (measure) the value of π, the
remaining entropy (i.e. uncertainty) of a
random variable π is given by the conditional
entropy π»(π|π).
β’ What is the reduction in uncertainty about π
as a consequence of the observation of π?
β’ This is given as πΌ(π, π) = π»(π) β π»(π|π).
β’ πΌ(π, π) is a mutual information.
β measures the information that π and π share
β is nonegative, symmetric
Decision trees
branch
leaf
Intelligent bioinformatics The application of artificial intelligence techniques to bioinformatics problems, Keedwell
β’ Supervised
β’ Used both for
β classification β classification tree
β regression β regression tree
β’ Advantages
β computationally undemanding
β clear, explicit reasoning, sets of rules
β accurate, robust in the face of noise
β’ How to split the data so that each subset
in the data uniquely identifies a class in
the data?
β’ Perform different tests
β i.e. split the data in subsets according to the
value of different attributes
β’ Measure the effectiveness of the tests to
choose the best one.
β’ Information based criteria are commonly
used.
β’ information gain
β gain(π₯) = info(π) β infoπ₯(π)
β Measures the information yielded by a test x.
β Reduction in uncertainty about classes as a
consequence of the test x?
β It is mutual information between the test x and
the class.
β gain criterion: select a test with maximum
information gain
β biased towards tests which have many
subsets
Gain ratio
β’ Gain criterion is biased towards tests
which have many subsets.
β’ Revised gain measure taking into account
the size of the subsets created by test is
called a gain ratio.
n
split info ο¨ x ο© ο½ ο ο₯
i ο½1
gain ratio ο¨ x ο© ο½
ο¦ Ti οΆ
ο΄ log 2 ο§
ο·ο·
ο§
T
ο¨ T οΈ
Ti
gain ο¨ x ο©
split info ο¨ x ο©
β’ J. Ross Quinlan, C4.5: Programs for machine
learning (book)
βIn my experience, the gain ratio criterion is
robust and typically gives a consistently
better choice of test than the gain criterionβ.
β’ However, Mingers J.1 finds that though gain
ratio leads to smaller trees (which is good), it
has tendency to favor unbalanced splits in
which one subset is much smaller than the
others.
1 Mingers
J., βAn empirical comparison of selection measures for decision-tree induction.β, Machine Learning 3(4), 319-342, 1989
Continuous data
β’ How to split on real, continuous data?
β’ Use threshold and comparison operators
<, β€, >, β₯ (e.g. βif Light β₯ 6 then Playβ for
Light variable being between 1 and 10).
β’ If continuous variable in the data set has π
values, there are π β 1 possible tests.
β’ Algorithm evaluates each of these splits, and
it is actually not expensive.
Pruning
β’ Decision tree overfits, i.e. it learns to
reproduce training data exactly.
β’ Strategy to prevent overfitting β pruning:
β Build the whole tree.
β Prune the tree back, so that complex
branches are consolidated into smaller (less
accurate on the training data) sub-branches.
β Pruning method uses some estimate of the
expected error.
Regression tree
Regression tree for predicting
price of 1993-model cars.
All features have been
standardized to have zero
mean and unit variance.
The R2 of the tree is 0.85,
which is significantly higher
than that
of a multiple linear regression
fit to the same data (R2 = 0.8)
Algorithms, programs
β’ ID3, C4.5, C5.0(Linux)/See5(Win) (Ross Quinlan)
β’ Only classification
β’ ID3
β uses information gain
β’ C4.5
β extension of ID3
β Improvements from ID3
β’ Handling both continuous and discrete attributes (threshold)
β’ Handling training data with missing attribute values
β’ Pruning trees after creation
β’ C5.0/See5
β Improvements from C4.5 (for comparison see
http://www.rulequest.com/see5-comparison.html)
β’ Speed
β’ Memory usage
β’ Smaller decision trees
β’ CART (Leo Breiman)
β Classification and Regression Trees
β only binary splits
Not binary
β splitting criterion β Gini impurity (index)
β’ not based on information theory
β’ Both C4.5 and CART are robust tools
β’ No method is always superior β experiment!
β’ continuous data
β use threshold and comparison operators <,
β€, >, β₯
β’ pruning
β prevents overfitting
β pre-pruning (early stopping)
β’ Stop building the tree before the whole tree is
finished.
β’ Tricky to recognize when to stop.
β post-pruning, pruning
β’ Build the whole tree
β’ Then replace some branches by leaves.
Support Vector Machine
(SVM)
New stuff
β’ supervised binary classifier (SVM)
β’ also works for regression (SVMR)
β’ two main ingrediences:
βmaximum margin
βkernel functions
Linear classification methods
β’ Decision boundaries are linear.
β’ Two class problem
β The decision boundary between the two
classes is a hyperplane (line, plane) in the
feature vector space.
Linear classifiers
π¦π = sign(π β
π + π)
denotes +1
denotes -1
πβ
π+π >0
x2
How would you
classify this data?
π = π₯1 , π₯2
π = π€1 , π€2
πβ
π+π <0
x1
Linear classifiers
denotes +1
denotes -1
Any of these
would be fine..
..but which is
best?
Linear classifiers
denotes +1
denotes -1
How would you
classify this data?
Misclassified
to +1 class
Linear classifiers
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.
Linear classifiers
denotes +1
denotes -1
Support
Vectors are the
datapoints that
the margin
pushes up
against
The maximum
margin linear
classifier is the
linear classifier with
the, um, maximum
margin.
This is the simplest
kind of SVM (called
an LSVM)
Linear SVM
Why maximum margin?
β’ Intuitively this feels safest.
β’ Small error in the location of boundary β least
chance of misclassification.
β’ LOOCV is easy, the model is immune to removal
of any non-support-vector data point.
β’ Only support vectors are important !
β’ Also theoretically well justified (statistical
learning theory).
β’ Empirically it works very, very well.
How to find a margin?
β’ Margin width, can be shown to be π =
1
π
.
β’ We want to find maximum margin, i.e. we
want to maximize π.
β’ This is equivalent to minimizing π 2 .
β’ However not every line with high margin is
the solution.
β’ The line has to have maximum margin, but
it also must classify the data.
Source: wikipedia
Quadratic constrained optimization
β’ This leads to the following quadratic constrained
optimization problem:
minimizeπ,π
subject to
1
π
2
2
π¦π π β
ππ + π β₯ 1 π = 1, β¦ , π
β’ Constrained quadratic optimization is a standard
problem in mathematical optimization.
β’ A convenient way how to solve this problem is
based on the so-called Lagrange multipliers πΆ.
π¦π = sign(π β
π + π)
β’ Constrained quadratic optimization using
Lagrange multipliers leads to the following
expansion of the weight vector π in terms of the
input examples ππ: (π¦π is the output variable, i.e.
+1 or -1)
π
π=
π¦π πΌπ ππ
π=1
β’ Only points on the margin (i.e. support vectors
xi) have Ξ±i > 0.
π
πβ
π+π =
π¦π πΌπ ππ β
π + π
π=1
π does not have to be explicitly formed
dot product
β’ Training SVM: find the sets of the
parameters πΌπ and π.
β’ Classification with SVM:
π
class(π₯π’πππππ€π ) = sign
π¦π πΌπ ππ β
πππππππ + π
π=1
β’ To classify a new pattern ππππππππ , it is only
necessary to calculate the dot product between
ππππππππ and every support vector ππ.
β If the number of support vectors is small, computation
time is significantly reduced.
Soft margin
β’ The above described margin is usually
refered to as hard margin.
β’ What if the data are not 100% linearly
separable?
β’ We allow error ΞΎi in the classification.
Soft margin
CSE 802. Prepared by Martin Law
Soft margin
β’ And we introduced capacity parameter C
- trade-off between error and margin.
β’ C is adjusted by the user
β large C β a high penalty to classification
errors, the number of misclassified patterns is
minimized (i.e. hard margin).
β’ Decrease in C: points move inside margin.
β’ Data dependent, good value to start with is
100
Kernel Functions
Nomenclature
β’ Input objects π are contained in the input
space π³.
β’ The task of classification is to find a
function that to each π assigns a value
from the output space π΄.
β In binary classification the output space has
only two elements: {β1, 1}
Nomenclature contd.
β’ A function ππ : π³ β β that maps each
object π β π³ to a real value ππ (π) is called
a feature.
β’ Combining π features ππ β¦ ππ results in a
feature mapping ππ : π³ β β± and the space
β± is called feature space.
β’ Linear classifiers have advantages, one of
them being that they often have simple
training algorithms that scale linearly with the
number of examples.
β’ What to do if the classification boundary is
non-linear?
β Can we propose an approach generating nonlinear classification boundary just by extending
the linear classifier machinery?
β Of course we can. Otherwise I wouldnβt ask.
β’ The way of making a non-linear classifier
out of a linear classier is to map our data
from the input space π³ to a feature space β±
using a non-linear mapping π(π)
π(π): π³ β β±
β’ Then the discriminant function in the space
β± is given as π π = π β
π π + b
π
transform π
π
β’ So in this case the input space π³ is one
dimensional with the dimension π₯.
β’ Feature space β± is two dimensional.
β’ Its dimensions (coordinates) are [π₯, π₯2].
β’ And feature function π(π) is π π = π₯ 2 .
β’ So the feature mapping π maps a point
from 1D input space π³ (its position is
given by the coordinate x) into 2D feature
space β±.
β’ In this space the coordinates of the point
are [π₯, π₯2].
β’ In feature space the problem is linearly
separable.
β’ It means, that this discriminant function
can be found:
π π =πβ
π π +b
Example
β’ Consider the case of 2D input space [π₯1, π₯2]
with the following mapping into 3D space:
π π = (π₯12 , 2π₯1 π₯2 , π₯22 )
features
β’ In this case, what is π β
π π ?
πβ
π π =
π π =πβ
π π +b
2
π€1 π₯1
+ π€2 2π₯1 π₯2 +
2
π€3 π₯2
β’ The approach of explicitly computing nonlinear features does not scale well with the
number of input features.
β For the above example the dimensionality of the
feature space πΉ (= 3) is roughly quadratic in the
dimensionality of the original space (= 2).
β This results in a quadratic increase in memory
and in time to train the classifier.
β’ However, the step of explicitly mapping the
data points from the low dimensional input
space to high dimensional feature space can
be avoided.
β’ We know that the discriminant function is
given by
π
π π₯ =
π¦π πΌπ ππ β
π + π
π=1
β’ In the feature space β± it becomes
π
π π₯ =
π¦π πΌπ π(ππ ) β
π(π) + π
π=1
β’ And now we use the so-called kernel trick.
We define kernel function
π π, π = π π β
π(π)
Example
π π = (x12 , 2π₯1 π₯2 , π₯22 )
π π, π = π π β
π(π)
β’ Calculate the kernel for this mapping.
π π, π = π π β
π π = x12 , 2π₯1 π₯2 , π₯22 β
z12 , 2π§1 π§2 , π§22 =
π₯12 π§12 + 2π₯1 π₯2 π§1 π§2 + π₯22 π§22 = π₯1 π§1 + π₯2 π§2 2 = π β
π
β’ So to form the dot product π π β
π(π) we do not
need to explicitly map the points π = (π₯1, π₯2) and
π = (π§1, π§2) into high dimensional feature space.
β’ This dot product is formed directly from the
coordinates in the input space as (π β π)2.
2
Kernels
β’ Linear (dot) kernel k ο¨ x , z ο© ο½ x ο z
β This is linear classifier, use it as a test of nonlinearity.
β Or as a reference for the classification
improvement with non-linear kernels.
β’ Polynomial
k ο¨ x , z ο© ο½ ο¨1 ο« x ο z ο©
d
β simple, efficient for non-linear relationships
β d β degree, high d leads to overfitting
O. Ivanciuc, Applications of SVM in Chemistry, In: Reviews in Comp. Chem. Vol 23
Polynomial kernel
d=2
d=3
d=5
d = 10
Gaussian RBF Kernel
Ο=1
ο¦
xοz
k ο¨ x , z ο© ο½ exp ο§ ο
2
ο§
2ο³
ο¨
2
οΆ
ο·
ο·
οΈ
Ο = 10
O. Ivanciuc, Applications of SVM in Chemistry, In: Reviews in Comp. Chem. Vol 23
β’ Kernel functions exist also for inputs that
are not vectors:
β sequential data (characters from the given
alphabet)
β data in the form of graphs
β’ It is possible to prove that for any given
data set there exists a kernel function
imposing linear separability !
β’ So why not always project data to higher
dimension (avoiding soft margin)?
β’ Because of the curse of dimensionality.
SVM parameters
β’ Training sets the parameters πΌπ and π.
β’ The SVM has another set of parameters
called hyperparameters.
β The soft margin constant C.
β Any parameters the kernel function depends on
β’ linear kernel β no hyperparameter (except for C)
β’ polynomial β degree
β’ Gaussian β width of Gaussian
β’ So which kernel and which parameters
should I use?
β’ The answer is data-dependent.
β’ Several kernels should be tried.
β’ Try linear kernel first and then see, if the
classification can be improved with
nonlinear kernels (tradeoff between quality
of the kernel and the number of
dimensions).
β’ Select kernel + parameters + C by
crossvalidation.
Computational aspects
β’ Classification of new samples is very
quick, training is longer (reasonably fast
for thousands of samples).
β’ Linear kernel β scales linearly.
β’ Nonlinear kernels β scale quadratically.
Multiclass SVM
β’ SVM is defined for binary classification.
β’ How to predict more than two classes
(multiclass)?
β’ Simplest approach: decompose the
multiclass problem into several binary
problems and train several binary SVMβs.
β’ one-versus-one approach
β Train a binary SVM for any two classes from
the training set
π πβ1
2
β For π-class problem create
SVM
models
β Prediction: voting procedure assigns the class
to be the class with the maximum votes
1/2
1/3
1
1/4
2/3
3
1
1
2/4
3/4
4
4
1
β’ one-versus-all approach
β For k-class problem train only k SVM models.
β Each will be trained to predict one class (+1)
vs. the rest of classes (-1)
β Prediction:
β’ Winner takes all strategy
β’ Assign new example to the class with the largest
output value π(π).
1/rest
2/rest
3/rest
4/rest
Resources
β’ SVM and Kernels for Comput. Biol., Ratsch et
al., PLOS Comput. Biol., 4 (10), 1-10, 2008
β’ What is a support vector machine, W. S. Noble,
Nature Biotechnology, 24 (12), 1565-1567, 2006
β’ A tutorial on SVM for pattern recognition, C. J. C.
Burges, Data Mining and Knowledge Discovery,
2, 121-167, 1998
β’ A Userβs Guide to Support Vector Machines, Asa
Ben-Hur, Jason Weston
β’ http://support-vector-machines.org/
β’ http://www.kernel-machines.org/
β’ http://www.support-vector.net/
β companion to the book An Introduction to Support
Vector Machines by Cristianini and Shawe-Taylor
β’ http://www.kernel-methods.net/
β companion to the book Kernel Methods for Pattern
Analysis by Shawe-Taylor and Cristianini
β’ http://www.learning-with-kernels.org/
β Several chapters on SVM from the book Learning
with Kernels by Scholkopf and Smola are available
from this site
Software
β’ SVMlight β one of the most widely used SVM
package. fast optimization, can handle very
large datasets, very efficient implementation of
the leaveβoneβout cross-validation, C++ code
β’ SVMstruct - can model complex data, such as
trees, sequences, or sets
β’ LIBSVM β multiclass, weighted SVM for
unbalanced data, cross-validation, automatic
model selection, C++, Java
Machine Learning Group
Examples of Kernel Functions
β’ Linear: K(xi,xj)= xiTxj
β Mapping Ξ¦:
x β Ο(x), where Ο(x) is x itself
β’ Polynomial of power p: K(xi,xj)= (1+ xiTxj)p
β Mapping Ξ¦:
x β Ο(x), where Ο(x) has
ο¦d ο« pοΆ
ο§ο§
ο·ο·
ο¨ p οΈ
β’ Gaussian (radial-basis function): K(xi,xj) = e
ο
dimensions
xi οx
2ο³
2
j
2
β Mapping Ξ¦: x β Ο(x), where Ο(x) is infinite-dimensional: every point is
mapped to a function (a Gaussian); combination of functions for support
vectors is the separator.
β’ Higher-dimensional space still has intrinsic dimensionality d (the mapping
is not onto), but linear separators in it correspond to non-linear separators
in original space.
University of Texas at Austin
63
Training a linear SVM
β’ To find the maximum margin separator, we have to solve
the following optimization problem:
c
for positive cases
c
for negative cases
w .x ο« b οΎ ο« 1
w .x ο« b οΌ ο 1
and
β’
|| w ||
2
is as small as possible
This is tricky but itβs a convex problem. There is only one
optimum and we can find it without fiddling with learning
rates or weight decay or early stopping.
β Donβt worry about the optimization problem. It has been
solved. Its called quadratic programming.
β It takes time proportional to N^2 which is really bad for
very big datasets
β’ so for big datasets we end up doing approximate optimization!
Introducing slack variables
β’ Slack variables are constrained to be non-negative.
When they are greater than zero they allow us to cheat
by putting the plane closer to the datapoint than the
margin. So we need to minimize the amount of cheating.
This means we have to pick a value for lamba (this
sounds familiar!)
w .x ο« b ο³ ο« 1 ο οΈ
c
for positive cases
w .x ο« b ο£ ο 1 ο« οΈ
c
for negative cases
c
c
with οΈ
and
c
ο³ 0
|| w ||
2
for all c
2
ο«ο¬
ο₯οΈ
c
c
as small as possible
Performance
β’ Support Vector Machines work very well in practice.
β The user must choose the kernel function and its
parameters, but the rest is automatic.
β The test performance is very good.
β’ They can be expensive in time and space for big datasets
β The computation of the maximum-margin hyper-plane
depends on the square of the number of training cases.
β We need to store all the support vectors.
β’ SVMβs are very good if you have no idea about what
structure to impose on the task.
β’ The kernel trick can also be used to do PCA in a much
higher-dimensional space, thus giving a non-linear version
of PCA in the original space.
Support Vector Machines are Perceptrons!
β’ SVMβs use each training case, x, to define a feature K(x,
.) where K is chosen by the user.
β So the user designs the features.
β’ Then they do βfeature selectionβ by picking the support
vectors, and they learn how to weight the features by
solving a big optimization problem.
β’ So an SVM is just a very clever way to train a standard
perceptron.
β All of the things that a perceptron cannot do cannot
be done by SVMβs (but itβs a long time since 1969 so
people have forgotten this).