Untitled

Overfitting을 해결하기 위한 방법

  1. Feature을 줄인다

    1. feature 중 일부를 실험자가 임의로 중요도를 따져서 선택하는 방법
    2. feature 중 일부를 model selection alogrithim을 이용해 선택하는 방법
  2. Dataset을 늘린다

  3. Regularization

    Feature는 모두 사용하되, feature가 모델에 미치는 영향을 줄인다(reduce the magnitude of theta)

    괜찮은 feature가 많을 때 사용

Regularization

$$ J(\theta_1,...\theta_n) =\frac{1}{2m}[\Sigma(h_\theta(x_i)-y_i)^2 + \lambda\Sigma\theta_j^2] $$

위의 새로운 costfunction을 이용 각 theta값(1부터 시작)을 최대한 작게 만드는 cost function을 만듬

$\lambda$는 regularization parameter(정규화 상수)라고 하고, 이 값에 따라 regularization 정도를 조정한다.

이 값이 너무 크면, undefitting이 발생할 수도 있기 때문에 유의해야한다.

Gradient descent of regularization

$$ \theta_i := \theta_i -\alpha\frac{\delta}{\delta\theta_i}J(\theta_0,...\theta_n)\\= \theta_i -\alpha(\frac{1}{m}\Sigma(h_\theta(x_i)-y_i)x^{(i)} + \frac{\lambda}{m}\theta_j )\\=\theta_i(1-\alpha\frac{\lambda}{m}) -\alpha(\frac{1}{m}\Sigma(h_\theta(x_i)-y_i)x^{(i)}) $$

위의 식처럼 유도가 된다. 이때 $1-\alpha\frac{\lambda}{m}$이 1보다 작은 값임을 알 수 있고, 결국 $\theta$의 값을 지속적으로 줄이는 식임을 확인 가능하다

!! 중요: regularized $\theta$의 범위(j)가 1부터임을 잊지말자, j=0일때는 0이다!!