Docsity

Linear Classification with Perceptron Algorithm: Separating Data with Hyperplanes, Slides of Artificial Intelligence

Partial preview of the text

Download Linear Classification with Perceptron Algorithm: Separating Data with Hyperplanes and more Slides Artificial Intelligence in PDF only on Docsity!

CSE 151 Machine Learning

Linear Classification

Given labeled data:

(xi, yi)

where y is +1 or -1 , find a hyperplane to separate + from -

feature

vector

label

i=1,..,n

- - - - - w

O

Linear Classification

Given labeled data (xi, yi), i=1,..,n, where y is +1 or -1 , Find a hyperplane through the origin to separate + from - w : normal vector to the hyperplane For a point x on one side of the hyperplane, ￿w, x￿ > 0 For a point x on the other side, ￿w, x￿ < 0

The Perceptron Algorithm

Goal: Given labeled data (xi, yi), i=1,..,n, where y is +1 or -1 , Find a vector w such that the corresponding hyperplane separates + from - Perceptron Algorithm:

  1. Initially, w 1 = y 1 x 1
  2. For t=2, 3,.... If wt+1 = wt + yt xt Else: yt￿wt, xt￿ < (^0) then: wt+1 = wt

Measure of Separability: Margin

For a unit vector w, and training set S, margin of w is defined as:

γ = min x∈S |￿w, x￿| ￿x￿ min cosine of angle between w and x, for any x in S

Low Margin

w

O

w

O

High Margin

Real Examples: Margin

For a unit vector w, and training set S, margin of w is defined as:

γ = min x∈S |￿w, x￿| ￿x￿ min cosine of angle between w and x, for any x in data

Low Margin High Margin

w

w

What if data is not linearly

separable?

Ideally, we want to find a linear separator that makes the

minimum number of mistakes on training data

But this is NP Hard

-^ -

Voted Perceptron

Perceptron: Voted Perceptron:

  1. Initially: m = 1, w 1 = y 1 x 1
  2. For t=2, 3,.... If wm+1 = wm + yt xt then: m = m + 1
  3. Output wm yt￿wm, xt￿ ≤ 0 1. Initially: m = 1, w 1 = y 1 x 1 2. For t=2, 3,.... If wm+1 = wm + yt xt then: m = m + 1 3. Output (w1, c 1 ), (w2, c 2 ), ..., (wm, cm) cm = 1 Else: cm = cm + 1 yt￿wm, xt￿ ≤ 0

Averaged Perceptron

Averaged Perceptron: How to classify example x?

Output: sign(￿

m

i=

ciwi, x￿)

  1. Initially: m = 1, w 1 = y 1 x 1
  2. For t=2, 3,.... If wm+1 = wm + yt xt then: m = m + 1
  3. Output (w1, c 1 ), (w2, c 2 ), ..., (wm, cm) cm = 1 Else: cm = cm + 1 yt￿wm, xt￿ ≤ 0

Voted vs. Averaged

How to classify example x?

Averaged: sign(￿

m

i=

ciwi, x￿)

Voted: sign( m ￿ i= cisign(￿wi, x￿)) Example where voted and averaged are different: w 1 = x 1 , w 2 = x 2 , w 3 = x 3 , c 1 = c 2 = c 3 = 1 Averaged: x 1 + x 2 + x 3 > 0 Voted: Any two of x 1 , x 2 , x 3 > 0

Perceptron: An Example

Data: ( (4, 0), +1), ( (1, 1), -1), ( (0, 1), -1), ( (-2,-2), +1) Step 1: w 1 = (4, 0), c 1 = 1 O w 1 Decision Boundary

Perceptron: An Example

Data: ( (4, 0), +1), ( (1, 1), -1), ( (0, 1), -1), ( (-2,-2), +1) Step 2: (x2, y 2 ) = ( (1, 1), -1) Step 1: w 1 = (4, 0), c 1 = 1 O Decision Boundary w 1 x 2

Perceptron: An Example

Data: ( (4, 0), +1), ( (1, 1), -1), ( (0, 1), -1), ( (-2,-2), +1) Step 2: (x2, y 2 ) = ( (1, 1), -1) y 2 ￿w 1 , x 2 ￿ < (^0) Mistake! Step 1: w 1 = (4, 0), c 1 = 1 Update: w 2 = (3, -1), c 2 = 1 O -x 2 w 2 Decision Boundary w 1 x 2

Perceptron: An Example

Data: ( (4, 0), +1), ( (1, 1), -1), ( (0, 1), -1), ( (-2,-2), +1) Step 2: (x2, y 2 ) = ( (1, 1), -1) y 2 ￿w 1 , x 2 ￿ < (^0) Mistake! Step 3: (x3, y 3 ) = ( (0, 1), -1) Step 1: w 1 = (4, 0), c 1 = 1 Update: w 2 = (3, -1), c 2 = 1 O w 2 Decision Boundary w 1 x 3 x 2