Data Science/Machine Learning

[Coursera Stanford Machine Learning (week3) ]Classification and Representation

sunnyshiny 2023. 2. 6. 12:47
728x90

해당 내용은 coursera Andrew Ng교수의 Machine Learning강의노트정리

Classification

email이 스팸메일인지 아닌지 종양이 악성인지 양성인지 등의 분류문제에서 linear regression 이 아닌 logistic regression을 이용하여 해결해야 한다

$y \in \begin {Bmatrix}0, 1\end {Bmatrix}$ 0: negative class, 1: positive class

$\because h_{\theta}>1 \quad or \quad h_{\theta} <0$ 만일 linear regression을 적용하면 hypothesis는 1보다 크고 0보다 작은 값을 가질수 있게 되며 이것은 output과 다른 결과를 갖는다.

Hypothesis Representation

분류문제는 $y \in \begin{Bmatrix}0, 1\end {Bmatrix}$ 인 discrete value를 갖기 때문에 기존의 선형회귀를 통해 예측하는 것은 적절하지 못한다 → logistic regression 사용

Logistic Regression : $0 \le h_{\theta} \le 1$

$$ h_{\theta}(x) = g(\theta^Tx)\\z =\theta^Tx\\g(z)=\frac{1}{1+e^{-z}} $$

sigmoid function , Logistic function → $g(z)=\frac{1}{1+e^{-z}}$

$h_{\theta}(x)$ = 입력 변수 $x$가 $y=1$일 확률로 종양환자의 예에서 $y=1$이 악성종양일 때 $h_{\theta}(x)=0.7$이라면 해당환자가 악성종양일 확률은 70%가 된다.

$$ h_{\theta}(x) = P(y=1| x;\theta) =1-P(y=0| x;\theta)\\ P(y=1| x;\theta) + P(y=0| x;\theta)=1 $$

Decision Boundary

Logistic Regression

$h_{\theta}(x) = g(\theta^Tx)\\g(z) = \frac {1}{1+e^{-z}}$

$y=1$ : if $g(z)\ge 0.5 \quad when \ z \ge 0 \quad \rightarrow h_{\theta}(x)= g(\theta^Tx) \ge 0.5 \quad when \ \theta ^Tx \ge 0$

$y=0$ : if $g(z)< 0.5 \ when \ z < 0 \quad \rightarrow h_{\theta}(x)= g(\theta^Tx) < 0.5 \quad when\ \theta^Tx <0$

예를 들어 위와 같이 데이터가 주어졌을 때 $\theta_0 =-3,\ \theta_1 =1,\ \theta_2 =1$이라고 할 때 decision boundary는 $x_1+x_2 = 3$이 된다. 만일 $x_1 +x_2 \ge3$이면 $y=1$로 예측하고 $x_1 +x_2 <3$이면 $y=0$으로 예측하게 된다.

좀 더 복잡한 decision boundary , 2차 항이 있는 decision boundary를 살펴보면 $\theta_0 =-1,\ \theta_1 =0,\ \theta_2 =0,\ \theta_3 =1,\ \theta_4 =1$ 라고 할 때 해당 데이터의 decision boundary는 $x_1^2+x_2^2=1$이 된다. 만일 $x_1^2+x_2^2 <1$이면 $y=0$이고 $x_1^2+x_2^2\ge1$이면 $y=1$로 예측된다.

 

Refrenece
Machine learning , Coursera, Andrew Ng 

728x90