Implementing L2 regularization

Now that we have seen how overfitting occurs on our dataset, we will explore the impact of L2 regularization in reducing overfitting on the dataset.

L2 regularization on a dataset can be defined as follows:

Note that the loss function is the traditional loss function where y is the dependent variable, x is the independent variables, and W is the kernel (weight matrices).

The regularization term is added to the loss function. Note the regularization value is the sum of squared weight values across all the dimensions of a weight matrix. Given that we are minimizing the sum of squared value of weights along with ...

Get Hands-On Machine Learning on Google Cloud Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.