Lensa ML
Lensa ML

Overfitting & Underfitting

Step 1 of 6

Underfitting

When the model is too simple to capture the pattern

xyTrainTestdegree = 1 (linear)TRAIN ERROR10.91TEST ERROR8.95Both errors are high!

A linear model cannot capture the quadratic pattern in the data. Both training and test errors remain high -- this is underfitting. The model has high bias and low variance.

Step 1 of 6: Underfitting

When the model is too simple to capture the pattern

xyTrainTestdegree = 1 (linear)TRAIN ERROR10.91TEST ERROR8.95Both errors are high!

A linear model cannot capture the quadratic pattern in the data. Both training and test errors remain high -- this is underfitting. The model has high bias and low variance.

Step 2 of 6: Overfitting

When the model captures noise instead of signal

xyTrainTestdegree = 11 (high)TRAIN ERROR0.00TEST ERROR0.90

A high-degree polynomial passes through every training point (near-zero train error) but wiggles wildly between them. On new test points, the error explodes -- this is overfitting. The model memorized noise instead of learning the pattern.

Step 3 of 6: The Sweet Spot

Just enough complexity to generalize

xydegree = 2sweet spotTrainTestTRAIN ERROR0.37TEST ERROR0.35
Model complexitydegree = 2
Simple (1)Complex (11)

Drag the slider to find the sweet spot. At degree 2-3, the model captures the true quadratic pattern without memorizing noise. Both train and test errors are low -- the model generalizes well.

Step 4 of 6: Bias vs Variance

Two sources of error, one tradeoff

BULLSEYE = TRUE VALUEHigh Bias, Low Variance

Bias = consistently wrong (off-center). Variance = inconsistent (scattered). The goal is low bias + low variance: predictions that are both accurate and consistent.

Step 5 of 6: Model Complexity Curve

The U-shaped test error

UNDERFITSWEET SPOTOVERFITModel Complexity (polynomial degree)Error (log scale)TrainTestOVERFIT
Complexitydegree = 5
TRAIN ERROR
0.11
TEST ERROR
0.69

The classic U-shaped test error curve. Training error always decreases with complexity, but test error hits a minimum then rises. The gap between curves is the generalization gap.

Step 6 of 6: What To Do About It

Practical strategies for finding the balance

Is test error high?YesIs training error also high?YesNoUNDERFITTINGOVERFITTINGSolutions:Use a more complex modelAdd more featuresReduce regularizationTrain longer / more epochsSolutions:Get more training dataAdd regularization (L1/L2)Use dropout / early stoppingSimplify the modelKey PrincipleUse a validation set to detect the problem early,then apply the right strategy from above.

Diagnose first, then act. If both errors are high, your model is too simple. If only test error is high, your model is too complex. Always use a validation set to catch these issues during training.