๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #128

Overfitting

Overfitting is the opposite failure mode from underfitting: the model learns the training data's specific noise and idiosyncrasies too well, achieving excellent training performance that doesn't transfer to new, unseen data.

The Defining Signature

MetricOverfitting Signature
Training lossVery low โ€” the model fits the training data extremely well, sometimes almost perfectly
Validation lossNoticeably higher than training loss, and may start increasing even as training loss keeps decreasing
Gap between train and validation performanceLarge and often growing over the course of training

Why It Happens โ€” Memorization vs Generalization

A sufficiently high-capacity model (many parameters relative to the amount of training data) can, in principle, memorize the training set almost exactly โ€” including its noise, labeling errors, and coincidental patterns that don't reflect the true underlying relationship being learned. A model that has memorized noise performs excellently on that exact noisy data but has learned nothing generalizable, so it performs poorly on new data drawn from the same true distribution but with different specific noise.

Visualizing Overfitting

overfit model: passes through every point, wildly, generalizes poorly

The overfit curve hits every training point exactly, but its wild oscillation between points reflects noise, not the true underlying trend.

Common Causes

  • Model too complex relative to the amount of available training data โ€” too many parameters for too little data.
  • Training for too many epochs โ€” even a well-sized model can eventually start memorizing noise if trained far past the point of genuine improvement (exactly what Early Stopping prevents).
  • Insufficient regularization โ€” no dropout, no weight decay, no data augmentation to discourage memorization.
  • Small or unrepresentative training dataset โ€” less data means more opportunity for the model to fit noise rather than genuine signal.

Fixes for Overfitting

FixCategory Covered In
Add or increase dropout, weight decay (L1/L2)Regularization (next category)
Add data augmentationRegularization (next category)
Use early stoppingThis category โ€” Early Stopping
Collect more training dataโ€”
Reduce model capacity (fewer layers/parameters)โ€”
Use transfer learning from a model pretrained on more dataTransfer Learning category

Code โ€” Diagnosing Overfitting From Training Logs

train_losses = [2.3, 1.5, 0.8, 0.4, 0.2, 0.1, 0.05]   # keeps dropping, very low
val_losses   = [2.4, 1.6, 1.0, 0.9, 0.95, 1.1, 1.3]     # drops initially, then RISES

# Training loss keeps improving; validation loss turns upward around epoch 4 --
# this diverging pattern is the classic signature of overfitting

Common Mistakes

  • Judging model quality from training accuracy alone โ€” a model with 99% training accuracy could be badly overfit, performing far worse on genuinely new data; validation/test performance is what actually matters.
  • Applying every regularization technique at maximum strength reflexively โ€” over-regularizing can push a properly-fitting model into underfitting instead; regularization strength should be tuned, not maximized blindly.

Interview Relevance

Q: "What's the clearest single signal that a model is overfitting, visible in a training log?" A growing gap between training loss (continuing to decrease, often to a very low value) and validation loss (plateauing or starting to increase) โ€” the model keeps improving on data it has memorized while getting worse on data it hasn't seen, which is exactly the diverging pattern early stopping and regularization address.

Practice Question

A model achieves 98% training accuracy and 75% validation accuracy. Name two specific techniques you'd try first to close this gap, and briefly justify each.

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Overfitting โ€“ FAQs

Quick answers about learning Overfitting in Deep Learning.

This free note from CodingNow 2.0 explains Overfitting in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Overfitting, is 100% free with no signup required.
With focused practice, most students grasp Overfitting in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now