Support vector machines (SVMs) Lecture 5 David Sontag - - PowerPoint PPT Presentation

support vector machines svms lecture 5
SMART_READER_LITE
LIVE PREVIEW

Support vector machines (SVMs) Lecture 5 David Sontag - - PowerPoint PPT Presentation

Support vector machines (SVMs) Lecture 5 David Sontag New York University So5 margin SVM w . x + b = +1 w . x + b = 0 w . x + b =


slide-1
SLIDE 1

Support ¡vector ¡machines ¡(SVMs) ¡ Lecture ¡5 ¡

David ¡Sontag ¡ New ¡York ¡University ¡

slide-2
SLIDE 2

So5 ¡margin ¡SVM ¡

w.x ¡+ ¡b ¡= ¡+1 ¡ w.x ¡+ ¡b ¡= ¡-­‑1 ¡ w.x ¡+ ¡b ¡= ¡0 ¡

Slack ¡penalty ¡C > 0: ¡

  • C=∞ ¡minimizes ¡upper ¡bound ¡on ¡0-­‑1 ¡loss ¡
  • C≈0 ¡ ¡points ¡with ¡ξi=0 ¡have ¡big ¡margin ¡
  • ¡Select ¡using ¡cross-­‑valida=on ¡

“slack ¡variables” ¡ ξ2 ξ1 ξ3 ξ4 Support ¡vectors: ¡ Data ¡points ¡for ¡which ¡the ¡constraints ¡are ¡binding ¡ ¡

slide-3
SLIDE 3

QP ¡form: ¡ More ¡“natural” ¡form: ¡

Empirical ¡loss ¡ RegularizaNon ¡ term ¡

Equivalent ¡if ¡

So5 ¡margin ¡SVM ¡

slide-4
SLIDE 4

Subgradient ¡ (for ¡non-­‑differenNable ¡funcNons) ¡

slide-5
SLIDE 5

(Sub)gradient ¡descent ¡of ¡SVM ¡objecNve ¡

Step ¡size: ¡

  • ­‑ ¡
slide-6
SLIDE 6

The ¡Pegasos ¡Algorithm ¡

Pegasos ¡Algorithm ¡(from ¡homework) ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ For ¡iter ¡= ¡1,2,…,20 ¡ ¡For ¡j=1,2,…,|data| ¡ ¡ ¡t ¡= ¡t+1 ¡ ¡ ¡ηt ¡= ¡1/(tλ) ¡ ¡ ¡If ¡yj(wt ¡xj) ¡< ¡1 ¡ ¡ ¡ ¡wt+1 ¡= ¡(1-­‑ηtλ) ¡wt ¡+ ¡ηt ¡yj ¡xj ¡ ¡ ¡Else ¡ ¡ ¡ ¡wt+1 ¡= ¡(1-­‑ηtλ) ¡wt ¡ Output: ¡wt+1 ¡ General ¡framework ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ While ¡not ¡converged ¡ ¡t ¡= ¡t+1 ¡ ¡Choose ¡a ¡stepsize, ¡ηt ¡ ¡Choose ¡a ¡direcNon, ¡pt ¡ ¡Go! ¡ ¡ ¡Test ¡for ¡convergence ¡ Output: ¡wt+1 ¡

slide-7
SLIDE 7

Pegasos ¡Algorithm ¡(from ¡homework) ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ For ¡iter ¡= ¡1,2,…,20 ¡ ¡For ¡j=1,2,…,|data| ¡ ¡ ¡t ¡= ¡t+1 ¡ ¡ ¡ηt ¡= ¡1/(tλ) ¡ ¡ ¡If ¡yj(wt ¡xj) ¡< ¡1 ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηt(λwt-­‑ ¡ ¡yjxj) ¡ ¡ ¡Else ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηtλwt ¡ Output: ¡wt+1 ¡ General ¡framework ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ While ¡not ¡converged ¡ ¡t ¡= ¡t+1 ¡ ¡Choose ¡a ¡stepsize, ¡ηt ¡ ¡Choose ¡a ¡direcNon, ¡pt ¡ ¡Go! ¡ ¡ ¡Test ¡for ¡convergence ¡ Output: ¡wt+1 ¡

The ¡Pegasos ¡Algorithm ¡

slide-8
SLIDE 8

Pegasos ¡Algorithm ¡(from ¡homework) ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ For ¡iter ¡= ¡1,2,…,20 ¡ ¡For ¡j=1,2,…,|data| ¡ ¡ ¡t ¡= ¡t+1 ¡ ¡ ¡ηt ¡= ¡1/(tλ) ¡ ¡ ¡If ¡yj(wt ¡xj) ¡< ¡1 ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηt(λwt-­‑ ¡ ¡yjxj) ¡ ¡ ¡Else ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηtλwt ¡ Output: ¡wt+1 ¡

Convergence ¡choice ¡: ¡Fixed ¡number ¡of ¡itera=ons ¡ ¡ ¡ ¡ ¡ ¡ ¡T=20*|data| ¡

General ¡framework ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ While ¡not ¡converged ¡ ¡t ¡= ¡t+1 ¡ ¡Choose ¡a ¡stepsize, ¡ηt ¡ ¡Choose ¡a ¡direcNon, ¡pt ¡ ¡Go! ¡ ¡ ¡Test ¡for ¡convergence ¡ Output: ¡wt+1 ¡

The ¡Pegasos ¡Algorithm ¡

slide-9
SLIDE 9

Pegasos ¡Algorithm ¡(from ¡homework) ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ For ¡iter ¡= ¡1,2,…,20 ¡ ¡For ¡j=1,2,…,|data| ¡ ¡ ¡t ¡= ¡t+1 ¡ ¡ ¡ηt ¡= ¡1/(tλ) ¡ ¡ ¡If ¡yj(wt ¡xj) ¡< ¡1 ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηt(λwt-­‑ ¡ ¡yjxj) ¡ ¡ ¡Else ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηtλwt ¡ Output: ¡wt+1 ¡ General ¡framework ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ While ¡not ¡converged ¡ ¡t ¡= ¡t+1 ¡ ¡Choose ¡a ¡stepsize, ¡ηt ¡ ¡Choose ¡a ¡direcNon, ¡pt ¡ ¡Go! ¡ ¡ ¡Test ¡for ¡convergence ¡ Output: ¡wt+1 ¡

Stepsize ¡choice: ¡-­‑ ¡Ini=alize ¡with ¡1/λ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡-­‑ ¡Decays ¡with ¡1/t ¡

The ¡Pegasos ¡Algorithm ¡

slide-10
SLIDE 10

Pegasos ¡Algorithm ¡(from ¡homework) ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ For ¡iter ¡= ¡1,2,…,20 ¡ ¡For ¡j=1,2,…,|data| ¡ ¡ ¡t ¡= ¡t+1 ¡ ¡ ¡ηt ¡= ¡1/(tλ) ¡ ¡ ¡If ¡yj(wt ¡xj) ¡< ¡1 ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηt(λwt-­‑ ¡ ¡yjxj) ¡ ¡ ¡Else ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηtλwt ¡ Output: ¡wt+1 ¡ General ¡framework ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ While ¡not ¡converged ¡ ¡t ¡= ¡t+1 ¡ ¡Choose ¡a ¡stepsize, ¡ηt ¡ ¡Choose ¡a ¡direc=on, ¡pt ¡ ¡Go! ¡ ¡ ¡Test ¡for ¡convergence ¡ Output: ¡wt+1 ¡

Direc=on ¡choice: ¡ ¡Stochas=c ¡approx ¡to ¡the ¡subgradient ¡

The ¡Pegasos ¡Algorithm ¡

slide-11
SLIDE 11

Subgradient ¡calculaNon ¡

λ 2 ||w||2 + 1 m X

i

max{0, 1 − yiw · xi}

λ 2 ||w||2 + max{0, 1 − yiw · xi}

Objec=ve: ¡ Stochas=c ¡Approx: ¡ For ¡a ¡randomly ¡chosen ¡data ¡point ¡i ¡ (in ¡the ¡assignment ¡the ¡choice ¡of ¡i ¡is ¡not ¡random ¡-­‑ ¡easier ¡ to ¡debug ¡and ¡compare ¡between ¡students). ¡

slide-12
SLIDE 12

Subgradient ¡calculaNon ¡

λ 2 ||w||2 + 1 m X

i

max{0, 1 − yiw · xi}

λ 2 ||w||2 + max{0, 1 − yiw · xi}

Objec=ve: ¡ Stochas=c ¡Approx: ¡ (sub)gradient: ¡

λ||w|| + d dw max{0, 1 − yiw · xi}

slide-13
SLIDE 13

Subgradient ¡calculaNon ¡

λ 2 ||w||2 + 1 m X

i

max{0, 1 − yiw · xi}

λ 2 ||w||2 + max{0, 1 − yiw · xi}

Objec=ve: ¡ Stochas=c ¡Approx: ¡ (sub)gradient: ¡

λ||w|| + d dw max{0, 1 − yiw · xi}

yiw · xi

>1 ¡ <1 ¡ =1 ¡

−yixi

1 ¡ 0 ¡ 0 ¡

yiw · xi

slide-14
SLIDE 14

Subgradient ¡calculaNon ¡

λ 2 ||w||2 + 1 m X

i

max{0, 1 − yiw · xi}

λ 2 ||w||2 + max{0, 1 − yiw · xi}

Objec=ve: ¡ Stochas=c ¡Approx: ¡ (sub)gradient: ¡

λ||w|| + d dw max{0, 1 − yiw · xi}

yiw · xi

>1 ¡ <1 ¡ =1 ¡

−yixi

1 ¡ 0 ¡ 0 ¡

yiw · xi

slide-15
SLIDE 15

Subgradient ¡calculaNon ¡

λ 2 ||w||2 + 1 m X

i

max{0, 1 − yiw · xi}

λ 2 ||w||2 + max{0, 1 − yiw · xi}

Objec=ve: ¡ Stochas=c ¡Approx: ¡ (sub)gradient: ¡

if yiw · xi < 1 else λw − yixi λw + 0

slide-16
SLIDE 16

Pegasos ¡Algorithm ¡(from ¡homework) ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ For ¡iter ¡= ¡1,2,…,20 ¡ ¡For ¡j=1,2,…,|data| ¡ ¡ ¡t ¡= ¡t+1 ¡ ¡ ¡ηt ¡= ¡1/(tλ) ¡ ¡ ¡If ¡yj(wt ¡xj) ¡< ¡1 ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηt(λwt-­‑ ¡ ¡yjxj) ¡ ¡ ¡Else ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηt(λwt ¡+ ¡0) ¡ Output: ¡wt+1 ¡ General ¡framework ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ While ¡not ¡converged ¡ ¡t ¡= ¡t+1 ¡ ¡Choose ¡a ¡stepsize, ¡ηt ¡ ¡Choose ¡a ¡direc=on, ¡pt ¡ ¡Go! ¡ ¡ ¡Test ¡for ¡convergence ¡ Output: ¡wt+1 ¡

Direc=on ¡choice: ¡ ¡Stochas=c ¡approx ¡to ¡the ¡subgradient ¡

The ¡Pegasos ¡Algorithm ¡

if yiw · xi < 1 else λw − yixi λw + 0

slide-17
SLIDE 17

Pegasos ¡Algorithm ¡(from ¡homework) ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ For ¡iter ¡= ¡1,2,…,20 ¡ ¡For ¡j=1,2,…,|data| ¡ ¡ ¡t ¡= ¡t+1 ¡ ¡ ¡ηt ¡= ¡1/(tλ) ¡ ¡ ¡If ¡yj(wt ¡xj) ¡< ¡1 ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηt(λwt-­‑ ¡ ¡yjxj) ¡ ¡ ¡Else ¡ ¡ ¡ ¡wt+1 ¡= ¡wt ¡– ¡ηtλwt ¡ Output: ¡wt+1 ¡ General ¡framework ¡ Ini=alize: ¡w1 ¡= ¡0, ¡t=0 ¡ While ¡not ¡converged ¡ ¡t ¡= ¡t+1 ¡ ¡Choose ¡a ¡stepsize, ¡ηt ¡ ¡Choose ¡a ¡direcNon, ¡pt ¡ ¡Go! ¡ ¡ ¡Test ¡for ¡convergence ¡ Output: ¡wt+1 ¡

Go: ¡ ¡update ¡wt+1 ¡= ¡wt ¡-­‑ ¡ηtpt ¡

The ¡Pegasos ¡Algorithm ¡

slide-18
SLIDE 18

Why ¡is ¡this ¡algorithm ¡interesNng? ¡

  • Simple ¡to ¡implement, ¡state ¡of ¡the ¡art ¡results. ¡

– NoNce ¡similarity ¡to ¡Perceptron ¡algorithm! ¡ Algorithmic ¡differences: ¡updates ¡if ¡insufficient ¡ margin, ¡scales ¡weight ¡vector, ¡and ¡has ¡a ¡learning ¡rate. ¡

  • Since ¡based ¡on ¡stochas7c ¡gradient ¡descent, ¡its ¡

running ¡Nme ¡guarantees ¡are ¡probabilisNc. ¡

  • Highlights ¡interesNng ¡tradeoffs ¡between ¡running ¡

Nme ¡and ¡data. ¡

slide-19
SLIDE 19

Much ¡faster ¡than ¡previous ¡methods ¡

  • 3 ¡datasets ¡(provided ¡by ¡Joachims) ¡

– Reuters ¡CCAT ¡(800K ¡examples, ¡47k ¡features) ¡ – Physics ¡ArXiv ¡(62k ¡examples, ¡100k ¡features) ¡ – Covertype ¡(581k ¡examples, ¡54 ¡features) ¡ Training ¡Time ¡ (in ¡seconds): ¡

Pegasos SVM-Perf SVM-Light

Reuters

2 77 20,075

Covertype

6 85 25,514

Astro-Physics

2 5 80

slide-20
SLIDE 20

Approximate ¡algorithms ¡

Error Decomposition

  • Approximation error:

– Best error achievable by large-margin predictor – Error of population minimizer w0 = argmin E[f(w)] = argmin λ|w|2 + Ex,y[loss(⟨w,x⟩;y)]

  • Estimation error:

– Extra error due to replacing E[loss] with empirical loss w* = arg min fn(w)

  • Optimization error:

– Extra error due to only optimizing to within finite precision err(w0) err(w*) err(w) Prediction error

From ¡ICML’08 ¡presentaNon ¡(available ¡here) ¡ [Shalev ¡Schwartz, ¡ Srebro ¡’08] ¡ Note: ¡w0 ¡is ¡redefined ¡in ¡this ¡ context ¡(see ¡below) ¡– ¡ does ¡not ¡refer ¡to ¡ini=al ¡weight ¡ vector ¡

slide-21
SLIDE 21

Approximate ¡algorithms ¡

Error Decomposition

  • Approximation error:

– Best error achievable by large-margin predictor – Error of population minimizer w0 = argmin E[f(w)] = argmin λ|w|2 + Ex,y[loss(⟨w,x⟩;y)]

  • Estimation error:

– Extra error due to replacing E[loss] with empirical loss w* = arg min fn(w)

  • Optimization error:

– Extra error due to only optimizing to within finite precision err(w0) err(w*) err(w) Prediction error

Pegasos ¡Guarantees ¡

A5er ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡updates: ¡ ¡ ¡err(wT) ¡< ¡err(w0) ¡+ ¡ ¡ With ¡probability ¡1-­‑ ¡

✏ δ

T = ˜ O ✓ 1 ✏ ◆

[Shalev ¡Schwartz, ¡ Srebro ¡’08] ¡

slide-22
SLIDE 22

Approximate ¡algorithms ¡

Error Decomposition

  • Approximation error:

– Best error achievable by large-margin predictor – Error of population minimizer w0 = argmin E[f(w)] = argmin λ|w|2 + Ex,y[loss(⟨w,x⟩;y)]

  • Estimation error:

– Extra error due to replacing E[loss] with empirical loss w* = arg min fn(w)

  • Optimization error:

– Extra error due to only optimizing to within finite precision err(w0) err(w*) err(w) Prediction error

Pegasos ¡Guarantees ¡

A5er ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡updates: ¡ ¡ ¡err(wT) ¡< ¡err(w0) ¡+ ¡ ¡ With ¡probability ¡1-­‑ ¡

✏ δ

Running ¡Nme ¡does ¡NOT ¡depend ¡

  • n: ¡

¡-­‑# ¡training ¡examples! ¡ It ¡DOES ¡depend ¡on: ¡ ¡-­‑ ¡Dimensionality ¡d ¡(why?) ¡ ¡-­‑ ¡ApproximaNon ¡ ¡ ¡ ¡ ¡ ¡and ¡ ¡ ¡-­‑ ¡Difficulty ¡of ¡problem ¡

✏ δ

T = ˜ O ✓ 1 ✏ ◆

λ

[Shalev ¡Schwartz, ¡ Srebro ¡’08] ¡

slide-23
SLIDE 23

But ¡how ¡is ¡that ¡possible? ¡ The Double-Edged Swo

data set size increases:

err(w0) err(w*) err(w) data set size (n) Prediction error

As ¡the ¡dataset ¡grows, ¡our ¡approximaNons ¡can ¡ be ¡worse ¡to ¡get ¡the ¡same ¡error! ¡

[Shalev ¡Schwartz, ¡ Srebro ¡’08] ¡