Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Unlock the full potential of AI with Building LLMs for Productionβ€”our 470+ page guide to mastering LLMs with practical projects and expert insights!

Publication

What Is Meant by the Regularization of the ML Model?
Latest   Machine Learning

What Is Meant by the Regularization of the ML Model?

Last Updated on July 17, 2023 by Editorial Team

Author(s): Mahesh Sonawane

Originally published on Towards AI.

Regularization Models: Ridge-Lasso

When I started studying ML, I was unable to understand how Linear regression, Ridge, Lasso, and Gradient Descent work mathematically. When I ask doubts to my friends, everyone explains differently, and some of them only say, β€œJust do it on your ML models”. It is hard to understand those things without any graphical visualization. That is the reason I am writing an article on Ridge and Lasso. In this article, I tried to explain these concepts as simply as possible.

Edited by author, Source: imgbin.com

Prerequisite: Linear Regression, Read my article on Linear regression- (https://medium.com/towardsdev/concepts-behind-linear-regression-ml-model-8b6962074102). Before we start, I assume you know all the basic concepts of linear regression. Let's start.

What is overfitting?

Let’s, take an example of a linear regression model.

Source: Author

Overfitting means the model tries to fit exactly to its training data. In the above example, the linear regression line goes through every point.

This means the accuracy of the overfitted model is 100%. Hence, the error is 0. (Error = Actual value β€” Predicted value = 0)

Assume your best fit line is Y = mx + c, Error = 0 (Error = Actual value β€” Predicted value = 0), m= tan(change in Y /change in X), c = 1 (intercept)

So, equation of line is Y= 0.03492076949 (X) + 1

look graph below, how will our model perform on unseen test data (Orange dots)? Errrrrrrrrrrrrrror…….

That means, Training accuracy = 100% and Testing accuracy = 70%

Source: Author

How will you reduce overfitting?

Overfitting means the error is zero. Now to reduce overfitting, we have to allow the model to have some errors in fitting the model on training data. From the below graph, we can see the line is not fitting exactly to train data.

Source: Author

Performance of regularized model on testing data.

Source: Author

For the above generalized model, we get Train accuracy = 80% and Test accuracy = 75%. (compare this with overfit model accuracies)

Here, we see training accuracy reduces (which means we allow some error to make the model generalized); hence, testing accuracy increases on the generalized model.

How did Ridge and Lasso introduce the extra amount of error in the model to avoid overfitting?

So assume the equation of the line is Y= 10 (X) + 1. Here, the coefficient is 0.03492076, and the intercept is 1. Look graph given below,

Source: Author

As the given model is overfitted,

Source: Author

Ridge Regression (L2 Regularization)

Ridge regression adds some amount of error to the error function. So the model will not overfit.

Source: Author

Look carefully; Ridge regression added term shown in an orange box. The term is the multiplication of the sum of squared coefficients (B) and lambda. (lambda value can be chosen as per requirement)

The equation of the line is Y= 10 (X) + 1. Here, the coefficient is 10, and the intercept is 1.

Source: Author

Ridge regression achieves regularization by reducing the importance given to some of the features and not by nullifying the importance of the features. Hence, it does not cause sparsity.

Lasso Regression (L1 Regularization)

Similarly, Lasso regression adds an error equivalent to lambda multiplied by the sum of absolute values of coefficients.

Source: Author

(lambda value can be chosen as per requirement)

Source: Author

Lasso regression achieves regularization by completely diminishing the importance given to some features (making the weight zero). Hence, causing sparsity

Conclusion

Regularization basically aims at proper feature selection to avoid over-fitting. Proper feature selection is achieved by optimizing the importance given to the features. It mainly regularizes or reduces the coefficient of features toward zero.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.

Published via Towards AI

Feedback ↓