$$
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
\newcommand{\ceil}[1]{\left\lceil #1 \right\rceil}
\newcommand{\N}{\mathbb{N}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\C}{\mathbb{C}}
\renewcommand{\L}{\mathcal{L}}
\newcommand{\x}{\times}
\newcommand{\contra}{\scalebox{1.5}{$\lightning$}}
\newcommand{\inner}[2]{\left\langle #1 , #2 \right\rangle}
\newcommand{\st}{\text{ such that }}
\newcommand{\for}{\text{ for }}
\newcommand{\Setcond}[2]{ \left\{\, #1 \mid #2 \, \right\}}
\newcommand{\setcond}[2]{\Setcond{#1}{#2}}
\newcommand{\seq}[1]{ \left\langle #1 \right\rangle}
\newcommand{\Set}[1]{ \left\{ #1 \right\}}
\newcommand{\set}[1]{ \set{#1} }
\newcommand{\sgn}{\text{sign}}
\newcommand{\halfline}{\vspace{0.5em}}
\newcommand{\diag}{\text{diag}}
\newcommand{\legn}[2]{\left(\frac{#1}{#2}\right)}
\newcommand{\ord}{\text{ord}}
\newcommand{\di}{\mathrel{|}}
\newcommand{\gen}[1]
\newcommand{\irr}{\mathrm{irr }}
\renewcommand{\deg}{\mathrm{deg }}
\newcommand{\nsgeq}{\trianglelefteq}
\newcommand{\nsg}{\triangleleft}
\newcommand{\argmin}{\mathrm{argmin}}
\newcommand{\argmax}{\mathrm{argmax}}
\newcommand{\minimize}{\mathrm{minimize}}
\newcommand{\maximize}{\mathrm{maximize}}
\newcommand{\subto}{\mathrm{subject\ to}}
\newcommand{\DKL}[2]{D_{\mathrm{KL}}\left(#1 \di\di #2\right)}
\newcommand{\ReLU}{\mathrm{ReLU}}
\newcommand{\E}{\mathsf{E}}
\newcommand{\V}{\mathsf{Var}}
\newcommand{\Corr}{\mathsf{Corr}}
\newcommand{\Cov}{\mathsf{Cov}}
\newcommand{\covariance}[1]{\Cov\left(#1\right)}
\newcommand{\variance}[1]{\V\left[#1\right]}
\newcommand{\variancewith}[1]{\V\left[#1\right]}
\newcommand{\expect}[1]{\E\left[#1\right]}
\newcommand{\expectwith}[2]{\E_{#1}\left[#2\right]}
\renewcommand{\P}{\mathsf{P}}
\newcommand{\uniform}[2]{\mathrm{Uniform}\left(#1 \dots #2\right)}
\newcommand{\gdist}[2]{\mathcal{N}\left(#1, #2\right)}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
$$
\everymath{\displaystyle}
Back to : ml-study
Contents
Classification
- Binary ํ๊ฒ (๋๋ Discreteํ๊ฒ) ๋ญ๊ฐ๋ฅผ ๊ฒฐ์ ํ๋ ํํ์ ๋ฌธ์ .
- ex) ์ข
์์ ์์ฑ/์์ฑ, ๋ฉ์ผ์ด ์คํธ์ด๋ค/์๋๋ค ๋ฑ๋ฑโฆ
- Idea : Linear Regression + Threshold. Linearํ๊ฒ hypothesis๋ฅผ ์ก๊ณ , ์ด๋ค ๊ฐ (0.5) ์ด์์ด๋ฉด 1๋ก ์์ธกํ๋ ํํ.
- ํ๊ณ์ : ์๋ฅผ ๋ค์ด, ์์ฑ ๋ฐ์ดํฐ๊ฐ (3, 4, 5, 100) ์ด๊ณ ์์ฑ ๋ฐ์ดํฐ๊ฐ (1, 2, 2) ์ด๋ฉด? Linear hypothesis๊ฐ ๋ณ๋ก ์ ์ ํ์ง ์์ ๊ฒฝ์ฐ๊ฐ ๋ง๋ค. 100์ ์ํด threshold๊ฐ ์ง๋์น๊ฒ ์ค๋ฅธ์ชฝ์ผ๋ก ์ด๋ํ๊ฒ ๋๊ธฐ ๋๋ฌธ.
- ๊ฐ์ : ์ ๋ฌธ์ ์ ์
Linear
๋๋ฌธ์ ์๊ธฐ๋ ๋ฌธ์ ๋ค. Linear
๋ณด๋ค ๋ ์ด๋ฐ ํํ์ ์ ํฉํ๊ฒ ์๊ธด ํจ์๋ฅผ ์ฐ๋ฉด ์ด๋จ๊น? $h$ ํจ์์ ์ต์์ ์ต๋๋ ๋ญ๊ฐ 0๊ณผ 1๋ก ๊ณ ์ ํ๊ณ ์ถ๋ค. $h_\theta(x)$ ๊ฐ 1๋ณด๋ค ํฌ๊ฑฐ๋ 0๋ณด๋ค ์์ ๊ฒ์ ๋ญ๊ฐ ๋ฐ๋์งํ์ง ์์ ์ํ์ธ๊ฒ์ผ๋ก ๋ณด์ธ๋ค.
- Logistic regression : ๋ค์๊ณผ ๊ฐ์ ํํ์ sigmoid ํจ์๋ฅผ ์ฌ์ฉํ๋ค.
\(h_\theta(x) = \frac{1}{1 + e^{-\theta^T x}}\)
- Why? ๊ทธ๋ํ๊ฐ ๋งค์ฐ ์ ์ฉํ ์ฑ์ง๋ค์ ๋ณด์ด๊ธฐ ๋๋ฌธ.
- Interpretation : $h_\theta(x)$ = $y = 1$์ผ ํ๋ฅ ์ ๋๋ ค์ค๋ค๊ณ ์๊ฐํ์.
\(h_\theta(x) = \mathsf{P}(y = 1 \ |\ x ; \theta)\)
Multiple Features
- $\theta$ ์ $x$๋ฅผ ๋ฒกํฐ๋ก ์๊ฐํ๋ ์์์ ๋ฐฉ๋ฒ์ ๊ทธ๋๋ก ์ด์ฉํ๋ฉด, Logistic regression๋ ๋๊ฐ์ด multiple feature์ ์ ์ฉ ๊ฐ๋ฅ.
- ์ด๋๋, $h_\theta(x) = 0.5$ ์ธ ๊ฒฝ๊ณ๋ฉด์ด $\R^n$ ์์ ์ดํ๋ฉด์ผ๋ก ์ ๊ณตํ๋ ํํ๊ฐ ๋๋ค.
- ์ด๋ฅผ Decision boundary ๋ผ๊ณ ๋ถ๋ฅธ๋ค.
- Logistic regression๋ ๋ค์๊ณผ ๊ฐ์ ํํ๋ก ์ผ๋ฐํํ ์ ์๋ค.
- $h_\theta(x) = g(p(\theta, x))$, such that $g(z) = \frac{1}{1 + e^{-z}}$ ๋ก ์ธ ์ ์๊ณ ,
- $p$์๋ ๋ค์ํ ํจ์๋ค์ด ๋ค์ด๊ฐ ์ ์๋ค. ์๋ฅผ ๋ค์ด, $p(\theta, x) = \theta_0 + \theta_1 x_1^2 + \theta_2 x_2^2$ ๊ฐ์ ๋คํญ์โฆ
- ์ด๊ฒฝ์ฐ, Decision boundary๊ฐ ์์ด๋ ํ์, ๋๋ ๋ค๋ฅธ ํํ๋ก ๋ํ๋๋ ๋ฌธ์ ๋ค๋ ํด๊ฒฐ ๊ฐ๋ฅํ๋ค.
Logistic Regression
- Cost function ๊ณผ ๊ทธ ํธ๋ํจ์๋ค์ ์๋ค๋ฉด, gradient descent๋ฅผ ์ธ ์ ์๋ค. $h$๋ ์ด๋ฏธ ์ ํ์ผ๋ฏ๋กโฆ
- Linear regression์์์ฒ๋ผ, $\frac{1}{2m}\sum_{i = 1}^{m} \ (h_\theta(x_i) - y_i)^2$ ๋ฅผ ์ด๋ค๋ฉด, ์ด ํจ์๋ Convexํ์ง ์๋ค.
-
Convexํ์ง ์์ผ๋ฉด Gradient Descent์ ์๋ ด์ฑ์ด ๋ณด์ฅ๋์ง ์๋๋ค!
- ๊ฐ๋ฅํ๋ฉด Convexํ ํจ์๋ฅผ ์ก์์ ์จ์ผ ํ๋ค. ๋ค์ ํจ์๊ฐ ์ ์๋ํจ์ด ์๋ ค์ ธ ์๋ค.
\(Cost_\theta(x, y) = \begin{cases}
-\log(h_\theta(x)) & \text{if } y = 1 \\
-\log(1 - h_\theta(x)) & \text{if } y = 0
\end{cases}\)
- $y = 1, h_\theta(x) = 1$ ์ด๋ผ๋ฉด, cost๊ฐ 0์ด๋ค. ์ด๋ ์ฌ๋ฐ๋ฅธ ์์ธก์์ cost ํจ์๊ฐ 0์ด ๋๋ค๋ ๊ฒ์ด๋ฏ๋ก, desirableํ๋ค.
- $y = 1, h_\theta(x) \to 0$ ์ผ ๋, cost๊ฐ ๋ฌดํ๋๋ก ๋ฐ์ฐํ๋ค. ์ด๋, 1์ด์ด์ผ ํ ๊ฐ์ 0์ผ๋ก ์์ธกํ๋ฉด ํฐ penalty term์ ์ฃผ๊ฒ ๋ค๋ ์๋ฏธ๊ฐ ๋๋ค. ์ด๋ฌํ intuition์ ์ฐ๋ฆฌ๊ฐ logistic regression์์ ์ํ๋ ๋ฐ์ ์ ๋ง์๋จ์ด์ง๋ค. $y = 0$์์๋ ์ ๋ ๊ฐ์ง๊ฐ ๋ง์ฐฌ๊ฐ์ง๋ก ์ฑ๋ฆฝํ๋ค.
- ์ ์์ ๊ฒฝ์ฐ๋ก ๋๋์ด์ ธ ์์ด์ ๋ณต์กํ๋ค (ํนํ Grad-descent ์ฐ๊ธฐ์). ์ด๋ฅผ ์ ์ ๋ฆฌํด์โฆ
\(Cost_\theta(x, y) = -y\log(h_\theta(x)) - (1-y)\log(1 - h_\theta(x))\)
- ์ด์ , Gradient descent๋ฅผ ์ธ ์ ์๋ค! $(x_i, y_i)$ ๊ฐ training set์ด๋ผ๊ณ ํ๋ฉด..
\(J(\theta) = -\frac{1}{m}\left(\sum_{i = 1}^{m} y_i\log(h_\theta(x_i)) + (1-y_i)\log(1 - h_\theta(x_i))\right)\)
\(\pdv{}{x_j}J(\theta) = \sum_{i = 1}^{m} (h_\theta(x_i) - y_i) x_j\)
- Linear regression ๋์ gradient descent์ ๋๊ฐ์ ํํ์ ํธ๋ํจ์๋ฅผ ์ป๋๋ค.
Advanced Optimization Ideas
- Optimization Algorithm์ ๋ค์ํ๋ค. ๋ ๊ฐํ ์๊ณ ๋ฆฌ์ฆ๋ค์ด ์๋ค.
- Gradient Descent
- Conjuagte Gradient
- BFGS algorithm, L-BFGS algorithm
- ์ฃผ๋ก Gradient Descent๋ณด๋ค ๋น ๋ฅด๊ณ , $\alpha$๋ฅผ ์ง์ ๊ณ ๋ฅด์ง ์์๋ ๋๋ (Line Search) ๊ณ ๊ธ ์๊ณ ๋ฆฌ์ฆ๋ค. ๋์ฒด๋ก ํจ์ฌ ๋ณต์กํ์ง๋ง ๋ ์ข์ ์ฑ๋ฅ์ ๋ณด์ธ๋ค.
Multiclass Classification
- 0/1์ด ์๋, ์ฌ๋ฌ ๊ฐ ์ค ํ๋๋ฅผ ๊ณ ๋ฅด๋ ํํ์ Classification
- ex) Email Classification : Work / Friends / Family / Hobby๋ฅผ 0 / 1 / 2 / 3 ์ผ๋ก.
- One-vs-All : ๋ฌธ์ ๋ฅผ one-vs-all ํํ์ binary classification์ผ๋ก ๋ฐ๊พธ์ด, classifier $h_\theta$๋ฅผ ๊ฐ๊ฐ ๋ง์ถ๋ค.
- ๊ฐ๊ฐ์ ํด๋์ค์ ๋ํ best $h$๋ฅผ ํ์ตํ ํ, ์๋ก์ด ๋ฐ์ดํฐ์ ๋ํด์๋ ๋ชจ๋ $h$๋ค์ ๋๋ ค๋ณด๊ณ ํ๋ฅ ์ด ๊ฐ์ฅ ๋๊ฒ ๋์ค๋ ํด๋์ค๋ก ํ์ ํ๋ค.
- ๊ฐ์ฅ ์์ฐ์ค๋ฌ์ด? ํํ์ extension.
Back to : ml-study