Lensa ML
Lensa ML

How Regularization Works

Step 1 of 6

The Overfitting Problem

When the model memorizes instead of learning

xyTrainTestGood fit
Train Loss
0.125
Test Loss
0.013

An overfit model memorizes training noise — its training loss is tiny but it fails on new data. A good fit captures the true pattern and generalizes.

Step 1 of 6: The Overfitting Problem

When the model memorizes instead of learning

xyTrainTestGood fit
Train Loss
0.125
Test Loss
0.013

An overfit model memorizes training noise — its training loss is tiny but it fails on new data. A good fit captures the true pattern and generalizes.

Step 2 of 6: L2 Regularization

Penalizing large weights to keep things smooth

TrainTestλ = 0.00
No regularizationλ = 0.00Strong
Train Loss
0.000
Test Loss
0.188
λΣw²
0.00
Weight magnitudes |wᵢ| — Σw² = 2691k
0280561

With λ ≈ 0, no regularization — weights are large and varied, causing wiggly overfitting. Train loss is near zero but test loss is high.

Step 3 of 6: L1 Regularization

Pushing weights to exactly zero — built-in feature selection

TrainTestL1 λ = 0.00
No regularizationλ = 0.00Strong
Train Loss
0.028
Test Loss
0.143
λΣ|w|
0.00
Zeros
0/18
Weight magnitudes |wᵢ| — Σw² = 10.7
01.12.2

With λ ≈ 0, no regularization — all weights are active, the model overfits the noisy training data.

Step 4 of 6: Dropout

Randomly silencing neurons during training

×××InputHidden 1Hidden 2Output
Rate40%
Effective weights — 6/9 neurons active
00.941.9

Dropout randomly silences neurons each training step, forcing the network to not rely on any single path. The weight chart shows how dropped neurons have their effective weight zeroed out. At test time, all neurons are active but weights are scaled down. Currently dropping 3 of 9 hidden neurons.

Step 5 of 6: Early Stopping

Stop training before overfitting kicks in

EpochLossoverfit zonelearningepoch 28TrainVal
Epoch 0Epoch 0Epoch 60
Train Loss
2.050
Val Loss
2.150
Gap
0.100
‖w‖
0.50

Training hasn't progressed much yet. Both train and val loss are still high. Press Play or drag the slider.

Step 6 of 6: Comparison

How each technique shapes the fit

No Reg
Method
Train Loss
Test Loss
No Reg
0.000
0.188
L2
0.129
0.029
L1
0.127
0.073
Dropout
0.067
0.057
Early Stop
0.037
0.178
True f(x)
0.125
0.013
All losses are MSE computed on the same 18 train / 5 test points from Step 1. L2: RBF fit with λ=1 added to kernel diagonal. L1: ISTA solver with λ=1. Dropout: approximated as L2 with λ=0.5 (dropout ≈ implicit L2). Early stop: gradient descent halted at 80 iterations.

No Reg: Overfits — memorizes noise. Train loss is near zero but test loss is high — the classic sign of overfitting.