[ML] Linear Regression

김선형·2025년 9월 19일

ML

목록 보기
5/6

Linear Regression

Input Feature와 연속형 출력값 사이의 관계를 설명하는 선형 방정식을 찾는 알고리즘
Input Feature Vector x=(x1,x2,,xn)\mathbf{x}=\left(x_1,x_2,\dots,x_n\right)에 대응되는 결과값 yy가 있을 때, yy를 가능한 한 잘 맞출 수 있는 선형 방정식을 찾는다.

y^=w1x1+w2x2++wnxn=wTx\hat{y}=w_1x_1+w_2x_2+\cdots+w_nx_n=\mathbf{w}^T\mathbf{x}

y^\hat{y}yy와 비슷할수록 좋은 선형 회귀 모델이다.
주어진 데이터를 선형 관계로 완벽하게 표현하는 것이 어렵기 때문에, 일반적으로 bias를 식에 추가해 사용한다.

y^=w0+w1x1+w2x2++wnxn=wTx\hat{y}=w_0+w_1x_1+w_2x_2+\cdots+w_nx_n=\mathbf{w}^T\mathbf{x}

Cost Function

J(w)=MSE(w)=1ni=1n12(y^(i)y(i))2J\left(\mathbf{w}\right)=\text{MSE}\left(\mathbf{w}\right)=\frac{1}{n} \sum_{i=1 }^n {\frac{1}{2}\left(\hat{y}^{(i)}-y^{(i)}\right)^2}

학습

Gradient Descent를 통해 J(w)J\left(\mathbf{w}\right)의 값이 최소가 되도록 하는 w\mathbf{w}의 최적치를 구한다.

J(w)=1ni=1n12(y^(i)y(i))2Δw=1ni=1n(y(i)+y^(i))x(i)w:=w+η1ni=1n(y(i)y^(i))x(i)\begin{aligned} J\left(\mathbf{w}\right)=\frac{1}{n} \sum_{i=1 }^n {\frac{1}{2}\left(\hat{y}^{(i)}-y^{(i)}\right)^2} &\\ &\Rightarrow \Delta \mathbf{w}=\frac{1}{n} \sum_{i=1 }^n {\left(-y^{(i)}+\hat{y}^{(i)}\right)\mathbf{x}^{(i)}} \\ &\Rightarrow \mathbf{w} := \mathbf{w}+\eta \frac{1}{n} \sum_{i=1 }^n {\left(y^{(i)}-\hat{y}^{(i)}\right)\mathbf{x}^{(i)}} \end{aligned}

예측

학습을 통해 가중치 벡터 w\mathbf{w}를 찾게 되면, 새로운 입력 벡터 x\mathbf{x}'에 대한 결과 예측값 yy'은 다음과 같다.

y=wTxy'=\mathbf{w}^T\mathbf{x}'
profile
선형의 비선형적 기록 🐜

0개의 댓글