Docsity

Understanding Support Vector Machines (SVM) in Machine Learning, Study notes of Engineering

Toggle sidebar
bg1
1
CS 540, University of Wisconsin-Madison, C. R. Dyer
What is a
Support Vector Machine?
• An optimally defined surface
• Typically nonlinear in the input space
• Linear in a higher dimensional space
• Implicitly defined by a kernel function
Acknowledgments: These slides combine and modify ones
provided by Andrew Moore (CMU), Glenn Fung (Wisconsin), and
Olvi Mangasarian (Wisconsin)
CS 540, University of Wisconsin-Madison, C. R. Dyer
What are Support Vector Machines
Used For?
• Classification
• Regression and data-fitting
• Supervised and unsupervised learning
CS 540, University of Wisconsin-Madison, C. R. Dyer
Linear Classifiers
f
x
y
denotes +1
denotes -1
f(x,w,b) = sign(w· x + b)
How would you
classify this data?
CS 540, University of Wisconsin-Madison, C. R. Dyer
Linear Classifiers
(aka Linear Discriminant Functions)
• Definition
It is a function that is a linear combination of the
components of the input x
where wis the weight vector and
b
the bias
• A two-category classifier then uses the rule:
Decide class
c
1
if f(x)
> 0 and class
c
2
if
f(x)
< 0
⇔Decide
c
1
if w
T
x> -b
and
c
2
otherwise
T
1
( ) m
ij j
j
f x w x b b
=
= + = +
∑w x
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Understanding Support Vector Machines (SVM) in Machine Learning and more Study notes Engineering in PDF only on Docsity!

CS 540, University of Wisconsin-Madison, C. R. Dyer

What is a

Support Vector Machine?

-^

An optimally defined surface

-^

Typically nonlinear in the input space

-^

Linear in a higher dimensional space

-^

Implicitly defined by a kernel function

Acknowledgments

:^

These slides combine and modify ones

provided by Andrew Moore (CMU), Glenn Fung (Wisconsin), andOlvi Mangasarian (Wisconsin)

CS 540, University of Wisconsin-Madison, C. R. Dyer

What are Support Vector Machines

Used For?

-^

Classification

-^

Regression and data-fitting

-^

Supervised and unsupervised learning

CS 540, University of Wisconsin-Madison, C. R. Dyer

Linear Classifiers

f

x

y

denotes +1denotes -

f( x ,w

,b

) = sign(

w

— x

b

)

How would youclassify this data?

CS 540, University of Wisconsin-Madison, C. R. Dyer

Linear Classifiers

(aka Linear Discriminant Functions)

•^

Definition

It is a function that is a linear combination of thecomponents of the input

x

where

w

is the weight vector and

b the bias

•^

A two-category classifier then uses the rule:Decide class

c^1

if f(

x

)^

0 and class

c^2

if

f(

x

)^

Decide

c^1

if w

T^ x

-b

and

c^2

T otherwise

1

( )

m

ij^

j

j

f^

x^

w x

b^

b

= =^

+^

=

∑

w x

CS 540, University of Wisconsin-Madison, C. R. Dyer

Linear Classifiers

f

x

y

denotes +1denotes -

f( x ,w

,b

) = sign(

w

— x

b

)

How would youclassify this data?

CS 540, University of Wisconsin-Madison, C. R. Dyer

Linear Classifiers

f

x

y

denotes +1denotes -

f(

x,

w

,b

) = sign(

w

— x

b

)

How would youclassify this data?

CS 540, University of Wisconsin-Madison, C. R. Dyer

Linear Classifiers

f

x

y

denotes +1denotes -

f( x ,w

,b

) = sign(

w

— x

b

)

How would youclassify this data?

CS 540, University of Wisconsin-Madison, C. R. Dyer

Linear Classifiers

f

x

y

denotes +1denotes -

f(

x,

w

,b

) = sign(

w

— x

b

)

Any of thesewould be fine …… but which isbest?

CS 540, University of Wisconsin-Madison, C. R. Dyer

Specifying a Line and Margin

  • How do we represent this mathematically?• … in

d

input dimensions?

  • An example

x

= (x

, …, x 1

)d

T

Plus-Plane

Minus-Plane

Classifier Boundary

“Predict Class = +1”

zone “Predict Class = -1”

zone

CS 540, University of Wisconsin-Madison, C. R. Dyer

Specifying a Line and Margin

•^

Plus-plane

w

T

— x

b

•^

Minus-plane =

w

T

— x

b

Plus-Plane

Minus-Plane

Classifier Boundary

“Predict Class = +1”

zone “Predict Class = -1”

zone

w

T

—^

x

  • b

if

Universeexplodes

w

T

—^

x

  • b
-^1

if

w

T

— x

  • b

if

Classify as..

wx+b=1^ wx+b=

wx+b=-

Weight vector:

w

= (w

1 , …, w

)d T

Bias or threshold:

b

CS 540, University of Wisconsin-Madison, C. R. Dyer

Computing the Margin

•^

Plus-plane

w x

b

•^

Minus-plane =

w x

b

Claim:

The vector

w

is perpendicular to the Plus-Plane

“Predict Class = +1”

zone “Predict Class = -1”

zone

wx+b= wx+b=0^ wx+b=-

M =

Margin

(width)

How do we compute

M

in terms of

w

and

b

w

CS 540, University of Wisconsin-Madison, C. R. Dyer

w

is the plane’s normal vector b is the distance from the origin

CS 540, University of Wisconsin-Madison, C. R. Dyer

Computing the Margin

•^

Plus-plane

w x

b

•^

Minus-plane =

w x

b

•^

The vector

w

is perpendicular to the Plus Plane

•^

Let

x

-^ be any point on the minus plane

•^

Let

x

be the closest plus-plane-point to

x

“Predict Class = +1”

zone “Predict Class = -1”

zone

wx+b= wx+b=0^ wx+b=-

M =

Margin

How do we compute

M

in terms of

w

and

b

  • x
  • x

Any location in ´^ m: not Any location inmRnecessarily adatapoint

: not necessarily adata point

w

CS 540, University of Wisconsin-Madison, C. R. Dyer

Computing the Margin

•^

Plus-plane

w x

b

•^

Minus-plane =

w x

b

•^

The vector

w

is perpendicular to the Plus Plane

•^

Let

x

-^ be any point on the minus plane

•^

Let

x

be the closest plus-plane-point to

x

•^

Claim

x

x

-^

λ w

for some value of

λ

.^

Why?

“Predict Class = +1”

zone “Predict Class = -1”

zone

wx+b=1^ wx+b=

wx+b=-

M =

Margin

How do we compute

M

in terms of

w

and

b

  • x x

w

CS 540, University of Wisconsin-Madison, C. R. Dyer

Computing the Margin

•^

Plus-plane

w x

b

•^

Minus-plane =

w x

b

•^

The vector

w

is perpendicular to the Plus Plane

•^

Let

x

-^ be any point on the minus plane

•^

Let

x

be the closest plus-plane-point to

x

•^

Claim

x

+^

x

-^

λ w

for some value of

λ

.^

Why?

“Predict Class = +1”

zone “Predict Class = -1”

zone

wx+b= wx+b=0^ wx+b=-

M =

Margin

How do we compute

M

in terms of

w

and

b

  • x
  • x

The line from

x

-^

to

x

+^

is

perpendicular to theplanes So to get from

x

-^ to

x

travel some distance indirection

w

w

CS 540, University of Wisconsin-Madison, C. R. Dyer

Computing the Margin

What we know:•

w x

+^

b

w x

-^

b

-^1

x

x

-^

λ^

w

•^

|^ x

x

-^

M

It’s now easy to get

M

in terms of

w

and

b

“Predict Class = +1”

zone “Predict Class = -1”

zone

wx+b=1^ wx+b=

wx+b=-

M =

Margin

  • x x

w

CS 540, University of Wisconsin-Madison, C. R. Dyer

Uh-oh!

denotes +1denotes -

This is going to be a problem!What should we do?

CS 540, University of Wisconsin-Madison, C. R. Dyer

Uh-oh!

denotes +1denotes -

This is going to be a problem!What should we do? Idea 1:

Find minimum ||

w

2 , while

minimizing number oftraining set errors

Problem: Two things tominimize makes for anill-defined optimization

CS 540, University of Wisconsin-Madison, C. R. Dyer

Uh-oh!

denotes +1denotes -

This is going to be a problem!What should we do? Idea 1.1:

Minimize||

w

2

  • C (#train errors)

There’s a serious practicalproblem that’s about to makeus reject this approach. Canyou guess what it is?

Tradeoff parameter

CS 540, University of Wisconsin-Madison, C. R. Dyer

Uh-oh!

denotes +1denotes -

This is going to be a problem!What should we do? Idea 1.1:

Minimize||

w

2

  • C

(#train errors)

There’s a serious practicalproblem that’s about to makeus reject this approach. Canyou guess what it is?

Tradeoff parameter

Can’t be expressed as a Quadratic

Programming problem. Solving it may be too slow. (Also, doesn’t distinguish betweendisastrous errors and near misses)

So… any

otherideas?

CS 540, University of Wisconsin-Madison, C. R. Dyer

Uh-oh!

denotes +1denotes -

This is going to be a problem!What should we do? Idea 2.0:

Minimize||

w

2

  • C

(distance of^ error points to^ their correctplace)

CS 540, University of Wisconsin-Madison, C. R. Dyer

Learning Maximum Margin with Noise

Given guess of

w

b,

we can

•^

Compute sum of distancesof points to their correctzones

-^

Compute the margin width Assume

N

examples, each

(x

k^

yk

) where

y k^

wx+b= wx+b=0^ wx+b=-

M =

w w

What should our quadratic

optimization criterion be?

How many constraints will we

have? What should they be?

CS 540, University of Wisconsin-Madison, C. R. Dyer

Learning Maximum Margin with Noise

Given guess of

w

b we can

•^

Compute sum of distancesof points to their correctzones

-^

Compute the margin width Assume

N

examples, each

(x

,k

yk

)^

where

y k^

wx+b= wx+b=0^ wx+b=-

M =

w w

What should our quadratic

optimization criterion be? Minimize

1

1

. 2

N

k

k C

=

w w

ε^11 ε^7

ε^2

How many constraints will we

have?

N

What should they be? w

x

k^

b

εk

if

y k^

w

x

k^

b

εk

if

yk

CS 540, University of Wisconsin-Madison, C. R. Dyer

Suppose we’re in 1 Dimension

What would

SVMs do withthis data?

x=

CS 540, University of Wisconsin-Madison, C. R. Dyer

  • CS 540, University of Wisconsin-Madison, C. R. Dyer

Project examples into some higher dimensional spacewhere the data

is

linearly separable, defined by

z

F

(x

Training depends only on dot products of the form

F(

xi ) —

F(

x

)j

Example:

K

(x

,i

x

) =j

F

(x

) —i

F

(x

) = (j

x

i^

—^

x

)j

2

Dimensionality of

z

space is generally much larger than

the dimension of input space

x

2

2

1

1

2

2

(^

,^

,^

F

x

x x

x

x

CS 540, University of Wisconsin-Madison, C. R. Dyer

Common SVM Basis Functions

z

k^

=

( polynomial terms of

x

k^

of degree 1 to

q

For example, when

q

=2 and

m

K

(x

,y

) = (x

y 1 1

  • x

y 2 2

2

= 1 + 2x

y 1 1

  • 2x

y 2 2

  • 2x

x 1

y 2

y 1 2

  • x

(^21) y

(^21)

  • x

(^22) y

(^22)

z

k^

=

( radial basis functions of

x

k^

z

k^

=

( sigmoid functions of

x

k^

 

^ 

−

=

=

KW

|

|

KernelFn ) (

] [^

j

k

k j

k

j^

c

x

x

z

CS 540, University of Wisconsin-Madison, C. R. Dyer

SVM Kernel Functions

K

(^ a

,b

)^ =

(^ a

.

b

d)

is an example of an SVM

kernel function

  • Beyond polynomials there are other very high

dimensional basis functions that can be madepractical by finding the right kernel function• Radial-Basis-style Kernel Function:• Neural-Net-style Kernel Function:

^ 
=^

2

2

2

exp ) , (

b σ a

b a K

tanh( ) , (

δ

κ

b a

b a K

σ ,^ κ

and

δ

are magic

parameters that mustbe chosen by a modelselection methodsuch as CV or VCSRM

CS 540, University of Wisconsin-Madison, C. R. Dyer

The Federalist Papers

Written in 1787-1788 by Alexander

Hamilton

John Jay, and James

Madison

to persuade the

citizens of New York to ratify the constitution

-^

Papers consisted of short essays, 900 to 3500 wordsin length

-^

Authorship of

of those papers have been in

dispute (

Madison

or

Hamilton

); these papers are

referred to as the

disputed Federalist papers

CS 540, University of Wisconsin-Madison, C. R. Dyer

Description

of

the

Data

For every paper: •^

Machine readable text was created using a scanner

-^

Computed relative frequencies of

words that

Mosteller-Wallace identified as good candidates forauthor-attribution studies

-^

Each document is represented as a vector containing the70 real numbers corresponding to the

word

frequencies

The dataset consists of

118

papers:

•^

Madison papers

-^

Hamilton papers

-^

disputed papers

CS 540, University of Wisconsin-Madison, C. R. Dyer

Function Words Based on Relative

Frequencies

SLA Feature Selection for Classifying CS 540, University of Wisconsin-Madison, C. R. Dyer

the Disputed Federalist Papers

Apply the SVM Successive LinearizationAlgorithm for feature selection to: •^

Train on the 106 Federalist papers with knownauthors

-^

Find a classification hyperplane that uses as fewwords as possible

  • Use the hyperplane to classify the 12

disputed papers

CS 540, University of Wisconsin-Madison, C. R. Dyer

Summary

  • Learning linear functions
    • Pick separating plane that maximizes margin• Separating plane defined in terms of support

vectors only

  • Learning non-linear functions
    • Project examples into higher dimensional space• Use kernel functions for efficiency
      • Generally avoids over-fitting problem• Global optimization method; no local optima• Can be expensive to apply, especially for multi-

class problems