본문 바로가기
스터디/인공지능, 딥러닝, 머신러닝

[Bayesian] Linear Modeling Settings (선형 회귀 모델링, MLE, Least Square, MAP, Ridge)

by 궁금한 준이 2023. 9. 17.
728x90
반응형

 

 

Notation

우리가 관측한(얻은) $n$개의 데이터셋을 $\mathcal{D}$이라 하자. 각 데이터 표본(인스턴스)는 $d$차원 변수이고, label은 상수(스칼라) 이다. 이를 수식으로 표현하면 다음과 같다.

\[ \mathcal{D} = (X, y), \quad X=[x_1, \dots, x_n]^\top \in \mathbb{R}^{n \times d}, \quad y=[y_1, \dots, y_n]^\top \in \mathbb{R}^{n} \]

$X$의 $i$번째 표본은 $X_i = (x_i, y_i)$이고 $x_i$는 $d$차원 벡터이고 $y$는 스칼라이다. ($x_i \in \mathbb{R}^d$)

Dataset

그리고 더 basis function(기저 함수, 혹은 feature map으로도 불린다)을 도입하여 선형식을 확장할 수 있다. 

기저함수는 $d$차원을 $h$차원으로 매핑한다. 즉 $\phi: \mathbb{R}^d \to \mathbb{R}^h$

 

기저함수의 대표적인 예로 polynomial basis function이 있다. $\phi_i(x): x_i^i$

※ 이때 $x$에 대하여 비선형이지만, 파라미터($w$, 여기서는 $\theta$)는 여전히 선형이므로 선형모델이다.

 

기저함수를 사용하여 선형식은 다음과 같다.

\[ f(x;\theta) = \theta^\top \phi(x) \]

이때 $\theta \in \mathbb{R}^h$ 이다.

$\Phi = [\phi(x_1), \dots, \phi(x_n)]^\top \in \mathbb{R}^{n \times h}$ 을 design matrix이라 한다. 

Dataset with Design Matrix

반응형

Least Square & Maximum Likelihood 

least square를 이용하여 $\theta$를 구한 파라미터를 $\theta_{\text{LS}}$라 하자.

\begin{align} \theta_{\text{LS}} &= \underset{\theta}{\mathrm{argmin}} \| y - \Phi \theta \|^2 \\ &= (\Phi^\top \Phi)^{-1}\Phi^\top y \end{align}

 

Probabilistic interpretation of least square

observed label($y$)는 선형 예측 $\theta^\top \phi(x)$로 얻어지고 분산이 $\sigma^2$인 noise를 포함한 분포를 따른다.

\[ p(y_i|x_i; \theta) = \mathcal{N}(y_i | \theta^\top \phi(x_i), \sigma^2) \ i = 1, \dots, n \]

 

maximum likelihood를 이용하여 구한 파라미터를 $\theta_{\text{ML}}$라 하면

\[ \theta_{\text{ML}} = \underset{\theta}{\mathrm{argmax}} \log p(y|X; \theta) \]

이때 $\theta_{\text{LS}} = \theta_{\text{ML}}$ 이다. (증명 생략)

 

Ridge regression & Maximum A Posteriori

$\theta$를 구할 때 $(\Phi^\top \Phi)^{-1}$를 구해야한다. 근데 ill-condition이면(e.g. $n \ll h$) 역행렬을 구하기가 매우 불안정하다(unstable). 

$(\Phi^\top \Phi)^{-1}$의 고유벡터를 빠르게 구하기 위해 $\lambda$를 더하여 파라미터를 구한다. ($\lambda>0$이고 작은 값이다.) 이렇게 regularized least square의 해를 ridge regression이라 한다.

 

\begin{align} \theta_{\text{Ridge}} &= (\Phi^\top \Phi + \lambda I_h)^{-1} \Phi^\top y \\ &= \underset{\theta}{\text{argmin}} \| y-\Phi \theta \|^2 + \lambda \| \theta \|^2  \end{align}

 

Probabilistic interpretation of ridge regression

observed label($y$)는 동일한 확률로 해석할 수 있지만, $\theta$는 random(분포)으로 가정된다.

\begin{align} p(y|x, \theta) &= \mathcal{N}(y|\theta^\top \phi(x), \sigma^2) \\ p(\theta) &= \mathcal{N}(\theta|0, (\sigma^2 / \lambda)I_h) \end{align}

 

$\theta$를 MAP를 이용한 점추정(point estimator)을 $\theta_{\text{MAP}}$라 하면 다음과 같다.

\[ \theta_{\text{MAP}} = \underset{\theta}{\text{argmax}} \log p(y|X, \theta) + \log p(\theta) \]

 

이때 $\theta_{\text{Ridge}} = \theta_{\text{MAP}}$ 이다. (증명 생략)

728x90
반응형