Regularization Rate

RawGraph

Last edited

Fact-checked

In review queue

Sources

17 citations

Revision

v8 · 4,209 words

Fact-checks are independent of edits: a reviewer re-verifies the article against its sources and stamps the date. How we verify

The regularization rate (commonly denoted as λ\lambda or alpha) is a hyperparameter that controls the strength of the penalty applied to a model's parameters during training. It determines how much weight the regularization term receives relative to the primary loss function, directly influencing the tradeoff between fitting the training data closely and keeping the model simple enough to generalize to unseen data.[7]

"Regularization rate" is the terminology used in Google's Machine Learning Crash Course and Machine Learning Glossary, which describe it as the scalar that developers use to "tune the overall impact of complexity on model training."[15] Google's glossary lists lambda (λ) as a direct synonym for the regularization rate.[14] Raising the rate strengthens regularization and reduces the chance of overfitting; setting it to zero removes regularization completely and, in Google's words, "poses the highest possible overfitting risk."[15]

In machine learning and statistics, the regularization rate appears in methods such as ridge regression, lasso regression, elastic net, and weight decay for neural networks. Selecting an appropriate value for this parameter is one of the most consequential decisions in model development, as it shapes the bias-variance tradeoff and affects whether a model underfits or overfits.

ELI5: Explain like I'm 5

Imagine you are building a sandcastle. If you use too little water, the sand falls apart and your castle has lots of messy details that look bad (this is like overfitting, where a model memorizes noise). If you use too much water, everything turns into a flat blob and you lose all the cool towers and details (this is like underfitting, where a model is too simple).

The regularization rate is like choosing the size of your water bucket. A bigger bucket (higher regularization rate) smooths everything out more. A smaller bucket (lower regularization rate) lets you keep more detail. You want to find just the right bucket size so your castle has nice shapes without falling apart.

What are the different names for the regularization rate?

The regularization rate goes by several names depending on the field and software framework:

TermContextNotes
λ\lambda (lambda)Statistics, optimization theoryThe most common symbol in textbook formulations; listed by Google's ML glossary as a synonym for regularization rate[14]
α\alpha (alpha)Scikit-learn, Python ML librariesUsed because lambda is a reserved keyword in Python
C (inverse)Logistic regression in scikit-learn, SVMC=1/λC = 1/\lambda, so larger C means less regularization
Regularization strengthGeneral ML literatureSynonymous with regularization rate
Penalty parameterStatisticsEmphasizes the penalty interpretation
Weight decay coefficientDeep learningSpecifically for L2 regularization applied to neural network weights
reg_lambda, reg_alphaXGBoost, LightGBML2 and L1 regularization parameters in gradient boosting frameworks

Throughout this article, λ\lambda is used as the primary symbol unless a specific framework's convention is being discussed.

How is the regularization rate defined mathematically?

The regularization rate λ\lambda appears as a multiplier on the penalty term added to the base loss function. The general regularized objective takes the form:

J(θ)=L(θ)+λR(θ)J(\theta) = L(\theta) + \lambda R(\theta)

where:

  • J(θ)J(\theta) is the total objective function to minimize
  • L(θ)L(\theta) is the data-fitting loss (for example, mean squared error or cross-entropy)
  • R(θ)R(\theta) is the regularization penalty (a function of the model parameters θ\theta)
  • λ0\lambda \ge 0 is the regularization rate

When λ=0\lambda = 0, there is no regularization and the model minimizes the raw loss. As λ\lambda increases, the penalty term exerts more influence, pushing the model toward simpler parameter configurations.

L2 regularization (ridge)

In ridge regression, the penalty is the sum of squared parameter values:

J(θ)=1ni(yiy^i)2+λjθj2J(\theta) = \frac{1}{n} \sum_i (y_i - \hat{y}_i)^2 + \lambda \sum_j \theta_j^2

The ridge estimator has the closed-form solution:

θ^=(XX+λI)1XY\hat{\theta} = (X^\top X + \lambda I)^{-1} X^\top Y

Adding λI\lambda I to the matrix XXX^\top X shifts the diagonal entries, which stabilizes the inversion when features are highly correlated or when the number of features exceeds the number of samples. This was first described by Hoerl and Kennard in 1970[1] and independently by Andrey Tikhonov in the context of solving ill-posed inverse problems.[2]

Key property: L2 regularization shrinks all coefficients toward zero by a uniform factor, but it never sets any coefficient to exactly zero.

L1 regularization (lasso)

In lasso regression, the penalty is the sum of absolute parameter values:

J(θ)=12nyXθ22+λθ1J(\theta) = \frac{1}{2n} \lVert y - X\theta \rVert_2^2 + \lambda \lVert \theta \rVert_1

This formulation was popularized by Robert Tibshirani in 1996, building on earlier work in geophysics from 1986.[3]

Key property: L1 regularization can drive coefficients to exactly zero, effectively performing feature selection. This occurs because the L1 constraint region forms a diamond shape whose corners lie on the coordinate axes, making it geometrically likely for the optimal solution to sit at a corner where one or more coefficients equal zero.

Elastic net

Elastic net combines both L1 and L2 penalties, introducing a mixing parameter (often called l1_ratio or α in scikit-learn) alongside the overall regularization rate:

J(θ)=12nyXθ22+λ[αθ1+1α2θ22]J(\theta) = \frac{1}{2n} \lVert y - X\theta \rVert_2^2 + \lambda \left[ \alpha \lVert \theta \rVert_1 + \frac{1 - \alpha}{2} \lVert \theta \rVert_2^2 \right]

Here, λ controls the total penalty strength and α determines the balance between L1 and L2:

α valueBehavior
α=1\alpha = 1Pure L1 (equivalent to lasso)
α=0\alpha = 0Pure L2 (equivalent to ridge)
0<α<10 < \alpha < 1A blend of both penalties

Elastic net is especially useful when there are groups of correlated features, since lasso tends to arbitrarily pick one feature from each correlated group while elastic net can retain entire groups.[4]

How does the regularization rate affect the bias-variance tradeoff?

The regularization rate directly controls where a model falls on the bias-variance tradeoff spectrum. Increasing λ\lambda increases bias and decreases variance; decreasing λ\lambda has the opposite effect.

Scenarioλ valueBiasVarianceRisk
No regularizationλ=0\lambda = 0LowHighOverfitting
Weak regularizationSmall λ\lambdaSlightly increasedModerately reducedMild overfitting possible
Moderate regularizationOptimal λ\lambdaBalancedBalancedBest generalization
Strong regularizationLarge λ\lambdaHighLowUnderfitting
Extreme regularizationλ\lambda \to \inftyVery highNear zeroSevere underfitting (model outputs near-constant predictions)

When λ is too small, the model retains enough flexibility to memorize noise in the training data. The training error may be very low, but the model performs poorly on new data because it has high variance.

When λ is too large, the penalty dominates the objective function and forces the parameters toward zero (or exactly to zero in the L1 case). The model becomes too constrained to capture the true underlying pattern, leading to high bias.

The optimal λ sits at the point where the sum of squared bias and variance is minimized, which corresponds to the lowest expected generalization error.[7] Because this optimal point depends on the specific dataset, it must be found empirically through validation procedures.

How does the regularization rate affect gradient descent?

In the context of gradient descent optimization, the regularization rate modifies the parameter update rule. Writing the L2 penalty with the common one-half convention, (λ/2) Σ θⱼ², the gradient of the penalty term with respect to each weight wⱼ is λwⱼ. The stochastic gradient descent update then becomes:

w(1ηλ)wηBL(w)w \leftarrow (1 - \eta\lambda) w - \frac{\eta}{\lvert B \rvert} \sum \nabla L(w)

where η is the learning rate and |B| is the mini-batch size.[12] The factor (1 - ηλ) causes the weights to shrink by a small fraction at each step before the gradient update is applied. This is why L2 regularization in neural networks is often called "weight decay."[13]

An important subtlety arises with adaptive optimizers like Adam. Loshchilov and Hutter (2019) showed that L2 regularization and weight decay are not equivalent when using Adam, because Adam rescales gradients by their running second moments. They proposed AdamW, which decouples the weight decay from the adaptive gradient step, and showed that this produces better generalization.[5] Their insight was that the regularization rate should interact with the raw weights rather than with the adapted gradients.

How does the regularization rate relate to the learning rate?

In neural network training, the regularization rate interacts closely with the learning rate, and the two are usually tuned together. According to Google's Machine Learning Crash Course, "learning rate and regularization rate tend to move weights in opposite directions. A high learning rate often pulls weights away from zero; a high regularization rate pushes weights towards zero."[15]

Because of this coupling, changing one hyperparameter typically requires re-examining the other. A model trained with a high learning rate may need a correspondingly higher weight decay to keep the weights from growing too large, and vice versa. This interaction is one reason weight decay and learning rate schedules are frequently searched jointly rather than in isolation. It also motivated the AdamW design: under the original coupled formulation, the effective amount of regularization changed whenever the learning rate changed, whereas decoupling the two makes the regularization rate behave more predictably across learning rate settings.[5]

What is the Bayesian interpretation of the regularization rate?

From a Bayesian perspective, the regularization rate relates to the strength of the prior distribution placed on the model parameters. The regularized objective function corresponds to the negative log-posterior in maximum a posteriori (MAP) estimation:

θ^MAP=argmax[logp(Dθ)+logp(θ)]\hat{\theta}_{\text{MAP}} = \arg\max \left[ \log p(D \mid \theta) + \log p(\theta) \right]

The regularization penalty R(θ)R(\theta) corresponds to the negative log-prior, and λ\lambda controls how strongly the prior influences the posterior estimate relative to the likelihood.[8]

Regularization typeCorresponding priorPrior distribution shape
L2 (ridge)Gaussian prior with mean 0Bell-shaped; shrinks parameters smoothly toward zero
L1 (lasso)Laplace prior with location 0Peaked at zero with heavy tails; encourages exact sparsity
Elastic netMixture of Gaussian and LaplaceCombines properties of both

In this framework, a large λ corresponds to a tight prior (small variance for the Gaussian, or small scale for the Laplace), expressing a strong belief that the parameters should be close to zero. A small λ corresponds to a diffuse prior, allowing the data to have more influence on the parameter estimates.

This interpretation gives the regularization rate a concrete statistical meaning rather than treating it as an abstract tuning knob.[10] It also provides a principled way to set λ when prior knowledge about the parameter magnitudes is available.

How do you choose the regularization rate?

Choosing the right value for λ is a model selection problem. Several methods are commonly used.

K-fold cross-validation

Cross-validation is the most widely used approach. The training data is split into k folds (typically k = 5 or k = 10). For each candidate λ value, the model is trained on k - 1 folds and evaluated on the held-out fold. This process repeats k times, and the average validation error across folds is computed. The λ that produces the lowest average error is selected.

Scikit-learn provides built-in cross-validated estimators such as RidgeCV, LassoCV, and ElasticNetCV that automate this process. These estimators test a range of λ values and return the model fitted with the best one.[11]

Grid search evaluates every combination of hyperparameters from a predefined set. For the regularization rate, practitioners typically search over a logarithmic scale (for example, 10⁻⁴, 10⁻³, 10⁻², 10⁻¹, 1, 10, 100) because the effect of λ spans several orders of magnitude.

Random search samples hyperparameter values from specified distributions. Bergstra and Bengio (2012) showed that random search is often more efficient than grid search, especially when some hyperparameters matter more than others.[6]

MethodStrengthsWeaknesses
Grid searchExhaustive; guaranteed to find the best value in the gridComputationally expensive; scales poorly with multiple hyperparameters
Random searchMore efficient for high-dimensional hyperparameter spacesMay miss the optimal value if the budget is too small
Bayesian optimizationUses past evaluations to guide the search intelligentlyMore complex to implement; overhead may not pay off for a single hyperparameter
Successive halvingStarts with many candidates and progressively eliminates poor onesRequires defining an early-stopping criterion

Information criteria

For certain linear models, the regularization rate can be selected using information-theoretic criteria such as the Akaike Information Criterion (AIC) or the Bayesian Information Criterion (BIC). These criteria estimate the generalization error by penalizing model complexity without requiring a validation set.

Scikit-learn's LassoLarsIC estimator uses AIC or BIC to select the optimal α for lasso regression.[11] This approach is faster than cross-validation because it computes a single regularization path rather than fitting the model multiple times. However, it relies on assumptions about the noise distribution and may be less reliable for small sample sizes.

Generalized cross-validation

Generalized cross-validation (GCV) is a rotation-invariant version of leave-one-out cross-validation that does not require explicit data splitting. It is particularly common in the Tikhonov regularization literature and in smoothing spline methods.[2] GCV has good asymptotic properties but may be unreliable for small to moderate sample sizes.

L-curve method

The L-curve method plots the norm of the regularized solution against the norm of the residual for a range of λ values. The resulting curve typically has an L-shape, and the optimal λ is chosen at the corner of the L, which represents the best tradeoff between solution smoothness and data fidelity. This method is mainly used in inverse problems and signal processing.

What is the regularization rate in neural networks (weight decay)?

In deep learning, the regularization rate (weight decay coefficient) is applied to the network's weight matrices.[9] The standard practice is to apply weight decay to the weight parameters but not to biases or batch normalization parameters.[12]

Common values

Typical weight decay values in deep learning range from 10⁻⁵ to 10⁻², depending on the architecture and dataset:

Architecture / taskTypical weight decay rangeNotes
CNNs for image classification10⁻⁴ to 5 × 10⁻⁴Often 10⁻⁴ is used as a default
Transformers for NLP10⁻² to 10⁻¹BERT used 0.01; GPT variants commonly use 0.1
Small networks / tabular data10⁻⁵ to 10⁻³Lower values because models are already relatively constrained
Fine-tuning pretrained models10⁻⁵ to 10⁻⁴Lighter regularization to preserve learned representations

For example, the original BERT model was trained with a weight decay of 0.01,[17] while GPT-3 used a larger weight decay of 0.1 together with Adam betas of 0.9 and 0.95.[16] These transformer-scale values are notably higher than the 10⁻⁴ range common for convolutional networks, reflecting the tendency of very large, over-parameterized models to benefit from stronger regularization.

Is weight decay the same as L2 regularization?

For standard stochastic gradient descent (SGD), L2 regularization and weight decay produce identical updates when the weight decay coefficient is properly rescaled by the learning rate. However, for adaptive optimizers like Adam, RMSProp, and Adagrad, the two are not equivalent. As Loshchilov and Hutter put it, "L2 regularization and weight decay regularization are equivalent for standard stochastic gradient descent (when rescaled by the learning rate), but ... this is not the case for adaptive gradient algorithms, such as Adam."[5]

Loshchilov and Hutter demonstrated this distinction in "Decoupled Weight Decay Regularization," first released as a preprint in 2017 and published at ICLR 2019, which introduced the AdamW optimizer.[5] In AdamW, weight decay is applied directly to the weights rather than being added to the loss gradient. This decoupling means the effective regularization does not depend on the adaptive learning rate scaling, leading to more consistent regularization behavior. The authors reported that the modification substantially improves Adam's generalization performance, allowing it to compete with SGD with momentum on image classification benchmarks.[5]

Regularization rate in linear models

Ridge regression

In ridge regression, the regularization rate controls how much the coefficient estimates are shrunk toward zero. As λ increases from 0, the coefficients decrease monotonically in magnitude. At λ=0\lambda = 0, the solution is the ordinary least squares (OLS) estimate. As λ approaches infinity, all coefficients approach zero.

Ridge regression is especially helpful when the design matrix has multicollinearity (highly correlated predictors), because the OLS solution becomes unstable with near-singular matrices. The regularization rate adds stability by inflating the diagonal of XXX^\top X.[1]

Lasso regression

In lasso regression, the regularization rate controls both the amount of shrinkage and the degree of sparsity. Small values of λ produce models with many nonzero coefficients, while large values produce sparse models with few nonzero coefficients.

The lasso solution path (plotting coefficient values as a function of λ) shows coefficients entering the model one at a time as λ decreases from its maximum value.[3] The maximum λ\lambda (λmax\lambda_{\max}) is the smallest value at which all coefficients are zero, and it equals the maximum absolute correlation between any predictor and the response.

Logistic regression

In logistic regression, scikit-learn uses the parameter C=1/λC = 1/\lambda by default.[11] This means that larger values of C correspond to weaker regularization (less penalty), while smaller values of C correspond to stronger regularization. This inverse parameterization can be a source of confusion when switching between frameworks.

Regularization rate in gradient boosting

Gradient boosting frameworks like XGBoost, LightGBM, and CatBoost expose multiple regularization parameters:

ParameterFrameworkDescription
reg_lambdaXGBoost, LightGBML2 regularization on leaf weights
reg_alphaXGBoost, LightGBML1 regularization on leaf weights
l2_leaf_regCatBoostL2 regularization coefficient
lambda_l1, lambda_l2LightGBM (alternative names)L1 and L2 regularization terms

In gradient boosting, the regularization parameters penalize the complexity of individual trees. Larger values of reg_lambda produce smoother predictions by discouraging extreme leaf values. Tuning these parameters typically involves searching over a log scale (for example, 0.001, 0.01, 0.1, 1, 10) using cross-validation.

Practical guidelines for tuning

The following guidelines can help practitioners select a good regularization rate:

  1. Search on a logarithmic scale. Because the effect of λ spans several orders of magnitude, a geometric progression (for example, 10⁻⁶, 10⁻⁵, ..., 10⁰, 10¹) is far more efficient than a linear grid.

  2. Start with cross-validation. Use k-fold cross-validation (k = 5 or 10) with a broad range of λ values, then narrow the search around the best-performing region.

  3. Monitor both training and validation error. If training error is much lower than validation error, λ is too small (overfitting). If both errors are high, λ is too large (underfitting).

  4. Consider the one-standard-error rule. Instead of choosing the λ that minimizes the cross-validation error, choose the largest λ whose error is within one standard error of the minimum. This produces a simpler model with comparable performance.[7]

  5. Adjust for dataset size. Smaller datasets generally benefit from stronger regularization because the risk of overfitting is higher. Larger datasets can tolerate weaker regularization.

  6. Account for feature scaling. Regularization penalizes parameters based on their magnitude, so features should be standardized (zero mean, unit variance) before applying regularization. Otherwise, features measured in large units will be penalized more heavily.

  7. Use framework defaults as a starting point. Many frameworks provide reasonable defaults (for example, scikit-learn's RidgeCV tests α values from 0.1 to 10 by default; XGBoost defaults reg_lambda to 1).

Comparison of regularization methods by λ behavior

PropertyL1 (Lasso)L2 (Ridge)Elastic net
Penalty termλjθj\lambda \sum_j \lvert \theta_j \rvertλjθj2\lambda \sum_j \theta_j^2λ[αjθj+1α2jθj2]\lambda \left[ \alpha \sum_j \lvert \theta_j \rvert + \frac{1-\alpha}{2} \sum_j \theta_j^2 \right]
SparsityYes, sets some coefficients to exactly zeroNo, shrinks all coefficients but none reach zeroPartial; degree depends on mixing parameter α
Feature selectionBuilt-in via zero coefficientsNoYes, when α > 0
Handling correlated featuresTends to select one feature from each correlated group arbitrarilyShrinks correlated features together; retains allGroups correlated features together like ridge while allowing sparsity like lasso
Bayesian priorLaplace (double exponential)Gaussian (normal)Mixture of Laplace and Gaussian
Computational costRequires iterative solvers (no closed-form solution)Closed-form solution availableRequires iterative solvers
When to useHigh-dimensional data where many features are irrelevantMulticollinear features; all features likely relevantCorrelated features with some irrelevant ones

Historical background

The idea of adding a penalty term to stabilize solutions has roots in multiple disciplines:

  • 1943: Andrey Tikhonov published foundational work on regularization for solving ill-posed problems in mathematical physics.
  • 1963: Tikhonov formalized the regularization method in his paper "Solution of incorrectly formulated problems and the regularization method."[2]
  • 1970: Arthur Hoerl and Robert Kennard introduced ridge regression in two papers published in Technometrics, applying similar ideas to statistical regression with multicollinear predictors.[1]
  • 1986: L1-penalty methods for sparse signal recovery appeared in the geophysics literature; Tibshirani later cited this work as a precursor to the lasso.[3]
  • 1996: Robert Tibshirani published the lasso paper, popularizing L1 regularization for statistical modeling and feature selection.[3]
  • 2005: Hui Zou and Trevor Hastie introduced elastic net regularization, combining L1 and L2 penalties.[4]
  • 2019: Ilya Loshchilov and Frank Hutter published the AdamW paper at ICLR (first posted as a 2017 preprint), showing that weight decay should be decoupled from the gradient-based update in adaptive optimizers.[5]

Common pitfalls

  1. Forgetting to scale features. If features have different scales, regularization will penalize some coefficients more than others, leading to biased results that have nothing to do with feature importance.

  2. Confusing C and λ. In scikit-learn's logistic regression and SVM implementations, the regularization parameter C is the inverse of λ. Increasing C weakens regularization, which is the opposite of what one might expect.

  3. Using a linear grid for λ. A linear grid (for example, 0.1, 0.2, 0.3, ...) wastes computational budget because it oversamples the region where λ changes produce negligible effects and undersamples the region where small changes in λ produce large effects.

  4. Ignoring the interaction with learning rate. In deep learning, the effective regularization depends on both the weight decay coefficient and the learning rate. Changing one without reconsidering the other can produce unexpected results.[12]

  5. Applying regularization to bias terms. Bias (intercept) terms should typically be excluded from regularization, as penalizing the bias pushes predictions toward zero rather than toward the true mean of the target variable.

See also

References

  1. Hoerl, A. E., & Kennard, R. W. (1970). "Ridge Regressions: Biased Estimation for Nonorthogonal Problems." *Technometrics*, 12(1), 55-67.
  2. Tikhonov, A. N. (1963). "Solution of incorrectly formulated problems and the regularization method." *Soviet Mathematics Doklady*, 4, 1035-1038.
  3. Tibshirani, R. (1996). "Regression Shrinkage and Selection via the Lasso." *Journal of the Royal Statistical Society: Series B*, 58(1), 267-288.
  4. Zou, H., & Hastie, T. (2005). "Regularization and Variable Selection via the Elastic Net." *Journal of the Royal Statistical Society: Series B*, 67(2), 301-320.
  5. Loshchilov, I., & Hutter, F. (2019). "Decoupled Weight Decay Regularization." *Proceedings of the International Conference on Learning Representations (ICLR)*. First released as arXiv:1711.05101 in 2017.
  6. Bergstra, J., & Bengio, Y. (2012). "Random Search for Hyper-Parameter Optimization." *Journal of Machine Learning Research*, 13, 281-305.
  7. Hastie, T., Tibshirani, R., & Friedman, J. (2009). *The Elements of Statistical Learning: Data Mining, Inference, and Prediction.* 2nd edition. Springer.
  8. Bishop, C. M. (2006). *Pattern Recognition and Machine Learning.* Springer.
  9. Goodfellow, I., Bengio, Y., & Courville, A. (2016). *Deep Learning.* MIT Press. Chapter 7: Regularization for Deep Learning.
  10. Murphy, K. P. (2012). *Machine Learning: A Probabilistic Perspective.* MIT Press.
  11. Pedregosa, F., et al. (2011). "Scikit-learn: Machine Learning in Python." *Journal of Machine Learning Research*, 12, 2825-2830.
  12. Zhang, A., Lipton, Z. C., Li, M., & Smola, A. J. (2023). *Dive into Deep Learning.* Cambridge University Press. Section 3.7: Weight Decay.
  13. Krogh, A., & Hertz, J. A. (1991). "A Simple Weight Decay Can Improve Generalization." *Advances in Neural Information Processing Systems (NeurIPS)*, 4.
  14. Google for Developers. "Machine Learning Glossary." developers.google.com/machine-learning/glossary (entry: lambda, listed as a synonym for regularization rate).
  15. Google for Developers. "Overfitting: L2 regularization." Machine Learning Crash Course. developers.google.com/machine-learning/crash-course/overfitting/regularization.
  16. Brown, T. B., et al. (2020). "Language Models are Few-Shot Learners" (GPT-3). *Advances in Neural Information Processing Systems (NeurIPS)*, 33.
  17. Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019). "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding." *Proceedings of NAACL-HLT*.

Improve this article

Add missing citations, update stale details, or suggest a clearer explanation. Every suggestion is reviewed for sourcing before it goes live.

7 revisions by 1 contributors · full history

Suggest edit