SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3...

17
1 SVD; PCA

Transcript of SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3...

Page 1: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

1

SVD; PCA

Page 2: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

2

Singular Value Decomposition

A = UΣVT = λ1

|u1

|

(− vT1

−)+

· · ·+ λr

|ur

|

(− vTr −

)

UTU = I,VT

V = VVT = I

Gene Golub’s plate

Page 3: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

3

Right svectors are evecs of A^T A

• For any matrix A

ATA = VΣ

TUTUΣV

T

= V(ΣTΣ)VT

(ATA)V = V(ΣTΣ) = VD

Page 4: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

4

Left svectors are evecs of A A^T

AAT = UΣV

TVΣ

TUT

= U(ΣΣT )UT

(AAT )U = U(ΣΣT ) = UD

Page 5: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

5

Truncated SVD

A = U:,1:kΣ1:k,1:kVT1:,1:k = λ1

|u1

|

(− vT1

−)+

· · ·+ λk

|uk

|

(− vTk −

)

Spectrum of singular values Rank k approximation to matrix

≈m

n k

k

k

A UΣ VT

n

Page 6: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

6

SVD on images

• Run demo

load clown

[U,S,V] = svd(X,0);

ranks = [1 2 5 10 20 rank(X)];

for k=ranks(:)’

Xhat = (U(:,1:k)*S(1:k,1:k)*V(:,1:k)’);

image(Xhat);

end

Page 7: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

7

Clown example

1 2 5

10 20 200

Page 8: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

8

Space savings

A ≈ U:,1:kΣ1:k,1:kVT1:,1:k

m× n ≈ (m× k) (k) (n× k) = (m+ n+ 1)k

200× 320 = 64, 000 → (200 + 320 + 1)20 = 10, 420

Page 9: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

9

Principal Components Analysis

-5 -4 -3 -2 -1 0 1 2 3 4 5

-3

-2

-1

0

1

2

3

4

xi =∑k

j=1 zijvj .

scores Loadings (basis)

Page 10: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

10

PCA on height-weight data

-4 -3 -2 -1 0 1 2 3 4-4

-3

-2

-1

0

1

2

3

4

5

height

wei

ght

55 60 65 70 75 80 8580

100

120

140

160

180

200

220

240

260

280

height

wei

ght

Page 11: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

11

Applications

• Visualizing high dim data

• Reducing dim for nearest neighbor classifier

Page 12: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

12

Visualizing data

• Project 256 dimensional vectors (representing 16x16 images of digits) into 2D

-1000 -500 0 500 1000 1500

-1000

-500

0

500

1000

1500

1

1

1

1

1

2 22 2

2

3

3

3 33

44

4

44

5

55

5

5

6

6

6

6

6

7

77

77 8

8

8

8

8

9

99

99

0

0

0

0

0

Page 13: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

13

Embed vectors into their z1, z2 coords

20 40 60 80 100 120 140 160 180 200

20

40

60

80

100

120

140

160

180

200

Page 14: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

14

Nearest neighbor classifier

• Look up k nearest neighbors in training set.

• Return majority vote of their labels.• For k=1, we have

D(x,x’) = Euclidean distance• Use PCA to embed in low dimensions, compute

distances there

y = y(argminiD(xi,x

∗))

Page 15: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

15

Eigenfaces

test imagesclosest match in training set using K=4

K=4

Page 16: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

16

Misclassification rate vs K

0 20 40 60 80 100 120 140 1600

5

10

15

20

25

30

35

40

PCA dimensionality

num

ber

of m

iscl

assi

ficat

ion

erro

rs o

n te

st s

et

Page 17: SVD; PCAmurphyk/Teaching/Stat406-Spring08/...10 PCA on height-weight data-4 -3 -2 -1 0 1 2 3 4-4-3-2-1 0 1 2 3 4 5 height weight 55 60 65 70 75 80 85 80 100 120 140 160 180 200 220

17

Eigenfaces

test images closest match in training set using K=10

K=10