무냐의 개발일지

[Coursera ML Specialization] C1 지도, 비지도학습 / Week3 본문

Coursera

[Coursera ML Specialization] C1 지도, 비지도학습 / Week3

무냐코드 2024. 2. 8. 23:38

| Classification (분류, Supervised Learning의 또 다른 타입)

: Linear Regression이 적절하지 않은 데이터 타입에 사용한다

: Use Classification where your output variable y can take on only one of a small handful of possible values instead of any number in an infinite range of numbers.  (ex. Binary classification 같은 Yes or No 문제)

  - negative class (false, 0)

  - positive class (true, 1)

 

 

>> Classification 문제는 linear regression이 아니라, threshold를 만들어서 그 이하면 0, 이상이면 1 이라고 간주하는 식이다

 

 

 

| Logistic Regression

: machine learning에서 매우 인기있는  classification algorithm

: output value of the outcome will always be between 0 and 1

 

매우 많은 인터넷 광고들이 Logistic Regression 을 조금 변형한 알고리즘으로 구성되어 있다.

 

 

| Decision Boundary

how logistic regressions are computing predictions

Non-Linear decision boundaries

 

 

 

| Cost Function

measures how well you're doing on the training set , and better parameter를 고를 수 있게 해준다. Logistic Regression에서는 Linear Regression에서 사용했던 거랑 다른 걸 사용한다

 

logistic regression에서는 오른쪽처럼 울퉁불퉁해지니까, 다른 모델이 낫다

 

| Logistic Loss Function

measures how well you're doing on one training example by summing up the losses on all of the training examples 

 

y=1

 

y=0

 

 

| Gradient descent for Logistic Regression

to fit the parameters of logistic regression,  cost fucntion J 를 minimize 하는 w, b를 찾는다

 

 

w랑 b를 동시에 계속 업데이트한다.

 

Linear Regression 이랑 똑같아 보인다. 하지만 Linear Regression과 Logistic Regression에서 f의 식이 다르다.

 

이런 식으로 다르다!

 

 


| Overfitting, Underfitting

지금까지 Supervised Learning 의 Learning algorithms (Regression, Classification) 를 알아보았다.

 

문제 : Overfitting, Underfitting 을 regularization을 통해 해결한다

- Overfitting (high bias) : when the model does not fit the training set well (학습 데이터가 충분하지 못해서, 예측을 제대로 해내지 못할때)

- Normal (generalization) : 잘 모델링 된 것. 새로운 데이터 예측을 적당히 잘 수행한다.

- Underfitting (high variance) : 너무 모든 데이터를 fit해내는 것 (predict 기존 데이터 toooo well, 새로운 데이터는 예측 잘 못함)

 

Regression

 

 

Classification

 

| Solutions for Overfitting 

1) Collect more data (training examples) : 고려할 수 있는 데이터가 많을수록 학습이 더 부드러워 질거다

2) Select Fewer features 

- 많은 Feature + 불충분한 데이터 => overfit

- selected Feature(가장 relevant한 것들만) + 데이터 => 적당하다

단, 중요한 feature를 버려버릴 수 있기 때문에 주의해야 한다.

 

3) Regularization : reduce the size of parameters wj (이게 우리가 배웠던 내용)

- gently reduce 덜 중요한 feature의 비중을 줄여줄 수 있다

 

 

feature가 너무 많으면, 뭐가 큰 영향을 미치는지 잘 안 보인다. 

-> 모든 변수 w에 penalize해서 영향을 다 조금씩 줄여준다.

(learning rate 구해줬던 것처럼, 람다 숫자도 정해주도록 한다.)

 

      1) mean squared error (fit data하는 역할) 2) regularization term (wj를 작게 하려는 역할)

위 수식이자 cost function인 J를 최소화하는 게 우리의 목표!

 

* 람다 = 0 : overfitting된다

* 람다 = 10의 10승 : regularizatoin term이 너무 커지니까, 모든 feature 가 너무 작아질거다. 수식의 상수랑 같아질거다.

(underfitting된다) (Increasing the regularization parameter  reduces overfitting by reducing the size of the parameters.)

* 람다가 적당한 수여야만, 적당히 fitting된다.

 

| Regularized Linear Regression

변수들을 동시에 업데이트 해준다

| Regularized Logistic Regression

뒤에 식을 하나 더해주면서 wj에 penalize 하는 효과가 된다

 

Cost Function 의 값을 줄여주기 위해 Gradient descent를 동시에 수행해주면서 값을 업데이트해준다.