๐ ๋ก์ง์คํฑ ํ๊ท ํฌ์คํ ์์ MLE๊ธฐ๋ฒ์ ํตํด model์ ๊ฒฐ์ ํ๋ค๊ณ ํ์๋ค. ๋ก์ง์คํฑ ํ๊ท์ ์์ ๋ deepํ๊ฒ ์ํ์ ์ผ๋ก ๋ค์ด๊ฐ, ์ด๋ค ๋ชจ๋ธ์ ๊ณ ๋ฅผ ์ง ์์์ผ๋ก ์ฐ์ฐํ๋ ๊ณผ์ ์์ MLE๊ฐ ํต์ฌ์ผ๋ก ์ฌ์ฉ๋๋๋ฐ, ์ด๋ฒ ์๊ฐ์๋ MLE๋ฅผ ์ํ์ ์ธ ๊ฐ๋ ์ผ๋ก ์ข ๋ ์์ธํ๊ฒ(๊ฝค deepํ๊ฒ) ์์๋ณด๊ณ ์ ํ๋ค.
๐ ์ถ๊ฐ๋ก ์๋ ๊ทธ๋ฆผ์์ ๋ณด๋ฏ์ด ์ถํ ํฌ์คํ ์์๋ ๋ก์ง์คํฑ ํ๊ท์ MLE๋ฅผ ๊ฐ์ด ์ฐ๊ด์์ผ ์์๋ณด์!
* ์ ์ & concepts>
๐ ๋ชจ์์ ์ธ ๋ฐ์ดํฐ ๋ฐ๋ ์ถ์ ๋ฐฉ๋ฒ์ผ๋ก, ํ๋ผ๋ฏธํฐ $\theta = (\theta_1, ... , \theta_m)$์ผ๋ก ๊ตฌ์ฑ๋ ์ด๋ค ํ๋ฅ ๋ฐ๋ํจ์ $P(x|\theta)$์์ ๊ด์ธก๋ ํ๋ณธ ๋ฐ์ดํฐ ์งํฉ์ $x = (x_1, x_2, ... , x_n)$์ด๋ผ ํ ๋, ์ด ํ๋ณธ๋ค์์ ํ๋ผ๋ฏธํฐ $\theta = (\theta_1, ... , \theta_m)$๋ฅผ ์ถ์ ํ๋ ๋ฐฉ๋ฒ
๐ ์ฝ๊ฒ ๋งํ๋ฉด, ์ฃผ์ด์ง data ์ฌ๋ฌ x๋ค์ด ์๋๋ฐ, ํด๋น x๋ฅผ ๊ฐ์ฅ ์ ์ค๋ช ํ๋ ์ต์ ์ distribution์ ์ฐพ๋ ๊ฒ - (ํ๋ฅ ๋ฐ๋ํจ์ ์ฐพ๊ธฐ - ํ๋ฅ ๋ฐ๋ํจ์ ๊ด๋ จ parameter $\theta$ ์ฐพ๊ธฐ)
๐ ex) ์๋ฅผ ๋ค์ด ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ์ฃผ์ด์ง ์ฌ๋ฌ x data ์ ๋ค์ด ์๊ณ ํด๋น data ์ ๋ค์ ๊ฐ์ฅ ์ ์ค๋ช ํ๋ ์ต์ ์ 'normal distribution'์ ์ฐพ๋๋ค๋ฉด MLE ์ฃผํฉ์ ๊ณก์ ์ ์ฐพ์ ์ ์๋ค. (์์ ์ด์ฉํ MLE ๊ธฐ๋ฒ์ ๋ค์ ํฌ์คํ ์ ์์ธํ ์ค๋ช ์์ )
๐ ์ง๊ด์ ์ผ๋ก ๋ณด์๋ฉด, ํน์ ๋ชจ์ parameter๋ค์ ์งํฉ์ผ๋ก ์ด๋ฃจ์ด์ง ํน์ ๋ถํฌ๊ฐ ์ฃผ์ด์ง x๋ฅผ ๊ฐ์ฅ ์ ์ค๋ช ํ๋ ๋ถํฌ์ธ์ง ์์๋ณด๊ธฐ ์ํด, ํด๋น x์์์ ๋ถํฌ๊น์ง์ ๋์ด๋ฅผ ๋ชจ๋ x๋ณ๋ก ๋ค ๊ณ์ฐํด์ ๊ฐ๊ฐ ๊ณฑํ๋ค. ์ด ๊ณฑํ ๊ฒฐ๊ณผ๋ฅผ 'likelihood(๊ฐ๋ฅ๋)'๋ผ ํ๋ฉฐ, ํด๋น likelihood๊ฐ ์ต๋๊ฐ ๋๋ ๋ถํฌ๋ฅผ ์ต์ข ์ ์ผ๋ก ์ ํ๋ค.
๐ ์
โ $L$ = $L_1$ x $L_2$ x $L_3$ x ... x $L_n$
(์ด n๊ฐ์ x data๊ฐ ์กด์ฌํ๊ณ ๊ฐ๊ฐ์ likelihood๋ฅผ ๋ชจ๋ ๊ณฑํ ๊ฒฐ๊ณผ๋ฅผ ์ต์ข ์ ์ธ likelihood๋ผ ํ์.)
โก $\prod_{i=1}^{N} L_{i}$ = $p(x_1|\hat{\theta})$ x $p(x_2|\hat{\theta})$ x $p(x_3|\hat{\theta})$ x ... x $p(x_N|\hat{\theta})$
(์ด likelihood๋ ๊ฐ x๋ณ ๋ชจ์ $\theta$ ๋ชจ์์ ๊ฐ๊ณ ์๋ ๋ถํฌ - ํ๋ฅ ๋ฐ๋ํจ์๊ฐ์ ๋ชจ๋ ๊ณฑํ ๊ฒ์์ ๋ปํ๋ค.)
โข $L$ = $\prod_{i=1}^{N} p(x_i|\hat{\theta})$
(์ฆ, ์ ๋ฆฌํ๋ฉด ์์ ๊ฐ์ด ์ ๋ฆฌํ ์ ์๋ค.)
โฃ $lnL$ = $\sum_{i=1}^{N} lnp(x_i|\hat{\theta})$
(์ดํ ๋ฏธ๋ถ์ ํธ์์ฑ์ ์ํด ์๋ณ์ log๋ฅผ ๋ถ์ฌ๋ณด์ - log likelihood function)
โค $\frac{\partial}{\partial \theta}$ $lnL(\theta|x)$ = $\sum_{i=1}^{N}$ $\frac{\partial}{\partial \theta}$ $lnp(x_i|\hat{\theta})$ = 0
(๋ถํฌ ๋ชจ์ $\theta$์ ๋ํด์ ํธ๋ฏธ๋ถ์ ํ๊ณ , ๋ฏธ๋ถ๊ฒฐ๊ณผ๊ฐ์ด 0์ผ ๋์ $\theta$ ๊ฐ์ ์ฐพ๋๋ค!
∴ ๊ทธ ๊ฒฐ๊ณผ ๊ตฌํด์ง $\theta$๋ก ์ด๋ฃจ์ด์ง ๋ถํฌ๊ฐ ์ฐ๋ฆฌ๊ฐ ์ฃผ์ด์ง x data๋ก ์ด๋ฃจ์ด์ง ์ํ๋ ๋ถํฌ.
(๋ชจ์ $\theta$๊ฐ ๋ ์ข
๋ฅ ์ด์์ผ๋ก ์ด๋ฃจ์ด์ ธ ์๋ค๋ฉด, ๊ฐ ์ข
๋ฅ๋ณ๋ก ๋ฏธ๋ถํ ๊ฒฐ๊ณผ(์ฆ ๊ฐ๊ฐ ํธ๋ฏธ๋ถ)๋ฅผ 0์ผ๋ก ๋์ด ํด๋น ๋ชจ์ ๊ฐ์ ๊ตฌํ๋ฉด ๋๋ค)
* w/logistic regression?>
Logistic Regression Model (concepts)
** ML ๊ฐ์ ํฌ์คํ ์์ ๋ค๋ฃฌ 'supervised learning'์ ์๋์ ๊ฐ์ ์ ์ฐจ๋ฅผ ๋ฐ๋ฅธ๋ค๊ณ ํ๋ค (↓↓↓↓ํ๋จ ํฌ์คํ ์ฐธ์กฐ ↓↓↓↓) ML Supervised Learning → Regression → Linear Regression 1. ML ๊ธฐ๋ฒ ๊ตฌ๋ถ ๐..
sh-avid-learner.tistory.com
๐ ์ผ๋ช '์ค์ฆ๋น'๋ก ๋ถ๋ฆฐ odds๋ ํ๋ฅ ๋ก 0์ด์ 1์ดํ์ ๊ฐ์ ๊ฐ์ง๋, ์๊ทธ๋ชจ์ด๋ ํจ์ ํํ๋ก ๊ณก์ ์ ๋ณด์ด๊ธฐ์, ์ฐ๋ฆฌ๋ '์ค์ฆ๋น'์ ๋ก๊ทธ๋ฅผ ์ทจํด ์ง์ ํจ์ ํํ๋ก ๋ฐ๊ฟ์ฃผ์๋ค.
๐ ์ง์ ์ผ๋ก ๋ฐ๋์์ง๋ง, ln ๋ก๊ทธ๋ฅผ ์ทจํจ์ผ๋ก์จ y๊ฐ์ range๊ฐ $-\infty$ ~ $+\infty$์ ๋ฒ์๋ฅผ ๋ณด์ฌ OLS -least squares method๋ก ์ฃผ์ด์ง data์ ์ง์ ๊ฐ์ ๊ฑฐ๋ฆฌ ์ ๊ณฑํฉ์ ๋ฐฉ๋ฒ์ ์ด์ฉํด ์ต์ ์ fitting line์ ์ฐพ์ ์๊ฐ ์๋ค. (OLS๋ฅผ logisitc์์ ์ฌ์ฉํ ์ ์๋ ์ด์ )
๐ ๋ฐ๋ผ์ ์ต์ ์ logistic model์ ์ฐพ๊ธฐ ์ํ ๋ฐฉ๋ฒ์ผ๋ก MLE(Maximum Likelihood Estimaiton) ๊ธฐ๋ฒ์ ํํจ. ์ฃผ์ด์ง x data๋ฅผ ์ด์ฉํด data๋ฅผ ๊ฐ์ฅ ์ ์ค๋ช ํ๋ logistic model์ ์ฐพ์๋ณด์.
๐ MLE์ likelihood๋ Odds์์์ p ์ฑ๊ณตํ๋ฅ ์ ๋ปํ๋ค.
๐ ๋ฐ๋ผ์ ์ฐ๋ฆฌ๋ ์์์ LR ์ง์ ์ ์ธ์ฐ๊ณ , logit transformationํ ๋ค์, ๊ฐ data๋ณ p ์ฑ๊ณตํ๋ฅ (likelihood)์ ๋ชจ๋ ๊ตฌํด์ผ ํ๋ค.
(์ฌ๊ธฐ์ 1์ด ์๋ 0์ผ๋ก class๊ฐ ๋ถ๋ฅ๋๋ data๋ (1- SLR ๊ณก์ ๊ฐ)์ด likelihood์ด๋ค.)
๐ ใlogistic model selection ์ ์ฐจใ
โ $\theta^T = [\theta_0, \theta_1, ... , \theta_n]$๋ฅผ ๋ชจ์๋ก ๊ฐ๊ณ ์๊ณ , ๋ class(A, B)๋ก ๋ถ๋ฅ๋ LR์ ๋จผ์ ์์ผ๋ก ๋ํ๋ด๋ฉด
$P(y_i = A | x_i;\hat{\theta}) = \theta^T \bar{x}$
$\theta^T = [\theta_0, \theta_1, ... \theta_n], \bar{x} = [1, x_0, x_1, ... , x_n]^T$
โก likelihood๋ฅผ ๊ตฌํ๊ธฐ ์ํด, [0, 1] range๋ก ๊ตฌ์ฑ๋ sigmoid ๊ณก์ ์ผ๋ก์ ๋ณํ - logit transformation ์ํ
$h(x) = \sigma(\theta^{T}\bar{x}) = \cfrac{1}{(1+e^{-\theta^{T}\bar{x}})}$
→ ์ฆ, likelihood๋ก ๋ํ๋ด๋ฉด $P(y_i = A | x_i;\hat{\theta}) = \cfrac{1}{(1+e^{-\theta^{T}\bar{x}})}$
→ class B์ ๊ฒฝ์ฐ likelihood๋ $P(y_i = B | x_i;\hat{\theta}) = 1 - \cfrac{1}{(1+e^{-\theta^{T}\bar{x}})}$
โข binary problem๊ณผ ๊ฐ์ด, ๋ class A์ class B์ ๊ฐ likelihood๋ฅผ ํฉ์น๋ฉด (bernoulli distribution์ ์ํด - ๊ณง ํฌ์คํ )
$P(y_i | x_i;\hat{\theta}) = h(x_i)^{y_i} (1-h(x_i))^{1-y_i}$
→ ๊ฐ๋ณ $y_i$๊ฐ ์๋, ์ ์ฒด y๋ก ๋ํ๋ด์๋ฉด
$P(y|x;\theta)$ = $\prod_{i=1}^{m} h(x_i)^{y_i} (1-h(x_i))^{1-y_i}$ = likelihood of $\theta$ = $L(\theta)$
(๊ฐ data์ likelihood๋ฅผ ๋ชจ๋ ๊ณฑํ๋ค๋ ๋ถ๋ถ์์๋ ๊ฐ data์ ๋ ๋ฆฝ์ฑ์ด ์ ์ ๋จ)
โฃ maximing $L(\theta)$ - ๋ก๊ทธ ์ทจํ๊ธฐ
$L(\theta)$ = $\sum_{i=1}^{m} y_i log(\sigma(\theta^{T}\bar{x_i})) + ... + (1-y_i)log((1-\sigma(\theta^{T}\bar{x_i})))$
โค $\theta$์ ๋ํด ํธ๋ฏธ๋ถํ๊ธฐ
$\cfrac{\partial L(\theta)}{\partial \theta}$ = $\cfrac{y}{\sigma(\theta^{T}\bar{x_i})}$$\cfrac{\partial \sigma(\theta^{T}\bar{x_i})}{\partial \theta}$ + ... + $\cfrac{1 - y}{1 - \sigma(\theta^{T}\bar{x_i})}$$(-1)\cfrac{\partial \sigma(\theta^{T}\bar{x_i})}{\partial \theta}$
+ ์ฌ๊ธฐ์ ์ฐ๋ฆฌ๋ $\cfrac{\partial \sigma(\theta^{T}\bar{x_i})}{\partial \theta}$๋ฅผ ์๋์ ๊ฐ์ด ๋ถํดํ ์ ์๊ณ
$\cfrac{\partial \sigma(\theta^{T}\bar{x_i})}{\partial \theta}$ = $\cfrac{\partial \sigma(\theta^{T}\bar{x_i})}{\partial (\theta^T\bar{x})}$$\cfrac{\partial (\theta^T\bar{x})}{\partial \theta}$
+ ์ฝ๊ฒ ๋ฏธ๋ถ๋๋ sigmoid ์ฑ์ง์ ์ด์ฉํด ๋ค์ ํ์ด์ฐ๋ฉด
$\cfrac{\partial \sigma(\theta^{T}\bar{x_i})}{\partial (\theta^T\bar{x})}$$\cfrac{\partial (\theta^T\bar{x})}{\partial \theta}$ = $\sigma(\theta^{T}\bar{x_i})$$(1-\sigma(\theta^T\bar{x}))$$\bar{x}$
+ ํ์ด ์ด ์ ํญ์ ๋ณธ ์์ ๋์ ํ๋ฉด
$\cfrac{\partial L(\theta)}{\partial \theta}$ = $(y - \sigma(\theta^T\bar{x})\bar{x}$์ ์ต์ข ์ ์ผ๋ก ์ป๋๋ค.
โฅ GD(Gradient Descent) ๊ฐ๋ ์ ์ ์ฉํด $\theta$์ ๋์ ํ๋ฉด
$\theta^+$ = $\theta^{-}$ + $\alpha\cfrac{\partial L(\theta)}{\partial \theta}$
โฆ ์ ์ฃผ์ด์ง GD์์ ํตํด ์ต์ ์ $\theta$๋ฅผ ๊ตฌํ๋ฉด ๋๋ค.
โง ๊ตฌํ ์ต์ ์ $\theta$๋ก ๊ตฌ์ฑ๋ ์ต์ ์ logistic model - sigmoid function์ ๊ตฌํ๋ฉด ๋๋ค.
- ๋! -
๐๐ป ์ ์์ ์งํ๊ณผ์ ์ฒ๋ผ ์์ ํ ๋๊ฐ์ ๊ณผ์ ์ผ๋ก MLE ๊ธฐ๋ฒ์ normal distribution์๋ ์ ์ฉํ ์ ์๋ค. MLE ๊ธฐ๋ฒ์ ํตํด ์ฃผ์ด์ง x data์ ๊ฐ์ฅ ์ ๋ง๋ normal distribution์ ๋ชจ์ $\mu$์ $\sigma$๋ฅผ ์์๋ณด๋ ๊ณผ์ ์ ์ํ์ ์ผ๋ก ํ์ด๋ณด์. (์ถํ ํฌ์คํ )
* ์ธ๋ฌ ์ถ์ฒ) https://programmathically.com/maximum-likelihood-estimation/
* ์ถ์ฒ1) ์ต๋์ฐ๋๋ฒ ๊ฐ๋ ์ค๋ช https://www.youtube.com/watch?v=XhlfVtGb19c
* ์ถ์ฒ2) MLE ๊ธฐ๋ฒ ๋ฌธํ http://www.sherrytowers.com/mle_introduction.pdf
* ์ถ์ฒ3) using MLE - logistic regression https://www.youtube.com/watch?v=TM1lijyQnaI
* ์ถ์ฒ4) ๊ฐ STATQUEST - MLE w/ logistic regression https://www.youtube.com/watch?v=BfKanl1aSG0
* ์ถ์ฒ5) ๊ฐ STATQUEST - MLE explained https://www.youtube.com/watch?v=XepXtl9YKwc
'Statistics > Concepts(+codes)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
MLE for the normal distribution (0) | 2022.06.27 |
---|---|
Auto-correlation + Durbin-Watson test (0) | 2022.06.17 |
Bayesian Theorem (0) | 2022.05.07 |
distributionใpoisson distribution (ํฌ์์ก๋ถํฌ) (0) | 2022.05.06 |
distributionใbinomial distribution (์ดํญ๋ถํฌ) (0) | 2022.05.06 |
๋๊ธ