Balancing Act: Mastering Underfitting & Overfitting

| | 5 min read

Quick summary

  • Underfitting misses the signal: a model may be too simple to capture useful relationships.
  • Overfitting follows noise: strong training performance can hide poor results on new data.
  • Inspect both kinds of error: training and validation behaviour help distinguish the problems.
  • Adjust complexity deliberately: features, model flexibility and regularisation influence the balance.

Welcome to a journey through the delicate landscape of machine learning models! Today, we’re tackling two notorious pitfalls: underfitting and overfitting. Imagine you’re teaching a child to recognise animals. If you only show them pictures of small dogs, they might not recognise a large dog as a dog – that’s underfitting. The model is too simplistic and fails to capture the diversity of the concept.

On the other hand, if you teach them by showing every possible variety of dogs, including those in costumes, they might get confused when they see a plain dog without a costume. That’s overfitting. The model has learned the training data, including the noise and outliers, so well that it fails when presented with new, unseen data.

Aspect Underfitting Overfitting
Complexity Too simple to capture the underlying patterns in the data. Too complex, capturing noise as if it were a significant pattern.
Flexibility Not flexible enough to learn from data. Too flexible, learns from both the noise and the signal in the data.
Performance on Training Data Poor, as it cannot model the training data well enough. Excellent, as it can model the training data too well.
Performance on New Data Poor, as it fails to generalize the patterns from the training data. Poor, as it fails to generalize due to learning noise and outliers.
Error due to Bias, as it makes assumptions that are too strong about the data. Variance, as it takes into account the random fluctuations in the data.
Typical Causes Not enough model complexity, insufficient features, too strong regularization. Too much model complexity, too many features, not enough regularization.
Indicators High bias, low variance. Low bias, high variance.
Solution Increase model complexity, add more features, reduce regularization. Simplify model, remove some features, increase regularization.

In machine learning, underfitting happens when a model is too simple to capture the underlying trend of the data. It doesn’t perform well even on the training data. Think of it as trying to fit a straight line to a curve – it doesn’t work because the model isn’t complex enough to handle the reality of the data’s shape.

Overfitting, conversely, is when a model is so complex that it captures the noise along with the trend. It’s like a line that zigzags to hit every point – it might look perfect for the training data but is too erratic to make sensible predictions on new data.

Our goal is to find the sweet spot – a model complex enough to capture the true pattern of the data but not so complex that it gets distracted by the noise. This post will walk you through understanding these concepts with clear examples, practical tips, and visual aids to ensure your model is just right. So, whether you’re new to the field or honing your skills, let’s optimize your models for the real world!

Diagnose underfitting and overfitting with a controlled experiment

The animal examples above are intuitions, but showing a learner more varied examples does not itself cause overfitting. The defining problem is learning sample-specific patterns that do not hold for new observations. A clearer practical test compares training and validation performance while keeping the data preparation and evaluation procedure consistent.

Consider a hypothetical regression task with three candidate models. The first produces large errors on both training and validation data. The second reduces both errors. The third fits the training examples almost perfectly but performs worse on validation. That pattern gives you a reason to investigate whether the third model’s extra flexibility is helping it follow noise.

Do not diagnose the cause from one score alone. Check data quality, target construction and the split. A validation set drawn from a different population can produce a gap even when the model is not excessively flexible. Likewise, a training procedure that has not converged can produce high error that resembles underfitting.

Use learning curves to choose the next step

A learning curve compares performance as the amount of training data changes. If training and validation errors remain close and high, adding similar examples may have limited value until you improve the representation or model. If a substantial gap narrows as more data arrives, collecting representative examples may be a promising direction.

The scikit-learn learning curve guide explains this diagnostic approach. Curves are clues, not automatic prescriptions. Interpret them alongside the task, the noise in the targets and the cost of additional data collection. A larger dataset with the same missing information will not solve every modelling problem.

For suspected underfitting, test one meaningful change such as a relevant feature or weaker regularisation. For suspected overfitting, compare stronger regularisation or a simpler candidate. Keep the validation procedure fixed so the comparison answers a clear question. Record unsuccessful experiments too, since they help prevent repeated work.

Finally, reserve a test set for the selected approach. Repeatedly tuning against the final test score undermines its role as an independent check. The explanation of test set MSE and the bias-variance trade-off connects these practical decisions with expected prediction error. The target is dependable performance on new observations, rather than the most impressive fit to the examples already seen.

The post Balancing Act: Mastering Underfitting & Overfitting appeared first on Alpesh Kumar.

Subscribe to Our Newsletter

We don’t spam! Read our privacy policy for more info.