Ridge Regularization (L2 Regularization) › L2 Regularization (Ridge)
Machine Learning from ScratchAll chapters Ridge Regularization (L2 Regularization) › L2 Regularization (Ridge)One section · Sections in this chapter1 / 9 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Ridge regression, also known as L2 regularization, is a technique used in multiple linear regression (MLR) to prevent overfitting by adding a penalty term to the loss function. In standard MLR, the model tries to minimize the sum of squared errors between the predicted and actual values. However, when the model is too complex or when there are many correlated features, it can fit the training data too closely, capturing noise rather than the underlying pattern.
Ridge regression addresses this by adding a penalty for large coefficient values, effectively constraining the model and encouraging simpler models that generalize better to new data. The two most common types of regularization are LASSO (L1) and Ridge (L2). They differ in how they penalize coefficients.
Ridge Regression is known as L2 regularization because it adds a penalty proportional to the squared L2 norm of the coefficients (the sum of their squares).
In simple terms, Ridge helps a regression model avoid overfitting by keeping coefficients small. Unlike LASSO, Ridge does not drive coefficients to zero, but rather shrinks them toward zero while keeping all features in the model. This helps prevent overfitting while maintaining all features for interpretation.
Advantages
Ridge regression offers several advantages. It prevents overfitting by shrinking coefficients toward zero while keeping all features in the model. Unlike ordinary least squares, Ridge can handle correlated predictors without becoming unstable. The L2 norm has a clear geometric interpretation: it measures the Euclidean distance from the origin in coefficient space, creating a circular constraint region. The L2 penalty is also a convex function, which ensures that the optimization problem has a unique global minimum that efficient algorithms can find reliably.


The geometric interpretation reveals why Ridge and LASSO behave differently. The contour lines (ellipses) represent the error surface; points closer to the amber star (OLS solution) have lower error. The constraint regions (blue circle for Ridge, coral diamond for LASSO) represent the penalty term. The optimal regularized solution occurs where the error contours first touch the constraint region.
For Ridge, the circular constraint has no corners, so the tangent point typically occurs away from the axes, meaning both β₁ and β₂ remain non-zero. For LASSO, the diamond has sharp corners on the axes, making it much more likely that the error contours will first touch the constraint at a corner, resulting in one coefficient being exactly zero (sparse solution).
Disadvantages
Despite its advantages, Ridge regression has some limitations. Unlike LASSO, Ridge does not perform automatic feature selection since it does not drive coefficients exactly to zero, meaning all features remain in the final model. This can make the model less interpretable when dealing with datasets containing many irrelevant features. Additionally, Ridge requires careful tuning of the regularization parameter λ, and the optimal value may not be obvious without cross-validation. The method also assumes that all features are equally important for regularization, which may not be appropriate for datasets where some features are known to be more relevant than others.