KAIST 문인철교수 강의 / Utah Univ cs5350 / Georgia Tech cs7641 / PRML
참고하여 헷갈릴 수 있는 개념 위주로 정리
MLE (Maximum Likelihood Estimation)
MLE의 정확한 의미
observed data의 등장확률을 최대화하는 모수를 찾음
θ ^ = argmax θ P ( D ∣ θ ) \hat\theta = \underset{\theta}{\operatorname{argmax}}P(D|\theta) θ ^ = θ a r g m a x P ( D ∣ θ )
Binomial에서의 MLE (Thumbtack flip의 예)
P ( D ∣ θ ) = θ a H ( 1 − θ ) a T P(D|\theta) = \theta^{a_H}(1-\theta)^{a_T} P ( D ∣ θ ) = θ a H ( 1 − θ ) a T
당연히 이항계수가 없음에 주의. 데이터행렬 그 자체의 Likelihood이므로 순서를 구분한다.
단순하게 독립사건확률의 곱으로 표현
ln 함수가 monotonically increasing 하기 때문에
ln P ( D ∣ θ ) = a H ln θ + a T ln ( 1 − θ ) \ln{P(D|\theta)} = a_H\ln\theta+a_T\ln(1-\theta) ln P ( D ∣ θ ) = a H ln θ + a T ln ( 1 − θ )
θ ^ = argmax θ P ( D ∣ θ ) = argmax θ ln P ( D ∣ θ ) = argmax θ { a H ln θ + a T ln ( 1 − θ ) } \hat\theta = \underset{\theta}{\operatorname{argmax}}P(D|\theta) = \underset{\theta}{\operatorname{argmax}}\ln{P(D|\theta)} = \underset{\theta}{\operatorname{argmax}}\{a_H\ln\theta+a_T\ln(1-\theta)\} θ ^ = θ a r g m a x P ( D ∣ θ ) = θ a r g m a x ln P ( D ∣ θ ) = θ a r g m a x { a H ln θ + a T ln ( 1 − θ ) }
d d θ { a H ln θ + a T ln ( 1 − θ ) } = 0 {d\over{d\theta}}\{a_H\ln\theta+a_T\ln(1-\theta)\} = 0 d θ d { a H ln θ + a T ln ( 1 − θ ) } = 0
a H θ − a T 1 − θ = 0 {a_H\over\theta}-{a_T\over{1-\theta}} = 0 θ a H − 1 − θ a T = 0
θ ^ = a H a H + a T \hat\theta = {a_H\over{a_H+a_T}} θ ^ = a H + a T a H
Simple Error Bound (Hoeffding’s inequality)
P ( ∣ θ ^ − θ ∗ ∣ ≥ ϵ ) ≤ 2 exp ( − 2 N ϵ 2 ) P(|\hat\theta-\theta^*|\geq\epsilon)\leq2\exp{(-2N\epsilon^2)} P ( ∣ θ ^ − θ ∗ ∣ ≥ ϵ ) ≤ 2 exp ( − 2 N ϵ 2 )
θ ^ \hat\theta θ ^ 은 probability P P P , approximately ϵ \epsilon ϵ 에 대하여 “PAC(Probably Approximate Correct) learning의 결과”
MLE의 단점
Observation에 따라 그 값이 너무 민감하게 변함
이러한 단점이 보완된 방법으로 MAP가 있음
MAP (Maximum a Posteriori Estimation)
MAP의 정확한 의미
observed data에 대하여 최대 확률을 가지는 모수를 찾음
θ ^ = argmax θ P ( θ ∣ D ) \hat\theta = \underset{\theta}{\operatorname{argmax}}P(\theta|D) θ ^ = θ a r g m a x P ( θ ∣ D )
P ( θ ∣ D ) = P ( D ∣ θ ) P ( θ ) P ( D ) P(\theta|D) = {P(D|\theta)P(\theta)\over{P(D)}} P ( θ ∣ D ) = P ( D ) P ( D ∣ θ ) P ( θ )
p o s t e r i o r = l i k e l i h o o d ∗ p r i o r n o r m a l i z n i n g c o n s t a n t posterior = {likelihood * prior\over{normalizning\quad{constant}}} p o s t e r i o r = n o r m a l i z n i n g c o n s t a n t l i k e l i h o o d ∗ p r i o r
P ( D ∣ θ ) = θ a H ( 1 − θ ) a T P(D|\theta) = \theta^{a_H}(1-\theta)^{a_T} P ( D ∣ θ ) = θ a H ( 1 − θ ) a T
P ( θ ) = ? P(\theta) = ? P ( θ ) = ?
Beta Distribution Model 가정 : 변수범위 [0,1], likelihood와 곱할 경우 동일한 형태가 됨
P ( θ ) = θ α − 1 ( 1 − θ ) β − 1 B ( α , β ) P(\theta) = {\theta^{\alpha-1}(1-\theta)^{\beta-1}\over{B(\alpha,\beta)}} P ( θ ) = B ( α , β ) θ α − 1 ( 1 − θ ) β − 1
B ( α , β ) = Γ ( α ) Γ ( β ) Γ ( α + β ) B(\alpha,\beta) = {\Gamma(\alpha)\Gamma(\beta)\over\Gamma(\alpha+\beta)} B ( α , β ) = Γ ( α + β ) Γ ( α ) Γ ( β )
Γ ( α ) = ( α − 1 ) ! \Gamma(\alpha) = (\alpha - 1)! Γ ( α ) = ( α − 1 ) !
B ( α , β ) = c o n s t B(\alpha,\beta) = const B ( α , β ) = c o n s t
P ( θ ∣ D ) ∝ θ a H ( 1 − θ ) a T θ α − 1 ( 1 − θ ) β − 1 = θ a H + α − 1 ( 1 − θ ) a T + β − 1 P(\theta|D)\propto\theta^{a_H}(1-\theta)^{a_T}\theta^{\alpha-1}(1-\theta)^{\beta-1} = \theta^{a_H+\alpha-1}(1-\theta)^{a_T+\beta-1} P ( θ ∣ D ) ∝ θ a H ( 1 − θ ) a T θ α − 1 ( 1 − θ ) β − 1 = θ a H + α − 1 ( 1 − θ ) a T + β − 1
θ ^ = argmax θ P ( θ ∣ D ) \hat\theta = \underset{\theta}{\operatorname{argmax}}P(\theta|D) θ ^ = θ a r g m a x P ( θ ∣ D )
θ ^ = a H + α − 1 a H + a T + α + β − 2 \hat\theta = {a_H+\alpha-1\over{a_H+a_T+\alpha+\beta-2}} θ ^ = a H + a T + α + β − 2 a H + α − 1
MLE, MAP 되새김질
MLE: likelihood의 최대값을 바로 계산, 관찰된 데이터를 가장 잘 표현하는 분포와 모수를 추정
MAP: likelihood * prior의 최대값을 계산, 미리 prior의 분포와 모수를 추정한 뒤 이와 likelihood를 곱한 값이 최대가 되는 분포와 모수를 추정
(내 생각) prior의 의미: 동전을 던질 때, 5:5가 나올 수도 있지만, 4:6이 나올 수도 있고, 7:3이 나올 수도 있음 이 자체를 확률이라고 생각하면, 사전확률 자체를 특정한 값이 아닌 확률분포의 일종으로 여길 수 있고 이를 통하여 유동적인 연쇄적 확률분포 추정이 가능해지며, 인위적인 prior모델을 반영해 보다 유연한 확률분포 추정이 가능
데이터에 대한 적절한 가정이 있을 경우 관측한 데이터만을 사용하는 것보다 더 우수한 추정 가능 (더 좋은 가정이 있다면 더 좋은 추정이 가능하다)
Distribution
Gaussian Distribution
f ( x ; μ , σ ) = 1 ( 2 π ) 1 / 2 σ e x p { − ( x − μ ) 2 σ − 2 2 } f(x;\mu,\sigma) = {1\over(2\pi)^{1/2}\sigma}exp{\left\{-{(x-\mu)^2\sigma^{-2}\over2}\right\}} f ( x ; μ , σ ) = ( 2 π ) 1 / 2 σ 1 e x p { − 2 ( x − μ ) 2 σ − 2 }
Multivariable Gaussian Distribution
f ( x ; μ , Σ ) = 1 ( 2 π ) D / 2 ∣ Σ ∣ 1 / 2 e x p { − ( x − μ ) T Σ − 1 ( x − μ ) 2 } f(x;\mu,\Sigma) = {1\over(2\pi)^{D/2}|\Sigma|^{1/2}}exp{\left\{-{(x-\mu)^T\Sigma^{-1}(x-\mu)\over2}\right\}} f ( x ; μ , Σ ) = ( 2 π ) D / 2 ∣ Σ ∣ 1 / 2 1 e x p { − 2 ( x − μ ) T Σ − 1 ( x − μ ) }
특징: long tail … x의 범위 ( − ∞ , + ∞ ) (-\infty, +\infty) ( − ∞ , + ∞ )
Beta Distribution
f ( x ; α , β ) = x α − 1 ( 1 − x ) β − 1 ∫ 0 1 u α − 1 ( 1 − u ) β − 1 d u = x α − 1 ( 1 − x ) β − 1 B ( α , β ) = Γ ( α + β ) Γ ( α ) Γ ( β ) x α − 1 ( 1 − x ) β − 1 f(x;\alpha,\beta) = {x^{\alpha-1}(1-x)^{\beta-1}\over\int_0^1{u^{\alpha-1}(1-u)^{\beta-1}du}} = {x^{\alpha-1}(1-x)^{\beta-1}\over{B(\alpha,\beta)}} = {\Gamma(\alpha+\beta)\over\Gamma(\alpha)\Gamma(\beta)}x^{\alpha-1}(1-x)^{\beta-1} f ( x ; α , β ) = ∫ 0 1 u α − 1 ( 1 − u ) β − 1 d u x α − 1 ( 1 − x ) β − 1 = B ( α , β ) x α − 1 ( 1 − x ) β − 1 = Γ ( α ) Γ ( β ) Γ ( α + β ) x α − 1 ( 1 − x ) β − 1
특징: x의 범위 [ 0 , 1 ] [0, 1] [ 0 , 1 ]
mean: α α + β {\alpha\over\alpha+\beta} α + β α
variance: α β ( α + β ) 2 ( α + β + 1 ) {\alpha\beta\over(\alpha+\beta)^2(\alpha+\beta+1)} ( α + β ) 2 ( α + β + 1 ) α β
Binomial Distribution
f ( k ; n , p ) = ( n k ) p k ( 1 − p ) n − k f(k;n,p) = {n\choose{k}}p^k(1-p)^{n-k} f ( k ; n , p ) = ( k n ) p k ( 1 − p ) n − k
( n k ) = n ! k ! ( n − k ) ! {n\choose{k}} = {n!\over{k!(n-k)!}} ( k n ) = k ! ( n − k ) ! n !
특징: discrete
mean: n p np n p
variance: n p ( 1 − p ) np(1-p) n p ( 1 − p )
Multinomial Distribution
f ( x 1 , ⋯ , x k ; n , p 1 , ⋯ , p k ) = n ! x 1 ! ⋯ x k ! p 1 x 1 ⋯ p k x k f(x_1,\cdots,x_k;n,p_1,\cdots,p_k) = {n!\over{x_1!{\cdots}x_k!}}p_1^{x_1}{\cdots}p_k^{x_k} f ( x 1 , ⋯ , x k ; n , p 1 , ⋯ , p k ) = x 1 ! ⋯ x k ! n ! p 1 x 1 ⋯ p k x k
mean: n p i np_i n p i
variance: n p i ( 1 − p i ) np_i(1-p_i) n p i ( 1 − p i )
covariance: − n p i p j -np_ip_j − n p i p j
Gamma function
Γ ( x ) = ∫ 0 ∞ t x − 1 e t d t \Gamma(x) = \int_0^\infty{t^{x-1}\over{e^t}}dt Γ ( x ) = ∫ 0 ∞ e t t x − 1 d t
Γ ( x ) = lim n → ∞ 1 ⋯ n x ⋯ ( x + n ) n x = lim n → ∞ n ! ( x − 1 ) ! ( x + n ) ! n x = lim n → ∞ n ! n x ( x + n ) ! ( x − 1 ) ! \Gamma(x) = \underset{n\rightarrow\infty}{\lim}{1{\cdots}n\over{x\cdots(x+n)}}n^x = \underset{n\rightarrow\infty}{\lim}{n!(x-1)!\over{(x+n)!}}n^x = \underset{n\rightarrow\infty}{\lim}{n!n^x\over{(x+n)!}}(x-1)! Γ ( x ) = n → ∞ lim x ⋯ ( x + n ) 1 ⋯ n n x = n → ∞ lim ( x + n ) ! n ! ( x − 1 ) ! n x = n → ∞ lim ( x + n ) ! n ! n x ( x − 1 ) !
가우스 극한의 식은 함수를 유일하게 정하기 위함
lim n → ∞ n ! n x ( x + n ) ! = 1 \underset{n\rightarrow\infty}{\lim}{n!n^x\over{(x+n)!}}=1 n → ∞ lim ( x + n ) ! n ! n x = 1
이므로
( x − 1 ) ! (x-1)! ( x − 1 ) !
로 수렴
Γ ( x + 1 ) = ∫ 0 ∞ t x e t d t = [ − t x e − t ] t = 0 t = ∞ − ( ∫ 0 ∞ − x t x − 1 e − t d t ) \Gamma(x+1) = \int_0^\infty{t^x\over{e^t}}dt = \left[-t^xe^{-t}\right]_{t=0}^{t=\infty} - \left({\int_0^\infty}-xt^{x-1}e^{-t}dt\right) Γ ( x + 1 ) = ∫ 0 ∞ e t t x d t = [ − t x e − t ] t = 0 t = ∞ − ( ∫ 0 ∞ − x t x − 1 e − t d t )
= lim t → ∞ ( − t x e − t ) − 0 + ( ∫ 0 ∞ x t x − 1 e − t d t ) = \underset{t\rightarrow\infty}{\lim}(-t^xe^{-t}) - 0 + \left({\int_0^\infty}xt^{x-1}e^{-t}dt\right) = t → ∞ lim ( − t x e − t ) − 0 + ( ∫ 0 ∞ x t x − 1 e − t d t )
극한항 L'Hospital's Rule 적용 (혹은 exponential이 polynomial보다 증가속도가 크기 때문에 0으로 수렴)
= x ∫ 0 ∞ t x − 1 e − t d t = x Γ ( x ) = x{\int_0^\infty}t^{x-1}e^{-t}dt = x\Gamma(x) = x ∫ 0 ∞ t x − 1 e − t d t = x Γ ( x )
Γ ( x + 1 ) = x Γ ( x ) \Gamma(x+1) = x\Gamma(x) Γ ( x + 1 ) = x Γ ( x )
Γ ( 1 ) = 1 , 0 ! = 1 \Gamma(1) = 1,{\quad}0! = 1 Γ ( 1 ) = 1 , 0 ! = 1
∴ Γ ( n + 1 ) = n ! , Γ ( n ) = ( n − 1 ) ! \therefore\Gamma(n+1) = n!,{\quad}\Gamma(n) = (n-1)! ∴ Γ ( n + 1 ) = n ! , Γ ( n ) = ( n − 1 ) !
Beta function
B ( x , y ) = ∫ 0 1 t x − 1 ( 1 − t ) y − 1 d t = Γ ( x ) Γ ( y ) Γ ( x + y ) B(x,y) = \int_0^1t^{x-1}(1-t)^{y-1}dt = {\Gamma(x)\Gamma(y)\over\Gamma(x+y)} B ( x , y ) = ∫ 0 1 t x − 1 ( 1 − t ) y − 1 d t = Γ ( x + y ) Γ ( x ) Γ ( y )
B ( n , m ) = ( n − 1 ) ! ( m − 1 ) ! ( n + m − 2 ) ! B(n,m) = {(n-1)!(m-1)!\over(n+m-2)!} B ( n , m ) = ( n + m − 2 ) ! ( n − 1 ) ! ( m − 1 ) !
Rule-Based ML
perfect world
No observation errors
Training data is error-free
No inconsistent observations
Training data is noise-free
No stochastic elements in the system we observe
Target function is deterministic
Full information in the observations to regenerate the system
Target function is contained in hypothesis set
Find-S Algorithm
initialize h to the most specific in H ...[0]
for instance x in D:
if y of x is positive: ...[1]
for feature f in O:
if (f in h) == (f in x): ...[1-1]
do nothing
else: ...[1-2]
(f in h) = (f in h) U (f in x)
…[0]: hypothesis h를 할 수 있는 한 가장 specific하게 초기설정 (어떤 feature로도 만족시킬 수 없는 경우로 시작)
…[1]: Dataset의 instance x에 대하여, x의 레이블값이 참일 경우
…[1-1]: h의 f와 x의 f가 동일한 경우 그대로
…[1-2]: h의 f와 x의 f가 다를 경우 둘 모두를 포함하는 범위로 h의 f를 수정
점점 범위를 넓혀 나가서 모든 dataset을 만족하는 최소집합(most specific)의 Rule을 찾음
문제점
가장 specific한 범위로부터 widen했기 때문에, 구해지는 hypothesis는 가장 specific한 hypothesis일 뿐이고, 이외에도 수많은 hypothesis가 가능
수많은 hypothesis를 converge시킬 수 없음
Version space(the set of possible hypothesis)를 찾는 방법으로 발전
Candidate Elimination Algorithm: General boundary와 Specific boundary를 모두 찾음
Candidate Elimination Algorithm
initialize S to maximally specific h in H ...[0-1]
initialize G to maximally general h in H ...[0-2]
for instance x in D:
if y of x is positive:
generalize S as much as needed to cover o in x
remove any h in G, for which h(o) != y
if y of x is negative:
specialize G as much as needed to exclude o in x
remove any h in S, for which h(p) = y
generate h that satisfies (s in S, g in G, g >= h >= s)
Decision Tree
Entropy
H ( X ) = ∑ i P ( x i ) I ( x i ) = − ∑ i P ( x i ) ln P ( x i ) = − ∫ p ( x ) ln p ( x ) d x H(X) = {\sum_i}P(x_i)I(x_i) = -{\sum_i}P(x_i){\ln}P(x_i) = -{\int}p(x){\ln}p(x)dx H ( X ) = ∑ i P ( x i ) I ( x i ) = − ∑ i P ( x i ) ln P ( x i ) = − ∫ p ( x ) ln p ( x ) d x
H ( Y ∣ X ) = ∑ x p ( x ) H ( Y ∣ X = x ) H(Y|X) = {\sum_x}p(x)H(Y|X=x) H ( Y ∣ X ) = ∑ x p ( x ) H ( Y ∣ X = x )
= − ∑ x p ( x ) ∑ y p ( y ∣ x ) ln p ( y ∣ x ) = -{\sum_x}p(x){\sum_y}p(y|x){\ln}p(y|x) = − ∑ x p ( x ) ∑ y p ( y ∣ x ) ln p ( y ∣ x )
= − ∑ x ∑ y p ( x , y ) ln p ( y ∣ x ) = -\sum_x{\sum_y}p(x,y){\ln}p(y|x) = − ∑ x ∑ y p ( x , y ) ln p ( y ∣ x )
= − ∑ x , y p ( x , y ) ln p ( y ∣ x ) = -\sum_{x,y}p(x,y){\ln}p(y|x) = − ∑ x , y p ( x , y ) ln p ( y ∣ x )
= − ∑ x , y p ( x , y ) ln { p ( x , y ) p ( x ) } = -\sum_{x,y}p(x,y){\ln}\left\{p(x,y)\over{p(x)}\right\} = − ∑ x , y p ( x , y ) ln { p ( x ) p ( x , y ) }
= ∑ x , y p ( x , y ) ln { p ( x ) p ( x , y ) } = \sum_{x,y}p(x,y){\ln}\left\{p(x)\over{p(x,y)}\right\} = ∑ x , y p ( x , y ) ln { p ( x , y ) p ( x ) }
I G ( Y , A i ) = H ( Y ) − H ( Y ∣ A i ) IG(Y, A_i) = H(Y) - H(Y|A_i) I G ( Y , A i ) = H ( Y ) − H ( Y ∣ A i )
데이터의 information(surprisal)이 감소한 정도
이를 획득한 정보라고 생각함
값이 클 수록(정보량이 많이 감소하였을 수록) 분류가 잘 되었다고 판단
Top-down Induction Algorithm
IG가 큰 순서대로 feature을 선정, 분기를 생성
ID3 Algorithm
select an open node to split
select a best variable to split
for values of the selected variable:
sort instances with the value of the selected variable
put the sorted items under the branch of the value of the variable
if the sorted items are all in one class:
close the leaf node of the branch
Linear Regression
Hypothesis
h : f ^ ( x ; θ ) = θ 0 + ∑ i = 1 n θ i x i = ∑ i = 0 n θ i x i ( x 0 = 1 ) h: \hat{f}(x;\theta) = \theta_0+\sum_{i=1}^n\theta_ix_i = \sum_{i=0}^n\theta_ix_i\quad(x_0=1) h : f ^ ( x ; θ ) = θ 0 + ∑ i = 1 n θ i x i = ∑ i = 0 n θ i x i ( x 0 = 1 )
f ( x ; θ ) = ∑ i = 0 n θ i x i + e = y f(x;\theta) = \sum_{i=0}^n\theta_ix_i+e=y f ( x ; θ ) = ∑ i = 0 n θ i x i + e = y
f : X θ + e = Y f: X\theta+e = Y f : X θ + e = Y
θ ^ = argmin θ ( f − f ^ ) 2 = argmin θ ( Y − X θ ) 2 = argmin θ ( Y − X θ ) T ( Y − X θ ) \hat\theta = \underset\theta{\operatorname{argmin}}(f-\hat{f})^2 = \underset\theta{\operatorname{argmin}}(Y-X\theta)^2 = \underset\theta{\operatorname{argmin}}(Y-X\theta)^T(Y-X\theta) θ ^ = θ a r g m i n ( f − f ^ ) 2 = θ a r g m i n ( Y − X θ ) 2 = θ a r g m i n ( Y − X θ ) T ( Y − X θ )
= argmin θ ( Y T Y − 2 θ T X T Y + θ T X T X Θ ) = argmin θ ( θ T X T X θ − 2 θ T X T Y ) = \underset\theta{\operatorname{argmin}}(Y^TY-2\theta^TX^TY+\theta^TX^TX\Theta) = \underset\theta{\operatorname{argmin}}(\theta^TX^TX\theta-2\theta^TX^TY) = θ a r g m i n ( Y T Y − 2 θ T X T Y + θ T X T X Θ ) = θ a r g m i n ( θ T X T X θ − 2 θ T X T Y )
∇ θ ( θ T X T X θ − 2 θ T X T Y ) = 0 \nabla_\theta(\theta^TX^TX\theta-2\theta^TX^TY) = 0 ∇ θ ( θ T X T X θ − 2 θ T X T Y ) = 0
2 X T X θ − 2 X T Y = 0 2X^TX\theta-2X^TY = 0 2 X T X θ − 2 X T Y = 0
θ = ( X T X ) − 1 X T Y \theta = (X^TX)^{-1}X^TY θ = ( X T X ) − 1 X T Y
( X T X ) − 1 X T = X + ( M o o r e − P e n r o s e P s e u d o i n v e r s e ) (X^TX)^{-1}X^T = X^+(Moore-Penrose\,Pseudoinverse) ( X T X ) − 1 X T = X + ( M o o r e − P e n r o s e P s e u d o i n v e r s e )
θ = X + Y \theta = X^+Y θ = X + Y
Naive Bayes Classifier
한마디로: prior에 label값에 대하여 feature가 conditionally independent하다고 가정된 feature별 class conditional density의 총 곱을 곱하여 얻은 posterior값을 최대로 하는 label값 선택
Optimal Classification
f ^ = argmin f P ( f ( X ) ≠ Y ) \hat{f} = \underset{f}{\operatorname{argmin}}P(f(X){\neq}Y) f ^ = f a r g m i n P ( f ( X ) = Y )
y ^ = argmax y ∑ θ i ∈ Θ P ( y ∣ θ i ) P ( θ i ∣ D ) \hat{y} = \underset{y}{\operatorname{argmax}}\sum_{\theta_i{\in}\Theta}P(y|\theta_i)P(\theta_i|D) y ^ = y a r g m a x ∑ θ i ∈ Θ P ( y ∣ θ i ) P ( θ i ∣ D )
y ^ = argmax y P ( Y = y ∣ X = x ) = argmax y P ( X = x ∣ Y = y ) P ( Y = y ) \hat{y} = \underset{y}{\operatorname{argmax}}P(Y=y|X=x) = \underset{y}{\operatorname{argmax}}P(X=x|Y=y)P(Y=y) y ^ = y a r g m a x P ( Y = y ∣ X = x ) = y a r g m a x P ( X = x ∣ Y = y ) P ( Y = y )
Bayes Risk - 추후 재정리
Optimal Classification의 한계
y ^ = argmax y P ( X = x ∣ Y = y ) P ( Y = y ) \hat{y} = \underset{y}{\operatorname{argmax}}P(X=x|Y=y)P(Y=y) y ^ = y a r g m a x P ( X = x ∣ Y = y ) P ( Y = y )
feature 개수가 많아짐에 따라 feature compound가 급격하게 늘어남 (총 feature = (2^D-1)*k)
충분한 샘플을 확보하기가 힘들기 때문에, sparse한 데이터가 되어 학습에 문제가 발생
Conditional Independence Assumption
P ( X = < x 1 , ⋯ , x i > ∣ Y = y ) ≈ ∏ i P ( X i = x i ∣ Y = y ) P(X = <x_1, \cdots, x_i>|Y = y) \approx \prod_iP(X_i = x_i|Y = y) P ( X = < x 1 , ⋯ , x i > ∣ Y = y ) ≈ ∏ i P ( X i = x i ∣ Y = y )
P ( x 1 ∣ x 2 , y ) = P ( x 1 ∣ y ) P(x_1|x_2,y) = P(x_1|y) P ( x 1 ∣ x 2 , y ) = P ( x 1 ∣ y )
Conditional(local) vs Marginal Independence
P ( X ) = P ( X ∣ Y ) P(X) = P(X|Y) P ( X ) = P ( X ∣ Y )
Conditional(local) Independence
P ( x 1 ∣ x 2 , y ) = P ( x 1 ∣ y ) P(x_1|x_2,y) = P(x_1|y) P ( x 1 ∣ x 2 , y ) = P ( x 1 ∣ y )
Conditional Independence는 latent variable이 존재하고, 이에 대해서 dependent하기 때문에, Y가 condition일 경우 상호간에는 independent
Naive Bayes에서는 Label Y를 latent variable로 가정, 이에 대해서 모든 변수가 종속적인 것으로 가정하고 Y를 condition으로 줌
주의: Conditional Independence는 latent variable이 condition일 경우에만 독립
Naive Bayes Classifier
conditional independence 가정시
y ^ = argmax y P ( X = x ∣ Y = y ) P ( Y = y ) \hat{y} = \underset{y}{\operatorname{argmax}}P(X=x|Y=y)P(Y=y) y ^ = y a r g m a x P ( X = x ∣ Y = y ) P ( Y = y )
≈ argmax y P ( Y = y ) ∏ 1 ≤ i ≤ d P ( X i = x i ∣ Y = y ) = f N B ( x ) \approx \underset{y}{\operatorname{argmax}}P(Y=y)\prod_{1{\leq}i{\leq}d}P(X_i = x_i|Y = y) = f_{NB}(x) ≈ y a r g m a x P ( Y = y ) ∏ 1 ≤ i ≤ d P ( X i = x i ∣ Y = y ) = f N B ( x )
해당 식을 MLE식과 비교하여 정확한 차이를 숙지하자 개념적으로는 차이가 크지만, 계산방법에 있어서는 어느정도 유사
Logistic Regression
σ ( z ) = 1 1 + exp ( − z ) \sigma(z) = {1\over{1+\exp(-z)}} σ ( z ) = 1 + e x p ( − z ) 1
l o g i t ( p ) = ln ( p 1 − p ) logit(p) = \ln\left({p\over{1-p}}\right) l o g i t ( p ) = ln ( 1 − p p )
z = ln ( p 1 − p ) = X θ z = \ln\left({p\over{1-p}}\right) = X\theta z = ln ( 1 − p p ) = X θ
h θ ( x ) = σ ( θ T x ) = 1 1 + exp ( − θ T x ) h_\theta(x) = \sigma(\theta^Tx) = {1\over{1+\exp(-\theta^Tx)}} h θ ( x ) = σ ( θ T x ) = 1 + e x p ( − θ T x ) 1
다른 방식으로 해석하면 fixed basis function을 이용, x x x 를 ϕ ( x ) \phi(x) ϕ ( x ) 로 매핑하여 변환 후 판별한다고 해석할 수 있음(PRML Chapter4)
Bernoulli 적용
P ( y ∣ x ) = μ ( x ) y ( 1 − μ ( x ) ) 1 − y P(y|x) = \mu(x)^y(1-\mu(x))^{1-y} P ( y ∣ x ) = μ ( x ) y ( 1 − μ ( x ) ) 1 − y
μ ( x ) = 1 1 + exp ( − θ T x ) = 1 1 + exp ( − X θ ) = P ( y = 1 ∣ x ) \mu(x) = {1\over{1+\exp(-\theta^Tx})} = {1\over{1+\exp(-X\theta})} = P(y=1|x) μ ( x ) = 1 + e x p ( − θ T x ) 1 = 1 + e x p ( − X θ ) 1 = P ( y = 1 ∣ x )
X θ = ln ( μ ( x ) 1 − μ ( x ) ) X\theta = \ln\left(\mu(x)\over{1-\mu(x)}\right) X θ = ln ( 1 − μ ( x ) μ ( x ) )
θ ^ = argmax θ P ( D ∣ θ ) \hat\theta = \underset{\theta}{\operatorname{argmax}}P(D|\theta) θ ^ = θ a r g m a x P ( D ∣ θ )
MLE의 대상 D는 상황에 따라 의미가 다르다: 식에서 D가 무엇을 의미하는지 헷갈리지 말 것
Likelihood는 단순히 모수에 대하여 sample(관측값)이 발현할 확률
Likelihood를 과대해석하여 의미를 부여하려 하지 말 것 - 여기서는 모수와 X에 따른 Y의 발현확률
MCLE (Maximum Conditional Likelihood Estimation)
θ ^ = argmax θ P ( D ∣ θ ) = argmax θ ∏ 1 ≤ i ≤ N P ( Y i ∣ X i ; θ ) \hat\theta = \underset{\theta}{\operatorname{argmax}}P(D|\theta) = \underset{\theta}{\operatorname{argmax}}{\prod_{1{\leq}i{\leq}N}}P(Y_i|X_i;\theta) θ ^ = θ a r g m a x P ( D ∣ θ ) = θ a r g m a x ∏ 1 ≤ i ≤ N P ( Y i ∣ X i ; θ )
= argmax θ ln { ∏ 1 ≤ i ≤ N P ( Y i ∣ X i ; θ ) } = argmax θ ∑ 1 ≤ i ≤ N ln { P ( Y i ∣ X i ; θ ) } = \underset{\theta}{\operatorname{argmax}}\ln\left\{\prod_{1{\leq}i{\leq}N}P(Y_i|X_i;\theta)\right\} = \underset{\theta}{\operatorname{argmax}}\sum_{1{\leq}i{\leq}N}\ln\left\{P(Y_i|X_i;\theta)\right\} = θ a r g m a x ln { ∏ 1 ≤ i ≤ N P ( Y i ∣ X i ; θ ) } = θ a r g m a x ∑ 1 ≤ i ≤ N ln { P ( Y i ∣ X i ; θ ) }
P ( Y i ∣ X i ; θ ) = μ ( X i ) Y i ( 1 − μ ( X i ) ) 1 − Y i P(Y_i|X_i;\theta) = \mu(X_i)^{Y_i}(1-\mu(X_i))^{1-Y_i} P ( Y i ∣ X i ; θ ) = μ ( X i ) Y i ( 1 − μ ( X i ) ) 1 − Y i
ln P ( Y i ∣ X i ; θ ) = Y i ln μ ( X i ) + ( 1 − Y i ) ln ( 1 − μ ( X i ) ) {\ln}P(Y_i|X_i;\theta) = Y_i\ln\mu(X_i)+(1-Y_i)\ln(1-\mu(X_i)) ln P ( Y i ∣ X i ; θ ) = Y i ln μ ( X i ) + ( 1 − Y i ) ln ( 1 − μ ( X i ) )
= Y i ( ln μ ( X i ) − ln ( 1 − μ ( X i ) ) + ln ( 1 − μ ( X i ) ) = Y_i(\ln\mu(X_i)-\ln(1-\mu(X_i))+\ln(1-\mu(X_i)) = Y i ( ln μ ( X i ) − ln ( 1 − μ ( X i ) ) + ln ( 1 − μ ( X i ) )
= Y i ( ln μ ( X i ) 1 − μ ( X i ) ) + ln ( 1 − μ ( X i ) ) = Y_i\left(\ln{\mu(X_i)\over{1-\mu(X_i)}}\right)+\ln(1-\mu(X_i)) = Y i ( ln 1 − μ ( X i ) μ ( X i ) ) + ln ( 1 − μ ( X i ) )
= Y i X i θ + ln ( 1 − μ ( X i ) ) = Y_iX_i\theta + \ln(1-\mu(X_i)) = Y i X i θ + ln ( 1 − μ ( X i ) )
= Y i X i θ − ln { 1 + exp ( X i θ ) } = Y_iX_i\theta - \ln\{1+\exp(X_i\theta)\} = Y i X i θ − ln { 1 + exp ( X i θ ) }
∂ ∂ θ j [ ∑ 1 ≤ i ≤ N Y i X i θ − ln { 1 + exp ( X i θ ) } ] {\partial\over\partial\theta_j}\left[\sum_{1{\leq}i{\leq}N}Y_iX_i\theta - \ln\{1+\exp(X_i\theta)\}\right] ∂ θ j ∂ [ ∑ 1 ≤ i ≤ N Y i X i θ − ln { 1 + exp ( X i θ ) } ]
= ∑ 1 ≤ i ≤ N X i , j ( Y i − exp ( X i θ ) 1 + exp ( X i θ ) ) = \sum_{1{\leq}i{\leq}N}X_{i,j}\left(Y_i-{\exp(X_i\theta)\over{1+\exp(X_i\theta)}}\right) = ∑ 1 ≤ i ≤ N X i , j ( Y i − 1 + e x p ( X i θ ) e x p ( X i θ ) )
= ∑ 1 ≤ i ≤ N X i , j ( Y i − P ( Y i = 1 ∣ X i ; θ ) ) = 0 = \sum_{1{\leq}i{\leq}N}X_{i,j}(Y_i-P(Y_i=1|X_i;\theta)) = 0 = ∑ 1 ≤ i ≤ N X i , j ( Y i − P ( Y i = 1 ∣ X i ; θ ) ) = 0
apply gradient ascent
θ j t + 1 = θ j t + h c ∂ f ( θ t ) ∂ θ j \theta_j^{t+1} = \theta_j^t+{h\over{c}}{\partial{f(\theta^t)}\over\partial\theta_j} θ j t + 1 = θ j t + c h ∂ θ j ∂ f ( θ t )
= θ j t + h c ∑ 1 ≤ i ≤ N X i , j ( Y i − exp ( X i θ t ) 1 + exp ( X i θ t ) ) = \theta_j^t+{h\over{c}}{\sum_{1{\leq}i{\leq}N}X_{i,j}\left(Y_i-{\exp(X_i\theta^t)\over{1+\exp(X_i\theta^t)}}\right)} = θ j t + c h ∑ 1 ≤ i ≤ N X i , j ( Y i − 1 + e x p ( X i θ t ) e x p ( X i θ t ) )
computational하게 계산할 때는 일반적으로 negative log likelihood
− ∑ 1 ≤ i ≤ N ln P ( Y i ∥ X i ; θ ) = − ∑ 1 ≤ i ≤ N { Y i ln μ ( X i ) + ( 1 − Y i ) ln ( 1 − μ ( X i ) ) } -\sum_{1{\leq}i{\leq}N}{\ln}P(Y_i\|X_i;\theta) = -\sum_{1{\leq}i{\leq}N}\left\{Y_i\ln\mu(X_i)+(1-Y_i)\ln(1-\mu(X_i))\right\} − ∑ 1 ≤ i ≤ N ln P ( Y i ∥ X i ; θ ) = − ∑ 1 ≤ i ≤ N { Y i ln μ ( X i ) + ( 1 − Y i ) ln ( 1 − μ ( X i ) ) }
을 loss function으로 둔다
Generative - Discriminative Pair
Naive Bayes Classifier - Logistic Regression
Naive Bayes Classifier에서 Gaussian Distribution가정, class conditional variance를 동일하다고 가정할 경우, 식을 정리하면 Linear Regression의 형태가 됨
Softmax Regression(Multinomial Logistic Regression)
σ ( z ) j = e z j ∑ k = 1 K e z k ( f o r j = 1 , ⋯ , K ) \sigma(z)_j = {e^{z_j}\over{\sum_{k=1}^Ke^{z_k}}}{\quad}(for\,j=1,\cdots,K) σ ( z ) j = ∑ k = 1 K e z k e z j ( f o r j = 1 , ⋯ , K )
Softmax Function의 loss function
Bernoulli distribution
P ( y ∣ x ) = p 1 y 1 ( 1 − p 1 ) 1 − y 1 P(y|x) = p_1^{y_1}(1-p_1)^{1-y_1} P ( y ∣ x ) = p 1 y 1 ( 1 − p 1 ) 1 − y 1
여확률 대신, True와 False의 확률과 라벨을 각각 분리시켜 일반화
P ( y ∣ x ) = p 1 y 1 ( 1 − p 1 ) 1 − y 1 = p 1 y 1 p 0 y 0 P(y|x) = p_1^{y_1}(1-p_1)^{1-y_1} = p_1^{y_1}p_0^{y_0} P ( y ∣ x ) = p 1 y 1 ( 1 − p 1 ) 1 − y 1 = p 1 y 1 p 0 y 0
multinomial에 대하여 확장
P ( y ∣ x ) = p 1 y 1 p 2 y 2 p 3 y 3 ⋯ p C y C P(y|x) = p_1^{y_1}p_2^{y_2}p_3^{y_3}{\cdots}p_C^{y_C} P ( y ∣ x ) = p 1 y 1 p 2 y 2 p 3 y 3 ⋯ p C y C
= ∏ 1 ≤ j ≤ C p j y j = \prod_{1{\leq}j{\leq}C}p_j^{y_j} = ∏ 1 ≤ j ≤ C p j y j
negative log likelihood
− ∑ 1 ≤ i ≤ N ln P ( Y i , j ∥ X i ; θ ) = − ∑ 1 ≤ i ≤ N ∑ 1 ≤ j ≤ C Y i , j ln μ j ( X i ) -\sum_{1{\leq}i{\leq}N}{\ln}P(Y_{i,j}\|X_i;\theta) = -\sum_{1{\leq}i{\leq}N}\sum_{1{\leq}j{\leq}C}Y_{i,j}\ln{\mu_j(X_{i})} − ∑ 1 ≤ i ≤ N ln P ( Y i , j ∥ X i ; θ ) = − ∑ 1 ≤ i ≤ N ∑ 1 ≤ j ≤ C Y i , j ln μ j ( X i )
결과가 cross entropy의 식이 된다
logistic regression에서도 마찬가지, 분포로부터 얻은 negative log likelihood는 둘다 cross entropy의 식
cross entropy를 이처럼 KL-divergence를 통하여 모델과 타겟의 유사도를 판정한다는 개념 외에도, 분포 자체의 likelihood를 최대화하는 MLE과정에서의 목적함수로서의 개념으로도 이해할 수 있다.
Support Vector Machine
이 부분에 있어서는 이미 이해도가 높기에 간략히 정리하고 넘어가고, 추후 이슈가 발생할 때에 내용을 보완하기로 한다
개념 자체는 간단하기 때문에 기본개념과 dual problem, kernel trick부분만 간단히 정리
추후 linear programming, quadratic programming, dual problem에 대하여 집중적으로 정리해 본다
추후 주제와는 별개로 convex optimization에 중점을 두고 생각해 본다
Problem Definition
w T x + b = 0 w^Tx+b = 0 w T x + b = 0
w T x + + b = + δ w^Tx_++b = +\delta w T x + + b = + δ
w T x − + b = − δ w^Tx_-+b = -\delta w T x − + b = − δ
w T x + + b ≥ + δ : y = + 1 w^Tx_++b \geq +\delta : y = +1 w T x + + b ≥ + δ : y = + 1
w T x − + b ≤ − δ : y = − 1 w^Tx_-+b \leq -\delta : y = -1 w T x − + b ≤ − δ : y = − 1
y ( w T x + b ) ≥ δ y(w^Tx+b) \geq \delta y ( w T x + b ) ≥ δ
2 δ ∥ w ∥ {2\delta\over\lVert{w}\rVert} ∥ w ∥ 2 δ
y ( w T x + b ) / δ ≥ 1 y(w^Tx+b)/\delta \geq 1 y ( w T x + b ) / δ ≥ 1
w T x + b = 0 , ( w T x + b ) / δ = 0 w^Tx+b = 0, \quad (w^Tx+b)/\delta = 0 w T x + b = 0 , ( w T x + b ) / δ = 0
두 평면은 동일한 평면이며,
우리는 w와 b의 절대적인 값이 아니라, 비율에만 관심이 있다.
따라서,
y ( w T x + b ) ≥ 1 y(w^Tx+b) \geq 1 y ( w T x + b ) ≥ 1
y ( w T x + b ) − 1 ≥ 0 y(w^Tx+b)-1 \geq 0 y ( w T x + b ) − 1 ≥ 0
min ∥ w ∥ \operatorname{min}{\lVert{w}\rVert} m i n ∥ w ∥
계산상 편의를 위해
min 1 2 ∥ w ∥ 2 \operatorname{min}{1\over{2}}\lVert{w}\rVert^2 m i n 2 1 ∥ w ∥ 2
quadratic programming을 이용하여 풀거나, lagrange duality를 이용하여 풀거나
알고리즘적인 부분은 여유 있을 때 보고, 지금은 lagrange duality를 이용하여 이차식의 최소값을 gradient descent로 푸는 방식으로 해결하자
Soft-margin and Penalization
Zero-One Loss 적용한 objective function
min 1 2 ∥ w ∥ 2 + C ∗ # e r r o r \operatorname{min}{1\over{2}}\lVert{w}\rVert^2+C*\#_{error} m i n 2 1 ∥ w ∥ 2 + C ∗ # e r r o r
s . t . ( w T x i + b ) y i ≥ 1 s.t.\quad(w^Tx_i+b)y_i\geq{1} s . t . ( w T x i + b ) y i ≥ 1
min 1 2 ∥ w ∥ 2 + C ∑ i n ξ i \operatorname{min}{1\over{2}}\lVert{w}\rVert^2+C\sum_{i}^n\xi_i m i n 2 1 ∥ w ∥ 2 + C ∑ i n ξ i
s . t . y i ( w T x i + b ) ≥ 1 − ξ i , ξ i ≥ 0 s.t.{\quad}y_i(w^Tx_i+b)\geq{1-\xi_i},\quad{\xi_i\geq{0}} s . t . y i ( w T x i + b ) ≥ 1 − ξ i , ξ i ≥ 0
ξ i = m a x ( 0 , { 1 − y i ( w T x i + b ) } ) \xi_i = max(0, \{1-y_i(w^Tx_i+b)\}) ξ i = m a x ( 0 , { 1 − y i ( w T x i + b ) } )
parameter C의 효과
C가 클 수록 slack variable의 영향(strength of loss function)이 커지고, 이에 따라 soft-margin이 작아짐
C가 작을 경우 slack variable의 영향(strength of loss function)이 작아지고, 이에 따라 soft-margin이 넓어짐
C가 0일 경우, slack variable에 대한 제한이 없기에 hyperplane은 제 구실을 하지 못함
C가 무한대일 경우, slack variable을 허용하지 않기에 hard-margin
Langrangian Dual Problem
o p t i m i z e f ( x ) optimize\,f(x) o p t i m i z e f ( x )
s u b j e c t t o subject\,to s u b j e c t t o
g i ( x ) ≤ 0 g_i(x)\leq{0} g i ( x ) ≤ 0
h i ( x ) = 0 h_i(x) = 0 h i ( x ) = 0
KKT - 1: stationarity
lagrange multiplier method 의 핵심제약조건: 정류점(local max / local min / saddle)을 찾는 제약조건
for maximazing f(x):
∇ f ( x ∗ ) = ∑ i = 1 m μ i ∇ g i ( x ∗ ) + ∑ j = 1 l λ j ∇ h j ( x ∗ ) \nabla{f(x^*)} = \sum_{i=1}^{m}\mu_i\nabla{g_i}(x^*)+\sum_{j=1}^{l}\lambda_j\nabla{h_j}(x^*) ∇ f ( x ∗ ) = ∑ i = 1 m μ i ∇ g i ( x ∗ ) + ∑ j = 1 l λ j ∇ h j ( x ∗ )
for minimizing f(x):
− ∇ f ( x ∗ ) = ∑ i = 1 m μ i ∇ g i ( x ∗ ) + ∑ j = 1 l λ j ∇ h j ( x ∗ ) -\nabla{f(x^*)} = \sum_{i=1}^{m}\mu_i\nabla{g_i}(x^*)+\sum_{j=1}^{l}\lambda_j\nabla{h_j}(x^*) − ∇ f ( x ∗ ) = ∑ i = 1 m μ i ∇ g i ( x ∗ ) + ∑ j = 1 l λ j ∇ h j ( x ∗ )
g i ( x ∗ ) ≤ 0 , f o r i = 1 , ⋯ , m g_i(x^*)\leq{0},{\quad}for\,i=1,\cdots,m g i ( x ∗ ) ≤ 0 , f o r i = 1 , ⋯ , m
h j ( x ∗ ) = 0 , f o r j = 1 , ⋯ , l h_j(x^*)=0,{\quad}for\,j=1,\cdots,l h j ( x ∗ ) = 0 , f o r j = 1 , ⋯ , l
μ i ≥ 0 , f o r i = 1 , ⋯ , m \mu_i\geq{0},{\quad}for\,i=1,\cdots,m μ i ≥ 0 , f o r i = 1 , ⋯ , m
μ i g i ( x ∗ ) = 0 , f o r i = 1 , ⋯ , m \mu_ig_i(x^*) = 0,{\quad}for\,i=1,\cdots,m μ i g i ( x ∗ ) = 0 , f o r i = 1 , ⋯ , m
min L P = 1 2 ∥ w ∥ 2 + C ∑ i = 1 n ξ i + ∑ i = 1 n α i { 1 − y i ( w T x i + b ) − ξ i } + ∑ i = 1 n − β i ξ i \operatorname{min}L_P = {1\over{2}}\lVert{w}\rVert^2+C\sum_{i=1}^n\xi_i+\sum_{i=1}^n\alpha_i\{1-y_i(w^Tx_i+b)-\xi_i\}+\sum_{i=1}^n-\beta_i\xi_i m i n L P = 2 1 ∥ w ∥ 2 + C ∑ i = 1 n ξ i + ∑ i = 1 n α i { 1 − y i ( w T x i + b ) − ξ i } + ∑ i = 1 n − β i ξ i
= 1 2 ∥ w ∥ 2 + C ∑ i = 1 n ξ i − ∑ i = 1 n α i { y i ( w T x i + b ) + ξ i − 1 } − ∑ i = 1 n β i ξ i = {1\over{2}}\lVert{w}\rVert^2+C\sum_{i=1}^n\xi_i-\sum_{i=1}^n\alpha_i\{y_i(w^Tx_i+b)+\xi_i-1\}-\sum_{i=1}^n\beta_i\xi_i = 2 1 ∥ w ∥ 2 + C ∑ i = 1 n ξ i − ∑ i = 1 n α i { y i ( w T x i + b ) + ξ i − 1 } − ∑ i = 1 n β i ξ i
∂ L ∂ w = 0 ∂ L ∂ b = 0 ∂ L ∂ ξ = 0 {\partial{L}\over{\partial{w}}} = 0\quad{\partial{L}\over{\partial{b}}} = 0\quad{\partial{L}\over{\partial{\xi}}} = 0 ∂ w ∂ L = 0 ∂ b ∂ L = 0 ∂ ξ ∂ L = 0
w = ∑ i = 1 n α i y i x i w = \sum_{i=1}^n\alpha_iy_ix_i w = ∑ i = 1 n α i y i x i
∑ i = 1 n α i y i = 0 \sum_{i=1}^n\alpha_iy_i = 0 ∑ i = 1 n α i y i = 0
∑ i = 1 n ( C − α i − β i ) = 0 \sum_{i=1}^n(C-\alpha_i-\beta_i) = 0 ∑ i = 1 n ( C − α i − β i ) = 0
Primal feasibility condition
y i ( w T x i + b ) ≥ 1 − ξ i , ξ i ≥ 0 y_i(w^Tx_i+b)\geq{1-\xi_i},\quad{\xi_i\geq{0}} y i ( w T x i + b ) ≥ 1 − ξ i , ξ i ≥ 0
Dual feasibility condition
α i ≥ 0 , β i ≥ 0 \alpha_i\geq{0},\quad\beta_i\geq{0} α i ≥ 0 , β i ≥ 0
Complementary slackness condition
α i { y i ( w T x i + b ) + ξ i − 1 } = 0 , β i ξ i = 0 \alpha_i\{y_i(w^Tx_i+b)+\xi_i-1\} = 0,\quad\beta_i\xi_i = 0 α i { y i ( w T x i + b ) + ξ i − 1 } = 0 , β i ξ i = 0
derived condition (from stationary & dual feasibility)
C ≥ α i ≥ 0 C\geq{\alpha_i}\geq{0} C ≥ α i ≥ 0
min L P = 1 2 ∥ w ∥ 2 + C ∑ i = 1 n ξ i − ∑ i = 1 n α i { y i ( w T x i + b ) + ξ i − 1 } − ∑ i = 1 n β i ξ i \operatorname{min}L_P = {1\over{2}}\lVert{w}\rVert^2+C\sum_{i=1}^n\xi_i-\sum_{i=1}^n\alpha_i\{y_i(w^Tx_i+b)+\xi_i-1\}-\sum_{i=1}^n\beta_i\xi_i m i n L P = 2 1 ∥ w ∥ 2 + C ∑ i = 1 n ξ i − ∑ i = 1 n α i { y i ( w T x i + b ) + ξ i − 1 } − ∑ i = 1 n β i ξ i
max L D = ∑ i = 1 n α i − 1 2 ∑ i = 1 n ∑ j = 1 n α i α j y i y j x i T x j \operatorname{max}L_D = \sum_{i=1}^n\alpha_i-{1\over{2}}\sum_{i=1}^n\sum_{j=1}^n\alpha_i\alpha_jy_iy_jx_i^Tx_j m a x L D = ∑ i = 1 n α i − 2 1 ∑ i = 1 n ∑ j = 1 n α i α j y i y j x i T x j
( ∑ i = 1 n α i y i = 0 ) \left(\sum_{i=1}^n\alpha_iy_i = 0\right) ( ∑ i = 1 n α i y i = 0 )
( α i { y i ( w T x i + b ) − 1 } = 0 ) \left(\alpha_i\{y_i(w^Tx_i+b)-1\} = 0\right) ( α i { y i ( w T x i + b ) − 1 } = 0 )
( C ≥ α i ≥ 0 ) \left(C\geq{\alpha_i}\geq{0}\right) ( C ≥ α i ≥ 0 )
Kernel Trick
Mercer’s theorem
K ( x , y ) K(x,y) K ( x , y ) 가 positive semidefinite할 경우, K ( x i , x j ) = ϕ ( x i ) ⋅ ϕ ( x j ) = ϕ ( x i ) T ϕ ( x j ) K(x_i,x_j) = \phi(x_i)\cdot\phi(x_j) = \phi(x_i)^T\phi(x_j) K ( x i , x j ) = ϕ ( x i ) ⋅ ϕ ( x j ) = ϕ ( x i ) T ϕ ( x j ) 를 만족하는 ϕ \phi ϕ 존재
다른 공간으로 매핑하는 함수ϕ \phi ϕ 의 존재를 알기에, K를 kernel로 사용 가능
ϕ \phi ϕ 를 고차원 basis function으로 mapping시킬 경우, 연산량이 대단히 높음 (RBF의 경우 무한대의 차원으로 매핑)
kernel을 이용하여 이러한 문제를 해결
dual problem 적용
max L D = ∑ i = 1 n α i − 1 2 ∑ i = 1 n ∑ j = 1 n α i α j y i y j ϕ ( x i ) T ϕ ( x j ) \operatorname{max}L_D = \sum_{i=1}^n\alpha_i-{1\over{2}}\sum_{i=1}^n\sum_{j=1}^n\alpha_i\alpha_jy_iy_j\phi(x_i)^T\phi(x_j) m a x L D = ∑ i = 1 n α i − 2 1 ∑ i = 1 n ∑ j = 1 n α i α j y i y j ϕ ( x i ) T ϕ ( x j )
= ∑ i = 1 n α i − 1 2 ∑ i = 1 n ∑ j = 1 n α i α j y i y j K ( x i , x j ) = \sum_{i=1}^n\alpha_i-{1\over{2}}\sum_{i=1}^n\sum_{j=1}^n\alpha_i\alpha_jy_iy_jK(x_i,x_j) = ∑ i = 1 n α i − 2 1 ∑ i = 1 n ∑ j = 1 n α i α j y i y j K ( x i , x j )
w = ∑ i = 1 n α i y i ϕ ( x i ) w = \sum_{i=1}^n\alpha_iy_i\phi(x_i) w = ∑ i = 1 n α i y i ϕ ( x i )
b = y i − ∑ i = 1 n α i y i ϕ ( x i ) T ϕ ( x j ) b = y_i-\sum_{i=1}^n\alpha_iy_i\phi(x_i)^T\phi(x_j) b = y i − ∑ i = 1 n α i y i ϕ ( x i ) T ϕ ( x j )
decision boundary를 확인할 필요 없고, classification만이 관심사
s i g n ( w ϕ ( x ) + b ) = s i g n ( ∑ i = 1 n α i y i ϕ ( x i ) ϕ ( x ) + y i − ∑ i = 1 n α i y i ϕ ( x i ) T ϕ ( x j ) ) sign(w\phi(x)+b) = sign\left(\sum_{i=1}^n\alpha_iy_i\phi(x_i)\phi(x)+y_i-\sum_{i=1}^n\alpha_iy_i\phi(x_i)^T\phi(x_j)\right) s i g n ( w ϕ ( x ) + b ) = s i g n ( ∑ i = 1 n α i y i ϕ ( x i ) ϕ ( x ) + y i − ∑ i = 1 n α i y i ϕ ( x i ) T ϕ ( x j ) )
= s i g n ( ∑ i = 1 n α i y i K ( x i , x ) + y i − ∑ i = 1 n α i y i K ( x i , x j ) ) = sign\left(\sum_{i=1}^n\alpha_iy_iK(x_i,x)+y_i-\sum_{i=1}^n\alpha_iy_iK(x_i,x_j)\right) = s i g n ( ∑ i = 1 n α i y i K ( x i , x ) + y i − ∑ i = 1 n α i y i K ( x i , x j ) )
K ( x 1 , x 2 ) = x 1 T x 2 K(x_1,x_2) = x_1^Tx_2 K ( x 1 , x 2 ) = x 1 T x 2
K ( x 1 , x 2 ) = ( γ ( x 1 T x 2 ) + θ ) d K(x_1,x_2) = (\gamma(x_1^Tx_2)+\theta)^d K ( x 1 , x 2 ) = ( γ ( x 1 T x 2 ) + θ ) d
RBF(Radial Basis Function), Gaussian Kernel
K ( x 1 , x 2 ) = exp ( − γ ∥ x 1 − x 2 ∥ 2 ) K(x_1,x_2) = \exp(-\gamma\lVert{x_1-x_2}\rVert^2) K ( x 1 , x 2 ) = exp ( − γ ∥ x 1 − x 2 ∥ 2 )
K ( x 1 , x 2 ) = tanh ( γ ( x 1 T x 2 ) + θ ) K(x_1,x_2) = \tanh(\gamma(x_1^Tx_2)+\theta) K ( x 1 , x 2 ) = tanh ( γ ( x 1 T x 2 ) + θ )
Training / Testing & Regularization
Source of error in two folds
E o u t ≤ E i n + Ω E_{out}\leq{E_{in} + \Omega} E o u t ≤ E i n + Ω
E o u t : E s t i m a t i o n e r r o r E_{out}:{\quad}Estimation\,error E o u t : E s t i m a t i o n e r r o r
E i n : E r r o r f r o m a p p r o x i m a t i o n E_{in}:{\quad}Error\,from\,approximation E i n : E r r o r f r o m a p p r o x i m a t i o n
Ω : E r r o r f r o m v a r i a n c e o f t h e o b s e r v a t i o n \Omega:{\quad}Error\,from\,variance\,of\,the\,observation Ω : E r r o r f r o m v a r i a n c e o f t h e o b s e r v a t i o n
Bias-Variance Decomposition
(문인철교수 강의보다는 PRML의 식이 더 입맛에 맞아 이쪽의 notation으로 정리)
notation
t t t : 입력 데이터 x에 대응되는 target값 (x에 대하여 단일 값이 아닌 분포의 형태를 띔)
h h h : target t를 real world의 전체 dataset에 대하여 평균낸 optimal prediction
y y y : dataset을 통하여 예측한 hypothesis
L L L : loss
optimal prediction
h ( x ) = E ( t ∣ x ) = ∫ t p ( t ∣ x ) d t h(x) = E(t|x) = \int{tp(t|x)}dt h ( x ) = E ( t ∣ x ) = ∫ t p ( t ∣ x ) d t
expected loss
E ( L ) = ∬ { y ( x ) − t } 2 p ( x , t ) d x d t E(L) = \iint\{y(x)-t\}^2p(x,t)dxdt E ( L ) = ∬ { y ( x ) − t } 2 p ( x , t ) d x d t
= ∫ { y ( x ) − h ( x ) } 2 p ( x ) d x + ∬ { h ( x ) − t } 2 p ( x , t ) d x d t = \int\{y(x)-h(x)\}^2p(x)dx+\iint\{h(x)-t\}^2p(x,t)dxdt = ∫ { y ( x ) − h ( x ) } 2 p ( x ) d x + ∬ { h ( x ) − t } 2 p ( x , t ) d x d t
우측텀은 sampling시 data의 noise항이므로 hypothesis와 무관계
첫 번째 텀에 대하여 논의 진행
∫ { y ( x ) − h ( x ) } 2 p ( x ) d x = ∫ E D ( { y ( x ; D ) − h ( x ) } 2 ) p ( x ) d x \int\{y(x)-h(x)\}^2p(x)dx = \int{E_D(\{y(x;D)-h(x)\}^2)p(x)dx} ∫ { y ( x ) − h ( x ) } 2 p ( x ) d x = ∫ E D ( { y ( x ; D ) − h ( x ) } 2 ) p ( x ) d x
E D ( { y ( x ; D ) − h ( x ) } 2 ) E_D(\{y(x;D)-h(x)\}^2) E D ( { y ( x ; D ) − h ( x ) } 2 )
= E D ( { y ( x ; D ) − E D ( y ( x ; D ) ) + E D ( y ( x ; D ) ) − h ( x ) } 2 ) = E_D(\{y(x;D)-E_D(y(x;D))+E_D(y(x;D))-h(x)\}^2) = E D ( { y ( x ; D ) − E D ( y ( x ; D ) ) + E D ( y ( x ; D ) ) − h ( x ) } 2 )
= E D ( { y ( x ; D ) − E D ( y ( x ; D ) ) } 2 + { E D ( y ( x ; D ) ) − h ( x ) } 2 = E_D(\{y(x;D)-E_D(y(x;D))\}^2+\{E_D(y(x;D))-h(x)\}^2 = E D ( { y ( x ; D ) − E D ( y ( x ; D ) ) } 2 + { E D ( y ( x ; D ) ) − h ( x ) } 2
+ 2 { y ( x ; D ) − E D ( y ( x ; D ) ) } { E D ( y ( x ; D ) ) − h ( x ) } ) +2\{y(x;D)-E_D(y(x;D))\}\{E_D(y(x;D))-h(x)\}) + 2 { y ( x ; D ) − E D ( y ( x ; D ) ) } { E D ( y ( x ; D ) ) − h ( x ) } )
E D ( y ( x ; D ) ) − h ( x ) = c o n s t E_D(y(x;D))-h(x) = const E D ( y ( x ; D ) ) − h ( x ) = c o n s t
E D ( y ( x ; D ) − E D ( y ( x ; D ) ) ) = 0 E_D(y(x;D)-E_D(y(x;D))) = 0 E D ( y ( x ; D ) − E D ( y ( x ; D ) ) ) = 0
∴ ∫ E D ( { y ( x ; D ) − h ( x ) } 2 ) p ( x ) d x \therefore{\int{E_D(\{y(x;D)-h(x)\}^2)p(x)dx}} ∴ ∫ E D ( { y ( x ; D ) − h ( x ) } 2 ) p ( x ) d x
= ∫ { E D ( y ( x ; D ) ) − h ( x ) } 2 p ( x ) d x + ∫ E D ( { y ( x ; D ) − E D ( y ( x ; D ) ) } 2 ) p ( x ) d x = \int{\{E_D(y(x;D))-h(x)\}^2p(x)dx}+\int{E_D(\{y(x;D)-E_D(y(x;D))\}^2)p(x)dx} = ∫ { E D ( y ( x ; D ) ) − h ( x ) } 2 p ( x ) d x + ∫ E D ( { y ( x ; D ) − E D ( y ( x ; D ) ) } 2 ) p ( x ) d x
∴ E ( L ) = ∬ { y ( x ) − t } 2 p ( x , t ) d x d t \therefore{E(L) = \iint\{y(x)-t\}^2p(x,t)dxdt} ∴ E ( L ) = ∬ { y ( x ) − t } 2 p ( x , t ) d x d t
= ∫ { E D ( y ( x ; D ) ) − h ( x ) } 2 p ( x ) d x ( b i a s ) 2 = \int{\{E_D(y(x;D))-h(x)\}^2p(x)dx}\quad(bias)^2 = ∫ { E D ( y ( x ; D ) ) − h ( x ) } 2 p ( x ) d x ( b i a s ) 2
+ ∫ E D ( { y ( x ; D ) − E D ( y ( x ; D ) ) } 2 ) p ( x ) d x ( v a r i a n c e ) + \int{E_D(\{y(x;D)-E_D(y(x;D))\}^2)p(x)dx}\quad(variance) + ∫ E D ( { y ( x ; D ) − E D ( y ( x ; D ) ) } 2 ) p ( x ) d x ( v a r i a n c e )
+ ∬ { h ( x ) − t } 2 p ( x , t ) d x d t ( n o i s e ) + \iint\{h(x)-t\}^2p(x,t)dxdt\quad(noise) + ∬ { h ( x ) − t } 2 p ( x , t ) d x d t ( n o i s e )
bias: model이 real world를 충분하게 표현할 수 없는 한계
to reduce: more complex model
variance: sample과 infinite dataset의 괴리
Dataset이 제한되어있을 때, bias와 variance는 model complexity를 변수로 하는 tradeoff관계
Model Complexity를 높임 (unstable, specific, overfitting)
variance증가, bias감소
dataset에 대하여 높은 성능
real world에 대하여 unstable
Model Complexity를 낮춤 (stable, general, underfitting)
variance감소, bias증가
dataset을 잘 표현하지 못함
real world에 대하여 stable
Occam’s Razor
오차가 비슷할 경우, complexity가 낮은 모델을 선택
Cross Validation
|||실제정답|
|||Positive|Negative|
|:---:|:---:|:---:|:---:|
실험결과|Positive|TP(True Positive)|FP(False Positive)|
||Negative|FN(False Negative)|TN(True Negative)|
Accuracy = T P + T N T P + F P + F N + T N {TP+TN\over{TP+FP+FN+TN}} T P + F P + F N + T N T P + T N
Precision = T P T P + F P {TP\over{TP+FP}} T P + F P T P
Recall = T P T P + F N {TP\over{TP+FN}} T P + F N T P
True negative rate(specificity) = T N T N + F P {TN\over{TN+FP}} T N + F P T N
Precision
Positive로 판정한 data중 실제로 positive인 data
Precision을 높일 경우 False Positive를 최소화하게 됨, positive 판정에 대하여 엄격
높은 Precision을 요구하는 예로 spam filter가 있음
Recall
실제로 positive인 data중 positive로 판정한 data
Recall의 높일 경우 False Negative를 최소화하게 됨, negative 판정에 대하여 엄격
높은 Recall을 요구하는 예로 CRM이 있음
F-measure
F β = ( 1 + β 2 ) ∗ p r e c i s i o n ∗ r e c a l l β 2 ∗ p r e c i s i o n + r e c a l l F_\beta={(1+\beta^2)*precision * recall\over\beta^2*precision+recall} F β = β 2 ∗ p r e c i s i o n + r e c a l l ( 1 + β 2 ) ∗ p r e c i s i o n ∗ r e c a l l
F 1 F_1 F 1 : evenly weighted
F 2 F_2 F 2 : emphasizes recall
F 0 . 5 F_0.5 F 0 . 5 : emphasizes precision
Regularization
PRML과 (http://enginius.tistory.com/476 )의 게시글 정리,
블로그의 게시글에 추가적으로 볼 내용 있으나, Legendre polynomial / Augmented error파트는 다 읽지 못함
추후에 반드시 공부할 것
E o u t ≤ E i n + Ω E_{out}\leq{E_{in} + \Omega} E o u t ≤ E i n + Ω
E ( w ) = E D ( w ) + λ E W ( w ) E(w) = E_D(w)+\lambda{E_W(w)} E ( w ) = E D ( w ) + λ E W ( w )
sacrifice perfect fit, complexity를 낮추는 효과(variance control)
weight decay : coefficient(weight)의 크기를 variance의 요인(복잡도)의 평가 기준으로 삼음
E ( w ) = 1 2 ∑ n = 1 N { t n − w T ϕ ( x n ) } 2 + 1 2 ∑ j = 1 M ∥ w j ∥ q E(w) = {1\over{2}}\sum_{n=1}^N\{t_n-w^T\phi(x_n)\}^2+{1\over{2}}\sum_{j=1}^M\lVert{w_j}\rVert^q E ( w ) = 2 1 ∑ n = 1 N { t n − w T ϕ ( x n ) } 2 + 2 1 ∑ j = 1 M ∥ w j ∥ q
Mahalanobis Distance / Singular Value Decomposition (과정외)
D M 2 = ( x − μ ) T Σ − 1 ( x − μ ) D_M^2 = (x-\mu)^T\Sigma^{-1}(x-\mu) D M 2 = ( x − μ ) T Σ − 1 ( x − μ )
X D ‾ = U S V T \overline{X_{D}} = USV^T X D = U S V T
Σ = X D ‾ T X D ‾ = V S U T U S V T = V S S V T \Sigma = \overline{X_{D}}^T\overline{X_{D}} = VSU^TUSV^T = VSSV^T Σ = X D T X D = V S U T U S V T = V S S V T
Σ + = V S + S + V T \Sigma^+ = VS^+S^+V^T Σ + = V S + S + V T
D M 2 = ( x − μ ) T Σ − 1 ( x − μ ) = ( x − μ ) T V S + S + V T ( x − μ ) D_M^2 = (x-\mu)^T\Sigma^{-1}(x-\mu) = (x-\mu)^TVS^+S^+V^T(x-\mu) D M 2 = ( x − μ ) T Σ − 1 ( x − μ ) = ( x − μ ) T V S + S + V T ( x − μ )
= { ( x − μ ) T V S + } { ( x − μ ) T V S + } T = \{(x-\mu)^TVS^+\}\{(x-\mu)^TVS^+\}^T = { ( x − μ ) T V S + } { ( x − μ ) T V S + } T