What is Ridge regression?
If there are too many predictor variables or features, then that may cause various problems. So, we can find important variables and keep them and omit the unimportant ones. But, in a practical scenario, it may not be the case where a variable is very important, and we should keep it, or a variable is unimportant, and we should omit it. So, to address the problem, we should find a way to penalize unimportant variables. In that way, we can keep the variables, but penalize them. We can use the Ridge regression for that purpose.
As we discussed in our article on linear regression, in linear regression, we need to find coefficients to minimize the error that can be expressed as:
In the Ridge regression, we need to minimize this function:
Here, λ is a variable that controls the amount of penalty that needs to be applied to a predictor variable. When λ is 0, the Ridge regression becomes multiple linear regression. When tends to infinity, coefficients reach 0.
Ridge Regression using Python
Let’s say we are given a set of car models along with their horsepower, weight, acceleration, and mpg or miles driven per 1 gallon of gasoline. We want to create a Ridge regression model using which we can determine the mpg of a car from its weight, horsepower, and acceleration.
We can use the following Python code for this Ridge regression model…








































0 Comments