Regularization

‍이세현·2024년 3월 26일
1

The problem of Overfitting

Overfitting: feature가 지나치게 많은 경우 가설은 J(θ)J(\theta)가 0에 가까워지도록 학습되지만 일반화하지는 못할 것이다.
train data는 잘 나타내지만 test data를 대응하지는 못할 것이다.

새로운 data, 다른 변인에 대해 대응하지 못한다면 overfitting이라고 본다.

Addressing overfitting

  1. Features 수를 줄인다.
    • 유지할 features를 직접 선택한다.
    • Model selection algorithm
  2. Regularization
    • 모든 features를 유지하고 parameters θj\theta_j 값의 크기를 줄인다.
    • Features가 많고 각 features가 y를 예측할 때 조금씩 기여하는 경우 잘 작동한다.

Cost function

Intuition

min12mi=1m(hθ(x(i))y(i))2+1000θ32+1000θ42\text{min}\frac{1}{2m}\sum_{i=1}^{m}(h_\theta(x^{(i)})-y^{(i)})^2 + 1000{\theta_3}^2 + 1000{\theta_4}^2
θ3\theta_3θ4\theta_4는 0에 가깝게 수렴할 것이다.

Regularization

  • parameter θ0,θ1,...,θn\theta_0, \theta_1, ..., \theta_n이 작은 경우 보다 단순한 가설이 되며 과적합에 취약할 가능성이 작아진다.

  • J(θ)=12mi=1m(hθ(x(i))y(i))2+λi=1mθj2J(\theta) = \frac{1}{2m}\sum_{i=1}^{m}(h_\theta(x^{(i)})-y^{(i)})^2 + \lambda\sum_{i=1}^{m}{\theta_j}^2
    λ\lambda는 얼마나 규제할 것인지 정하는 regularization parameter이다.

  • λ\lambda 값은 문제에 따라 그 크기가 달라진다.

  • θ\theta에 대한 정규화식 λi=1mθj2\lambda\sum_{i=1}^{m}{\theta_j}^2은 앞의 cost function과 독립적이다.

  • 정규화를 진행하면 accuracy는 저하될 수 있으나 test accuracy는 향상된다.

  • Linear regression, Logistic regression에서 regularization을 사용하면 모델의 복잡도가 조금씩 낮아지고 overfitting 문제를 해결할 수 있다.

Regulaized linear regression에서 λ\lambda가 매우 큰 경우

θ\theta가 모두 0으로 수렴하여 y 절편(yy)만 유의미해진다.

underfitting: 학습이 제대로 이루어지지 않음

Regularized linear regression

Gradient descent

θj:=θj(1αλm)α1mi=1m(hθ(x(i))y(i))xj(i)\theta_j := \theta_j(1-\alpha\frac{\lambda}{m}) - \alpha\frac{1}{m} \sum_{i=1}^{m}(h_\theta(x^{(i)})-y^{(i)}){x_j}^{(i)}

θj\theta_j가 조금씩 작아진다. - parameter가 작아진다.
이때 θ0\theta_0은 복잡도에 영향을 주지 않으므로 정규화하지 않는다.

Regularized logistic regression

Cost function

  • J(θ)=1mi=1m[y(i)loghθ(x(i))+(1y(i))log(1hθ(x(i)))]+λ2mj=1mθj2J(\theta)=-\frac{1}{m}\sum_{i=1}^{m}[y^{(i)}\text{log}h_\theta(x^{(i)})+(1-y^{(i)})\text{log}(1-h_\theta(x^{(i)}))] + \frac{\lambda}{2m}\sum_{j=1}^{m}{\theta_j}^2
profile
Hi, there 👋

0개의 댓글

관련 채용 정보