Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin...

22
1 Solving optimal margin classifier Recall our opt problem: This is equivalent to Write the Lagrangian: Recall that (*) can be reformulated as Now we solve its dual problem: i b x w y w i T i b w + , ) ( s.t max , 1 1 i b x w y w w i T i T b w + , ) ( s.t min , 0 1 2 1 [ ] = + = m i i T i i T b x w y w w b w 1 1 2 1 ) ( ) , , ( α α L * ( ) ) , , ( max min , α α b w i b w L 0 ) , , ( min max , α α b w b w i L 0

Transcript of Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin...

Page 1: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

1

Solving optimal margin classifierRecall our opt problem:

This is equivalent to

Write the Lagrangian:

Recall that (*) can be reformulated asNow we solve its dual problem:

ibxwy

w

iT

i

bw

∀≥+ ,)(s.tmax ,

1

1

ibxwy

ww

iT

i

Tbw

∀≤+− ,)(s.tmin ,

0121

[ ]∑=

−+−=m

ii

Tii

T bxwywwbw1

121 )(),,( ααL

*( )

),,(maxmin , αα bw ibw L0≥

),,(minmax , αα bwbwiL0≥

Page 2: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

2

***( )

The Dual Problem

We minimize L with respect to w and b first:

Note that (*) implies:

Plus (***) back to L , and using (**), we have:

),,(minmax , αα bwbwiL0≥

, ),,( ∑=

=−=∇m

iiiiw xywbw

10ααL

, ),,( ∑=

==∇m

iiib ybw

10ααL

∑=

=m

iiii xyw

*( )

∑∑==

−=m

jij

Tijiji

m

ii yybw

11 21

,

)(),,( xxααααL

**( )

The Dual problem, cont.Now we have the following dual opt problem:

This is, (again,) a quadratic programming problem.A global maximum of αi can always be found. But what's the big deal??Note two things:

1. w can be recovered by

2. The "kernel"

∑∑==

−=m

jij

Tijiji

m

ii yy

11 21

,

)()(max xxααααα J

.

,, , s.t.

∑=

=

=≥m

iii

i

y

ki

10

10

α

α K

∑=

=m

iiii yw

1xα

jTi xx

See next …

More later …

Page 3: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

3

Support vectorsNote the KKT condition --- only a few αi's can be nonzero!!

kiwgα ii ,, ,)( K10 ==

α6=1.4

Class 1

Class 2

α1=0.8

α2=0

α3=0

α4=0

α5=0α7=0

α8=0.6

α9=0

α10=0

Call the training data points whose αi's are nonzero the support vectors (SV)

Support vector machinesOnce we have the Lagrange multipliers {αi}, we can reconstruct the parameter vector w as a weighted combination of the training examples:

For testing with a new data zCompute

and classify z as class 1 if the sum is positive, and class 2 otherwise

Note: w need not be formed explicitly

∑∈

=SVi

iii yw xα

( ) bzybzwSVi

Tiii

T +=+ ∑∈

Page 4: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

4

Interpretation of support vector machines

The optimal w is a linear combination of a small number of data points. This “sparse” representation can be viewed as data compression as in the construction of kNN classifier

To compute the weights {αi}, and to use support vector machines we need to specify only the inner products (or kernel) between the examples

We make decisions by comparing each new example z with only the support vectors:

jTi xx

( ) ⎟⎠

⎞⎜⎝

⎛+= ∑

bzyySVi

Tiii xαsign*

Non-linearly Separable Problems

We allow “error” ξi in classification; it is based on the output of the discriminant function wTx+bξi approximates the number of misclassified samples

Class 1

Class 2

Page 5: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

5

Soft Margin HyperplaneNow we have a slightly different opt problem:

ξi are “slack variables” in optimizationNote that ξi=0 if there is no error for xi

ξi is an upper bound of the number of errorsC : tradeoff parameter between error and margin

, ,)(

s.ti

ibxwy

i

iiT

i

∀≥∀−≥+

01

ξξ

∑=

+m

ii

Tbw Cww

121 ξ,min

The Optimization ProblemThe dual of this new constrained optimization problem is

This is very similar to the optimization problem in the linear separable case, except that there is an upper bound C on αinowOnce again, a QP solver can be used to find αi

∑∑==

−=m

jij

Tijiji

m

ii yy

11 21

,

)()(max xxααααα J

.

,, ,0 s.t.

∑=

=

=≤≤m

iii

i

y

kiC

10

1

α

α K

Page 6: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

6

Extension to Non-linear Decision Boundary

So far, we have only considered large-margin classifier with a linear decision boundaryHow to generalize it to become nonlinear?Key idea: transform xi to a higher dimensional space to “make life easier”

Input space: the space the point xi are locatedFeature space: the space of φ(xi) after transformation

Why transform?Linear operation in the feature space is equivalent to non-linear operation in input spaceClassification can become easier with a proper transformation.

Transforming the Data

Computation in the feature space can be costly because it is high dimensional

The feature space is typically infinite-dimensional!

The kernel trick comes to rescue

φ( )

φ( )

φ( )φ( )φ( )

φ( )

φ( )φ( )

φ(.) φ( )

φ( )

φ( )φ( )

φ( )

φ( )

φ( )

φ( )φ( ) φ( )

Feature spaceInput spaceNote: feature space is of higher dimension than the input space in practice

Page 7: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

7

The Kernel TrickRecall the SVM optimization problem

The data points only appear as inner productAs long as we can calculate the inner product in the feature space, we do not need the mapping explicitlyMany common geometric operations (angles, distances) can be expressed by inner productsDefine the kernel function K by

∑∑==

−=m

jij

Tijiji

m

ii yy

11 21

,

)()(max xxααααα J

.

,, ,0 s.t.

∑=

=

=≤≤m

iii

i

y

kiC

10

1

α

α K

)()(),( jT

ijiK xxxx φφ=

An Example for feature mapping and kernels

Consider an input x=[x1,x2]Suppose φ(.) is given as follows

An inner product in the feature space is

So, if we define the kernel function as follows, there is no need to carry out φ(.) explicitly

2122

2121

2

1 2221 xxxxxxxx

,,,,,=⎟⎟⎠

⎞⎜⎜⎝

⎛⎥⎦

⎤⎢⎣

⎡φ

=⎟⎟⎠

⎞⎜⎜⎝

⎛⎥⎦

⎤⎢⎣

⎡⎟⎟⎠

⎞⎜⎜⎝

⎛⎥⎦

⎤⎢⎣

⎡''

,2

1

2

1

xx

xx

φφ

( )21 ')',( xxxx TK +=

Page 8: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

8

More examples of kernel functions

Linear kernel (we've seen it)

Polynomial kernel (we just saw an example)

where p = 2, 3, … To get the feature vectors we concatenate all pth order polynomial terms of the components of x (weighted appropriately)

Radial basis kernel

In this case the feature space consists of functions and results in a non-parametric classifier.

')',( xxxx TK =

( )pTK ')',( xxxx += 1

⎟⎠⎞

⎜⎝⎛ −−= 2

21 'exp)',( xxxxK

Kernelized SVMTraining:

Using:

∑∑==

−=m

jijijiji

m

ii Kyy

1,1

),(21)(max xxααααα J

.

,, ,0 s.t.

∑=

=

=≤≤m

iii

i

y

kiC

10

1

α

α K

( ) ⎟⎠

⎞⎜⎝

⎛+= ∑

bzKyySVi

iii ,sign* xα

Page 9: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

9

SVM examples

Examples for Non Linear SVMs –Gaussian Kernel

Page 10: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

10

Cross-validation errorThe leave-one-out cross-validation error does not depend on the dimensionality of the feature space but only on the # of support vectors!

examples trainingof #ctorssupport ve #error CVout -one-Leave =

Machine LearningMachine Learning

1010--701/15701/15--781, Fall 2006781, Fall 2006

BoostingBoosting

Eric XingEric Xing

Lecture 9, October 10, 2006

Reading: Chap. 14.3, C.B book

Page 11: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

11

Rationale: Combination of methods

There is no algorithm that is always the most accurate

We can select simple “weak” classification or regression methods and combine them into a single “strong” method

Different learners use different

AlgorithmsHyperparametersRepresentations (Modalities)Training setsSubproblems

The problem: how to combine them

Some early algorithmsBoosting by filtering (Schapire 1990)

Run weak learner on differently filtered example setsCombine weak hypothesesRequires knowledge on the performance of weak learner

Boosting by majority (Freund 1995)Run weak learner on weighted example setCombine weak hypotheses linearlyRequires knowledge on the performance of weak learner

Bagging (Breiman 1996)Run weak learner on bootstrap replicates of the training setAverage weak hypothesesReduces variance

Page 12: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

12

Combination of classifiersSuppose we have a family of component classifiers (generating ±1 labels) such as decision stumps:

where θ = {k,w,b}

Each decision stump pays attention to only a single component of the input vector

( )bwxxh k += sign);( θ

Combination of classifiers con’dWe’d like to combine the simple classifiers additively so that the final classifier is the sign of

where the “votes” {αi} emphasize component classifiers that make more reliable predictions than others

Important issues:what is the criterion that we are optimizing? (measure of loss)we would like to estimate each new component classifier in the same manner (modularity)

);();()(ˆ mmhhh θαθα xxx ++= K11

Page 13: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

13

Measurement of errorLoss function:

Generalization error:

Objective: find h with minimum generalization error

Main boosting idea: minimize the empirical error:

( ) ))(( e.g. ))(,( xx hyIhy ≠λ

[ ]))(,()( xhyEhL λ=

∑=

=N

nnn hy

NhL

1

1 ))(,()(ˆ xλ

Exponential LossOne possible measure of empirical loss is

The combined classifier based on m − 1 iterations defines a weighted loss criterion for the next simple classifier to addeach training sample is weighted by its "classifiability" (or difficulty) seen by the classifier we have built so far

{ }

{ }

{ } { }

{ });(exp

);(exp)(ˆexp

);()(ˆexp

)(ˆexp

mimi

n

i

mi

mimi

n

iimi

n

imimiimi

n

iimi

hayW

hayhy

hayhy

hy

θ

θ

θ

x

xx

xx

x

−=

−−=

−−=

=

=−

=−

=

1

1

11

11

1

);();()(ˆ mmhhh θαθα xxx ++= K11

Page 14: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

14

Linearization of loss functionWe can simplify a bit the estimation criterion for the new component classifiers (assuming α is small)

Now our empirical loss criterion reduces to

We could choose a new component classifier to optimize this weighted agreement

{ } );();(exp mimimimi hayhay θθ xx −≈− 1

{ }

∑∑

=

=

=

=

−=

−≈

n

imii

mim

n

i

mi

mimi

n

i

mi

n

iimi

hyWaW

hayW

hy

1

1

1

1

1

1

1

1

);(

));((

)(ˆexp

θ

θ

x

x

x

A possible algorithmAt stage m we find θ* that maximize (or at least give a sufficiently high) weighted agreement:

each sample is weighted by its "difficulty" under the previously combined m − 1 classifiers,more "difficult" samples received heavier attention as they dominates the total loss

Then we go back and find the “votes” αm* associated with the new classifier by minimizing the original weighted (exponential) loss

∑=

−n

imii

mi hyW

1

1 );( *θx

{ });(exp mimi

n

i

mi hayW θx−∑

=

1

1

Page 15: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

15

BoostingWe have basically derived a Boosting algorithm that sequentially adds new component classifiers, each trained on reweighted training examples

each component classifier is presented with a slightly different problem

AdaBoost preliminaries:we work with normalized weights Wi on the training examples, initially uniform ( Wi = 1/n)the weight reflect the "degree of difficulty" of each datum on the latest classifier

The AdaBoost algorithmAt the kth iteration we find (any) classifier h(x; θk*) for which the weighted classification error:

is better than change.This is meant to be "easy" --- weak classifier

Determine how many “votes” to assign to the new component classifier:

stronger classifier gets more votes

Update the weights on the training examples:

⎟⎠

⎞⎜⎝

⎛−= ∑

=

−n

ikii

kik hyW

1

1

2150 );(. *θε x

( )kkk εε /)(log. −= 150α

{ });(exp kikik

ik

i hayWW θx−= −1

Page 16: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

16

The AdaBoost algorithm cont’dThe final classifier after m boosting iterations is given by thesign of

the votes here are normalized for convenience

m

mmhhhαα

θαθα++++

=K

K

1

11 );();()(ˆ xxx

AdaBoost: summaryInput:

N examples SN = {(x1,y1),…, (xN,yN)}a weak base learner h = h(x,θ)

Initialize: equal example weights wi = 1/N for all i = 1..NIterate for t = 1…T:

1. train base learner according to weighted example set (wt,x) and obtain hypothesis ht = h(x,θt)

2. compute hypothesis error εt

3. compute hypothesis weight αt

4. update example weights for next iteration wt+1

Output: final hypothesis as a linear combination of ht

Page 17: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

17

AdaBoost: dataflow diagram

w1 w2 wTA(w,S) A(w,S) A(w,S)

Boosting: examples

Page 18: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

18

Boosting: example cont’d

Boosting: example cont’d

Page 19: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

19

Base LearnersWeak learners used in practice:

Decision stumps (axis parallel splits)Decision trees (e.g. C4.5 by Quinlan 1996)Multi-layer neural networksRadial basis function networks

Can base learners operate on weighted examples?In many cases they can be modified to accept weights along with the examplesIn general, we can sample the examples (with replacement) according to the distribution defined by the weights

Boosting performance

The error rate of component classifier (the decision stumps) does not improve much (if at all) over time

But both training and testing error improve over time!

Even after the training error of the combined classifier goes to zero, boosting iterations can still improve the generalization error!!

Page 20: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

20

Why it is working?You will need some learning theory (to be covered in the next two lectures) to understand this fully, but for now let's just go over some high level ideasGeneralization Error:

With high probability, Generalization error is less than:

As T goes up, our bound becomes worse, Boosting should overfit!

Trainingerror

Testerror

The Boosting Approach to Machine Learning, by Robert E. Schapire

Experiments

Page 21: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

21

Training MarginsWhen a vote is taken, the more predictors agreeing, the more confident you are in your prediction.

Margin for example:

The margin lies in [−1, 1] and is negative for all misclassified examples.

Successive boosting iterations improve the majority vote or margin for the training examples

⎥⎦

⎤⎢⎣

⎡++++

=m

mimiiiih

hhy,yαα

θαθαK

K

1

11 );();( )(margin xxx

More Experiments

The Boosting Approach to Machine Learning, by Robert E. Schapire

Page 22: Solving optimal margin classifierepxing/Class/10701-06f/lectures/lecture9...Solving optimal margin classifier zRecall our opt problem: zThis is equivalent to zWrite the Lagrangian:

22

A Margin Bound

Robert E. Schapire, Yoav Freund, Peter Bartlett and Wee Sun Lee. Boosting the margin: A new explanation for the effectiveness of voting methods.

The Annals of Statistics, 26(5):1651-1686, 1998.

For any γ, the generalization error is less than:

It does not depend on T!!!

( ) ⎟⎟⎠

⎞⎜⎜⎝

⎛+≤ 2γ

γm

dO,yh )(marginPr x

SummaryBoosting takes a weak learner and converts it to a strongone

Works by asymptotically minimizing the empirical error

Effectively maximizes the margin of the combined hypothesis