Prompts Forms Resume Reports ★ Saved ★ Saved★ + Submit a tool
Core concepts

L1 and L2 Regularization

About 3562 characters Updated Nov 30, 2026 31 views AI wiki

Regularization is the technique of adding a penalty on the size of model parameters to the loss function in order to suppress overfitting. L1 and L2 are the two most basic penalty forms; they differ in the norm of the penalty term, yielding two very different parameter distributions: sparse solutions and smooth solutions. It is a constraint broadly applicable from linear regression to deep networks, and together with early stopping, data augmentation, and Dropout it belongs to the toolbox for improving generalization.

Core Principles

The original objective is to minimize training error. Regularization changes the objective to training error plus lambda times a parameter penalty, where lambda is a hyperparameter controlling the strength of the constraint. The larger lambda is, the more the parameters are squeezed down and the lower the model capacity; as lambda approaches zero it degenerates into an ordinary model. This amounts to adding a prior preference in parameter space, and from a Bayesian view L2 corresponds to a Gaussian prior on the parameters and L1 to a Laplacian prior.

L1 penalizes the sum of absolute values of the parameters. Its loss surface has sharp corners along the coordinate directions, and the optimum easily lands on corners where some coefficients are exactly zero, producing a sparse solution that acts as automatic feature selection. L2 penalizes the sum of squared parameters; its contour lines are circular, and the gradient direction keeps pulling parameters toward zero without pressing them exactly to zero, giving parameters that are overall small but dense, similar to weight decay.

Geometrically it can be understood this way: looking at the constraint region together with the loss contours, L1's diamond-shaped constraint region has vertices on the axes, so a contour touching it is more likely to touch on an axis and the coefficients of some dimensions are zeroed; L2's circular constraint has no corners, and the tangent point is generally not on an axis.

Key Points

In linear models, L2 is also called ridge regression; it has an analytical solution and handles collinearity among features effectively, while L1 is called Lasso and is solved relatively fast by coordinate descent. When features are highly correlated and numerous, L1 picks one at random to keep and presses the rest to zero, giving unstable results; the elastic net mixes the two in proportion, balancing sparsity with group retention.

In deep learning, L2 is usually implemented through the optimizer's weight decay, but note that Adam's L2 penalty is not equivalent to decoupled weight decay; only the latter truly corresponds to classic L2, which is why AdamW was proposed. Bias terms and the scaling parameters of normalization layers are generally not regularized, since penalizing them distorts expressive power.

On implementation details, standardization is crucial. The penalty is sensitive to parameter scale, and when features have different units L1 will preferentially penalize the coefficients of features with large units, distorting the result. Hence centering and standardization must precede modeling. Lambda must be chosen by cross-validation along the regularization path, not set by feel.

Common Misconceptions

First, assuming L1 is necessarily better than L2, when sparse solutions are unstable under highly correlated features and do not necessarily generalize better. Second, treating L2 regularization and weight decay as equivalent under any optimizer. Third, comparing coefficient magnitudes directly on unstandardized data. Fourth, setting lambda too large, causing severe underfitting that is misdiagnosed as a data problem. Fifth, believing deep networks mainly rely on regularization to prevent overfitting, when data volume and data quality actually matter more.

Application Scenarios

Screening high-dimensional gene-expression data, feature reduction in text classification, matrix-factorization constraints in recommender systems, financial factor modeling with severe collinearity, stabilizing neural-network training, model compression and deployment, and compliance scenarios that need an interpretable set of key features.