Skip to content
mlmentorship

Regularization: diagnose the gap and choose a constraint

Check train/validation comparability, distinguish sparse and small coefficients, and return the best validated state instead of stacking penalties.

Published · 6 min read ·Core ·Foundation

Visual quick review

Distinguish a train-validation overfitting gap from underfitting or adequate fit, then match the diagnosed failure to one targeted regularization lever.

L1 can erase a coefficient; L2 shrinks both toward zero

Subtracting and scaling reshape the same coefficients differentlyFor this quadratic fit, L1 moves coefficients a fixed distance toward zero and stops there. Small coefficients can disappear. L2 shrinks each coefficient by the same proportion, leaving both nonzero here. The magnified small-coefficient ruler makes those different motions visible.Same data; penalty strength 0.2L1: subtract; stop at zeroSmall coefficient0.1 to 000.24Large coefficient2 to 1.802.4L2: scale toward zeroSmall coefficient0.1 to 0.0833300.24Large coefficient2 to 1.66702.4
Read it this way: For this quadratic fit, L1 moves coefficients a fixed distance toward zero and stops there. Small coefficients can disappear. L2 shrinks each coefficient by the same proportion, leaving both nonzero here. The magnified small-coefficient ruler makes those different motions visible. Which L1 coefficient returns when the threshold falls below 0.1?
Full explanation 6 min read
Reading depth

Summary

Regularization changes fitting to improve generalization under stated assumptions. A validation error alone does not identify overfitting. Compare unregularized training and validation losses in evaluation mode, with matched metrics and preprocessing. Check leakage, split shift, label conventions, and optimization before selecting a constraint.

Task: fit independent coordinates with , where . Choose between small coefficients and exact zeros at penalty strength . These are analytic fixtures, not measured generalization gains.

A train/validation gap is evidence to investigate, not a diagnosis by itself

A train/validation gap is evidence to investigate, not a diagnosis by itselfIllustrative same-task train losses .9,.65,.4,.25,.15 and validation losses .92,.7,.5,.55,.7 diverge after step three. Split validity and train/eval mode are checked before testing an early-stop checkpoint on independent held-out evidence. Poor-both and good-both alternatives remain explicit; the intervention result is unknown.Illustrative matched loss traces; same task andsplitLossTraining steps: 1 -> 5Solid: train; dashed: validationFirst verify split + train/eval modes.If valid: test an early-stopcheckpointon independent held-out evidence;result ?Both poor: check optimization/data beforeconstraining.Both good: more regularization need not help.
The dashed validation curve turns upward while train loss falls. Check split and mode before attributing the gap to capacity. The proposed held-out intervention has no invented result.
Check: What evidence distinguishes a capacity hypothesis from a bad evaluation split before adding regularization?
Reference drawing

L1 can erase a coefficient; L2 shrinks both toward zero

Subtracting and scaling reshape the same coefficients differentlyFor this quadratic fit, L1 moves coefficients a fixed distance toward zero and stops there. Small coefficients can disappear. L2 shrinks each coefficient by the same proportion, leaving both nonzero here. The magnified small-coefficient ruler makes those different motions visible.Same data; penalty strength 0.2L1: subtract; stop at zeroSmall coefficient0.1 to 000.24Large coefficient2 to 1.802.4L2: scale toward zeroSmall coefficient0.1 to 0.0833300.24Large coefficient2 to 1.66702.4
Derivation
A train/validation gap is evidence to investigate, not a diagnosis by itselfIllustrative same-task train losses .9,.65,.4,.25,.15 and validation losses .92,.7,.5,.55,.7 diverge after step three. Split validity and train/eval mode are checked before testing an early-stop checkpoint on independent held-out evidence. Poor-both and good-both alternatives remain explicit; the intervention result is unknown.Illustrative matched loss traces; same task andsplitLossTraining steps: 1 -> 5Solid: train; dashed: validationFirst verify split + train/eval modes.If valid: test an early-stopcheckpointon independent held-out evidence;result ?Both poor: check optimization/data beforeconstraining.Both good: more regularization need not help.
The dashed validation curve turns upward while train loss falls. Check split and mode before attributing the gap to capacity. The proposed held-out intervention has no invented result.
Check: What evidence distinguishes a capacity hypothesis from a bad evaluation split before adding regularization?
Read it this way: For this quadratic fit, L1 moves coefficients a fixed distance toward zero and stops there. Small coefficients can disappear. L2 shrinks each coefficient by the same proportion, leaving both nonzero here. The magnified small-coefficient ruler makes those different motions visible. Which L1 coefficient returns when the threshold falls below 0.1?

The classical lineup

For this unit-curvature quadratic, the penalty determines the optimum:

Added penaltyOptimumAt

The first L1 coordinate is zero because satisfies its subgradient condition. For L2, differentiating gives , retaining both nonzero coordinates. Exact L1 zeros require an objective optimum or an appropriate nonsmooth solver, not merely a few ordinary gradient steps.

When to use what

New task: retain the weak feature by reducing L1 strength to . Move the threshold inward without changing the data quadratic. Check: ; neither coordinate is zero. Use when: held-out evidence and the desired feature count favor retaining it.

New task: select a checkpoint from epoch losses on validation. Save epoch two; patience controls stopping time, not returned weights. Check: restore loss , not the final epoch’s . Use when: further fitting worsens a trustworthy held-out objective; never select on the test set.

Failure: flipped validation label conventions can create a gap that weight decay cannot repair.

Reconstruct: combine L1 strength with L2 strength in this fixture. What is the optimum?

Answer

Threshold to , then divide by , giving . This Elastic Net formula depends on the separable unit-curvature quadratic.

L2 regularization (weight decay)

Use for a loss penalty. Its Gaussian MAP-prior interpretation depends on likelihood scaling. Decoupled decay is not generally the same optimizer update.

L1 regularization

The absolute-value penalty corresponds to independent Laplace priors under matching MAP assumptions. Feature scaling and solver choice affect sparse solutions.

L1 + L2 (Elastic Net)

Combining penalties changes both threshold and shrinkage, as the reconstruction example shows.

Dropout

Follow the mask-expectation calculation rather than treating nonlinear inference as exact ensemble averaging. Placement and probability are architecture-specific. Monte Carlo dropout deliberately retains sampling for a separate uncertainty procedure.

Early stopping

Finite optimization time changes the learned solution. Equivalence to an L2 penalty holds only under particular model, optimization, and spectral assumptions.

Data augmentation

Specify an assumed label-preserving transformation; flipping an image or replacing a word can instead change the target. Augmented samples are not additional independent observations.

The modern view: implicit regularization

Optimizer, initialization, sampling, and architecture can bias solutions without an explicit penalty. Small-batch or flat-minimum generalization advantages are conditional findings, not universal guarantees or optimizer rankings.

Common confusions

More regularization can worsen fitting and generalization. Joint changes obscure which hypothesis the experiment tested.

Why interviewers ask

Explain the evidence, selected constraint, validation decision, and a counterexample to the diagnosis.


Related: Why does dropout work?, Adam, AdamW, and modern optimizer choices.