Implementing L1 regularization

L1 regularization works in a similar way as that of L2; however, the cost function for L1 regularization is different than L2 regularization, as follows:

Note that, in the preceding equation, all the terms remain the same; just the regularization term is the summation of absolute values of weights than squared values of weights.

Let's implement the L1 regularization in code; now we see the corresponding outputs as follows:

Note that, as the regularization term does not involve squaring in L1 regularization, we ...

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.