Regularization

A method to deal with

Overfitting

The model fits the training set too perfectly and therefore has poor performance on unknown data.

Possible causes:

  • The chosen model is much more complex than the relationship between independent and dependent variables. Thus the model tries to learn to fit for example random fluctuations of an originally mostly linear dataset.
    • Fitting a high order polynomial to linear data
  • The training set and the validation set / real-world data come from a different distribution (for instance too much time passed since the collection of the training data)
    • You can use Adversarial Validation to test whether you can easily distinguish between training and test data

.

Intuition: Penalize high values of model parameters θj\theta_j, to get a "simpler model"

Add a regularization term λ∑i=1nθj2\lambda \sum_{i=1}^{n} \theta_j^2 to the cost function

New cost function will be:

J(θ)=12m[∑i=1m(hθ(x(i))−y(i))2+λ∑i=1nθj2]J(\theta) = \frac{1}{2m} [ \sum_{i=1}^{m}(h_\theta(x^{(i)}) - y^{(i)})^{2} + \lambda \sum_{i=1}^{n} \theta_j^2 ]

  • λ\lambda is the regularization parameter
    • Too high value will result in underfitting, since it will just eliminate all featurs and try to fit to a horizontal line.

Note: θ0\theta_0 is not penalized traditionally but even if it were it would not make much of a difference