Week 03: Regularization and Quiz


1. The problem of overfitting

첫 번째 그림의 모델의 상태를 underfitting이라고 하고 high bias인 상태라고 한다.

세 번째를 overfitting 이라고 부르며 high variance로도 알려져 있다.
이것은 high oder polynomial (고차 다항식)을 이용한 것으로 트레이닝 data에 거의 완벽히 fit 시키게 된다.
당연히 hypothesis의 space는 많은 공간을 차지하게 된다.

Overffting을 간단히 요약하면,
엄청나게 많은 feature들을 이용해서 학습하게 된다 그러면 cost function은 거의 zero에 다가서게 하는
함수를 만들 수 있다.

Addressing overfitting:

  1. Reduce number of features.
    1. Manually select which features to keep
    2. Model selection algorithm (later in course)
  2. Regularization
    1. Keep all features, but reduce magnitude of parameters θ
    2. Works well when we have a lot of features, each of which contributes a bit to predicting y

2. Cost Function

고차 다항식의 경우 좀더 구불 구블한 선을 만들어서
Training data에 더 fit한 모델을 생성 할 수 있다.

Regularization의 기본적인 아이디어는

$\theta_n$에 엄청나게 큰 값을 줘서 패널티를 주는 것이다.
그렇게 하면 min function에 의해서 $\theta_n$값은 결국 0에 가까워 질 수 밖에 없는 것이다.

결국 이것을 수식으로 나타내면 아래와 같다.

$$ J(\theta )=\frac { 1 }{ 2m } \left[ \sum { i=1 }^{ m }{ (h{ \theta }(x^{ (i) })-y^{ (i) })^{ 2 }+\lambda \sum _{ j=1 }^{ n }{ \theta _{ j }^{ 2 } } } \right] $$

그냥 convention에 의해서 \theta_0부터 시작하지 않고 \theta_1부터 시작 하는 것이다.
위에서 \lambda는 Regularization의 rate이 된다.

3. Regularized Linear Regression

  • Previously, we looked at two algorithms for linear regression
    • Gradient descent
    • Normal equation
  • Our linear regression with regularization is shown below

Regularization with the normal equation

  • Normal equation is the other linear regression model
    • Minimize the J(θ) using the normal equation
    • To use regularization we add a term (+ λ [n+1 x n+1]) to the equation
      • [n+1 x n+1] is the n+1 identity matrix

4. Regularized Logistic Regression

logistic regression은 feature의 수가 늘어나면, overffting 되는 경향이 존재한다.

Logistic regression cost function은 다음과 같다.

이것에 아래의 추가 term을 더해서 regularization을 한다.

함수는 아래와 같다.



퀴즈 문제는 아래와 같다.


Quize week03_Regularization.pdf



+ Recent posts