34
Principal Component Analysis Wanho Choi (wanochoi.com)

Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Principal Component Analysis

Wanho Choi(wanochoi.com)

Page 2: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

평균 (Average) • 평균 = 산술 평균 = 표본 평균

• 통계학의 내용 중에서 가장 이해하기 쉬운 개념 중 하나.

• 개의 관측값 이 주어져 있을 때,평균은 다음과 같이 정의한다.

µ = X = 1N

Xii=1

N

X1,X2,!,XN( )N

Page 3: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

분산 (Variance) • 관측값들이 평균으로부터 얼마나 흩어져 있는가?• 퍼져 있는 정도만 중요하기 때문에 부호는 중요하지 않다.• 따라서, 각 편차(=관측값-평균)의 제곱의 합의 평균으로 분산을 정의한다. (부호를 없애는 방법으로 절대값을 취하는 방법과 제곱을 취하는 방법이 있는데, 절대값은 대수 연산에 있어 여러 가지 불편함이 있기 때문에 잘 사용하지 않는다.)

V =σ 2 = 1N

Xi − µ( )2i=1

N

Page 4: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

예제: 평균과 분산• 2학년 1반 학생들의 수학 성적

• 2학년 2반 학생들의 수학 성적

65 72 57 92 45

σ 2 = 15

65 − 66.2( )2 + 72 − 66.2( )2 + 57 − 66.2( )2 + 92 − 66.2( )2 + 45 − 66.2( )2{ } = 246.96µ = 1

565 + 72 + 57 + 92 + 45( ) = 66.2

76 58 72 65 63

σ 2 = 15

76 − 66.8( )2 + 58 − 66.8( )2 + 72 − 66.8( )2 + 65 − 66.8( )2 + 63− 66.8( )2{ } = 41.36µ = 1

576 + 58 + 72 + 65 + 63( ) = 66.8

Page 5: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

표본공간 (Sample Space) • 한 번의 시행에서 일어날 수 있는 모든 결과(=사건)의 집합

• 주사위를 던져서 나오는 숫자에 대한 표본 공간

• 동전을 던져서 나오는 면에 대한 표본 공간

• 10문제가 나온 수학 시험 점수에 대한 표본 공간

S = 1,2,3,4,5,6{ }

S = front,back{ }

S = 0,10,20,30,40,50,60,70,80,90,100{ }

Page 6: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

확률 (Probability) • 동일한 조건에서 같은 실험을 무수히 반복할 때 특정 결과가 나오는 비율.

• 확률은 0과 1 사이의 값을 가진다.

• 1에 가까울수록 확률이 높다고 말하며, 이는 무한 시행시특정 결과가 나올 확실성이 그만큼 크다는 것을 의미한다.

• 주사위를 던졌을 때 3이 나올 확률: 1/6• 동전을 던졌을 때 앞면이 나올 확률: 1/2

Page 7: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

확률변수 (Random Variable) • 일정한 확률을 가지고 발생하는 실험결과(사건)에 수치를 부여한 것.

• 확률변수와 일반변수의 차이점은 확률표본에서 관찰한 변수인지 아닌지에 달려있다. (stochastic vs deterministic)

• 확률변수는 대문자, 확률변수가 취하는 값은 소문자로 표기.

P(X = x) = p

Page 8: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

확률분포 (Probability Distribution) • 확률변수 가 가지는 값과 그 값을 가질 확률과의 대응 관계

• “확률변수 = 주사위를 던졌을 때 나오는 숫자”에 대한 확률분포는 이산균등분포

X

0

0.05

0.1

0.15

0.2

1 2 3 4 5 6

Page 9: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

가우스 분포 (Gaussian Distribution) • 정규분포(normal distribution)라고도 한다.

34.1 34.113.5 13.5 2.5 2.5

P(x) = 1σ 2π

e−(x−µ )2

2σ 2

Page 10: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

가우스 분포 (Gaussian Distribution)

https://www.youtube.com/watch?v=xDIyAOBa_yU

• 많은 수의 경제, 사회, 자연 현상들이 정규분포를 따른다.• 한국 남자의 평균키가 170cm이라는 것은, 키가 170cm에 가까운 사람들이 가장 많고, 이 수치에서 크게 벗어난 150cm, 또는 190cm의 사람들의 수는 기하급수적으로 적어진다는 의미이다.

Page 11: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

기대값 (Expectation Value) • (각 사건이 발생할 때의 결과)×(그 사건이 일어날 확률)을전체 사건에 대해 합한 값.

• 어떤 확률적 사건에 대한 평균의 의미를 지님.

E(X) = xi ⋅P(xi )[ ]i=1

N

E(X) = µ

Page 12: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

예제: 기대값

수익률 확률

호황 50% 10%

보통 30% 50%

불황 -10% 40%

E(X) = 50 × 0.1( )+ 30 × 0.5( )+ −10 × 0.4( ) = 5 +15 − 4 = 16%

Page 13: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Proof) E(aX) = aE(X)

E(aX) = axi ⋅P(xi )[ ]i=1

N

= a xi ⋅P(xi )[ ]i=1

N

∑ = aE(X)

Page 14: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

V (X) = E (X − µ)2⎡⎣ ⎤⎦ = xi − µ( )2 ⋅P(xi )⎡⎣

⎤⎦

i=1

N

= xi2 − 2µxi + µ2( ) ⋅P(xi )⎡⎣ ⎤⎦

i=1

N

= xi2 ⋅P(xi )⎡⎣ ⎤⎦

i=1

N

∑ − 2µ xi ⋅P(xi )[ ]i=1

N

∑ + µ2 P(xi )[ ]i=1

N

∑ = E(X 2 )− 2µ2 + µ2

= E(X 2 )− µ2

Proof) V (X) = E(X 2 )− E(X)2

Page 15: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

공분산 (Covariance) • 서로 다른 두 확률변수의 상관관계를 나타냄.• 두 확률변수의 편차의 곱.

Cov(X,Y ) = E X − E(X)( ) ⋅ Y − E(Y )( )⎡⎣ ⎤⎦

Cov(X,Y ) > 0 : X ↑⇒Y ↑

Cov(X,Y ) < 0 : X ↑⇒Y ↓Cov(X,Y ) = 0 : no relationship

ex) X :height, Y :weightex) X :age, Y :eyesightex) X :age, Y :eye size

Page 16: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

상관계수 (Correlation)

Cor(X,Y ) =E X − E(X)( ) ⋅ Y − E(Y )( )⎡⎣ ⎤⎦

σ X ⋅σ Y

http://baileysimpson.weebly.com/objectives-1---8.html

Page 17: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Cov(X,Y ) = E X − E(X)( ) ⋅ Y − E(Y )( )⎡⎣ ⎤⎦ = E XY − XE(Y )−YE(X)+ E(X)E(Y )[ ] = E(XY )− E(X)E(Y )− E(X)E(Y )+ E(X)E(Y ) = E(XY )− E(X)E(Y ) = E(XY )− µXµY

Proof) Cov(X,Y ) = E X − E(X)( ) ⋅ Y − E(Y )( )⎡⎣ ⎤⎦ = E(XY )− µXµY

Page 18: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

확률벡터 (Random Vector) • Multivariate random variables

• 각 성분이 확률변수인 벡터

X =

X1X2!XK

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

x =

x1x2!xK

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

확률 벡터 (random vector) 표본값 벡터 (sample vector)

Page 19: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

확률벡터의 기대값과 분산• 기대값 벡터

• 공분산 행렬

!µ = X = E

X1X2"XK

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

=

E(X1)E(X2 )"

E(XK )

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

C(X) =

Var(X1) Cov(X1,X2 ) ! Cov(X1,XK )Cov(X2,X1) Var(X2 ) ! Cov(X2,XK )

! ! " !Cov(XK ,X1) Cov(XK ,X2 ) ! Var(XK )

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

Page 20: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Covariance Body• 개의 2차원 점들이 주어져 있을 때,N

from “My Friend, the Covariance Body”

Page 21: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Covariance Body• 이 점들의 분포를 설명해주는 타원 (ellipse).

from “My Friend, the Covariance Body”

Page 22: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Covariance Body• 즉, 가장 큰 분포를 가지는 축과,가장 작은 분포를 가지는 축을 구하는 문제.

from “My Friend, the Covariance Body”

Page 23: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Covariance Body• 만약 2차원이 아닌 차원의 점들의 분포라면,

차원에서 존재하는 타원체(hyper ellipsoid)가 됨.

http://mathground.net/ellipsoid/

3차원 타원체

KK

Page 24: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

왜 Covariance Body 라고 부르는가?• Covariance matrix로 부터 계산하기 때문.

• 공분산 행렬 (covariance matrix)

xi2

i=1

N

∑ xiyii=1

N

yixii=1

N

∑ yi2

i=1

N

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

xi2

i=1

N

∑ xiyii=1

N

∑ xizii=1

N

yixii=1

N

∑ yi2

i=1

N

∑ yizii=1

N

zixii=1

N

∑ ziyii=1

N

∑ zi2

i=1

N

⎢⎢⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥⎥⎥

3D covariance matrix2D covariance matrix

Page 25: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

공분산 행렬 (Covariance Matrix)• 분산(variance)의 개념을 다차원으로 확대한 것.

• The variance in a collection of random points in two-dimensional space cannot be characterized fully by a single number. We need a 2 by 2 matrix to fully characterize the two-dimensional variation.

xi2

i=1

N

∑ xiyii=1

N

yixii=1

N

∑ yi2

i=1

N

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

Page 26: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Covariance Body• 2차원 확률변수 에 대한 회의 시행 결과라고 볼 수 있다.N

from “My Friend, the Covariance Body”

X

Page 27: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Covariance Body• 2개의 확률변수 와 에 대한 회의 시행 결과라고 볼 수 있다.

NX Y

C(X) =xi2

i=1

N

∑ xiyii=1

N

yixii=1

N

∑ yi2

i=1

N

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

Page 28: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

공분산 행렬의 기하학적 의미• Covariance matrix의

가장 큰 eigenvalue = (타원 최대축의 길이)2

가장 큰 eigenvectors = (타원 최대축의 방향)

가장 작은 eigenvalue = (타원 최소축의 길이)2

가장 작은 eigenvectors = (타원 최소축의 방향)

가 된다.

Page 29: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

공분산 행렬과 Eigen과의 관계• 일단 계산의 편의를 위해 점들의 중심을 원점으로 이동한다.• 따라서,

• 인 관계와 마찬가지로 공분산 행렬은 다음과 같이 표현할 수 있다.

• 그러면 이제 eigenvector 방향 대한 공분산을 구해보자.

E(X) = 0

V (X) = E(X 2 )− E(X)2 = E(X 2 )

v

C(vTX) = E vTX( ) vTX( )T⎡⎣

⎤⎦

the projected random vector onto v

C(X) = E XXT⎡⎣ ⎤⎦

Page 30: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

공분산 행렬과 Eigen과의 관계

C(vTX) = E vTX( ) vTX( )T⎡⎣

⎤⎦ = E vTX( ) XTv( )⎡⎣ ⎤⎦

= E vTXXTv⎡⎣ ⎤⎦ = E vT XXT( )v⎡⎣ ⎤⎦ = vTE XXT( )v = vTC X( )v = vTλv = λvTv = λ

by the definition of eigenvalue & eigenvector:

C X( )v = λv

Page 31: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

PCA (Principal Component Analysis)• The main purpose of PCA is the analysis of data to

identify patterns that represent the data “well.”

• The principal components can be understood as new axes of the dataset that maximize the variance along those axes (the eigenvectors of the covariance matrix).

• In other words, PCA aims to find the axes with maximum variances along which the data is most spread.

• PCA is used for reducing dimensions from a high dimensional space into a low dimensional space.

http://sebastianraschka.com/Articles/2014_kernel_pca.html

Page 32: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

PCA (Principal Component Analysis)

https://www.analyticsvidhya.com/blog/2016/03/practical-guide-principal-component-analysis-python/

Page 33: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

PCA의 활용: Image Compression

https://www.projectrhea.org/rhea/index.php/PCA_Theory_Examples

Page 34: Wanho Choi (wanochoi.com) · 2019-04-25 · PCA (Principal Component Analysis) • The main purpose of PCA is the analysis of data to identify patterns that represent the data “well.”

Q & A