Overfitting vs. Underfitting (And How to Fix Both)

Building an effective machine learning model requires striking a delicate balance between memorizing known data and generalizing to unseen instances.
When a model fails to strike this balance, it usually falls into one of two fundamental traps: Underfitting or Overfitting.
Diagnosing whether your model suffers from high bias (underfitting) or high variance (overfitting)—and knowing exactly which levers to pull to fix the issue—is one of the most critical skills in applied data science.

1. Defining the Core Concepts

      Underfitting                     Balanced                      Overfitting
    (High Bias / Simple)          (Optimal Generalization)      (High Variance / Complex)
  ┌──────────────────────┐        ┌──────────────────────┐      ┌──────────────────────┐
  │  •  •          •     │        │  •  •          •     │      │  •──•          •     │
  │     \                │        │      ╭─────────╯     │      │   \  \        /      │
  │      \               │        │   ╭──╯               │      │    \  •──────•       │
  │       \──•     •     │        │  •     •             │      │     •       •        │
  └──────────────────────┘        └──────────────────────┘      └──────────────────────┘

What is Underfitting? (High Bias)

Underfitting occurs when a model is too simple to capture the underlying structure, relationships, or trends present in the data. The model makes overly rigid assumptions, causing high prediction error on both training and validation sets.
  • Analogy: A student who only skims a single page of a textbook before an exam. They fail both the practice quizzes and the real exam because they never learned the material in the first place.

What is Overfitting? (High Variance)

 

Overfitting occurs when a model is too complex relative to the amount and noise level of the training data. Rather than learning general patterns, the model “memorizes” training instances, including random noise, outliers, and temporary fluctuations.
  • Analogy: A student who memorizes every exact question and answer from past practice exams. They score $100\%$ on practice tests, but fail the real exam because the questions are phrased slightly differently.

2. Diagnosing Model Behavior

The most reliable way to diagnose whether your model is underfitting or overfitting is by plotting its Learning Curves—comparing training error against validation error across training epochs or iterations:
                  UNDERFITTING                              OVERFITTING
          Error                                     Error
            ▲                                         ▲
            │                                         │
            │  Validation Error                       │  Validation Error
            │  ───────────────                        │  ───────────────┐
            │  Training Error                         │                 └───────► (Climbs)
            │  ───────────────                        │  Training Error
            │                                         │  ─────────────────────► (Plummets)
            └────────────────────►                    └────────────────────►
                               Epochs                                    Epochs
            (Both errors remain high)                  (Large gap between curves)
Metric / Behavior Underfitting Optimal Model Overfitting
Training Error High Low Extremely Low (near $0$)
Validation Error High Low High (or climbing)
Train vs. Val Gap Minimal Small Very Large
Model State Inflexible / Simple Balanced Overly Complex
Root Cause High Bias Ideal Complexity High Variance

3. How to Fix Underfitting (High Bias)

When your model performs poorly across all datasets, you need to increase its capacity to learn non-linear and complex patterns:

1. Increase Model Complexity

Upgrade to a model family with greater expressive power. For example, switch from a simple Linear Regression to a Decision Tree, Random Forest, or Deep Neural Network.

2. Feature Engineering & Selection

Introduce new contextual variables, create non-linear interaction terms ($X_1 \cdot X_2$), or add higher-order polynomial features ($X^2, X^3$).

3. Reduce Regularization Penalties

If you are using regularized models like Lasso ($L_1$) or Ridge ($L_2$), lower the regularization hyperparameter ($\lambda$ or $\alpha$). Heavy penalties artificially restrict model parameters from fitting complex trends.

4. Train Longer / Increase Epochs

Ensure optimization algorithms (like Gradient Descent) have enough iterations to reach convergence rather than stopping prematurely.

4. How to Fix Overfitting (High Variance)

When your model performs exceptionally well on training data but degrades on validation splits, apply these constraints to enforce generalization:

1. Cross-Validation

Implement $K$-Fold Cross-Validation to ensure performance evaluations are stable and consistent across multiple unseen data folds, preventing hyperparameter tuning from overfitting a single validation set.

2. Train with More Data

Increasing your training dataset size dilutes the impact of random noise, making it harder for complex models to memorize individual data points.

3. Apply Regularization ($L_1 / L_2$ & Dropout)

  • $L_1$ (Lasso): Forces uninformative feature weights to absolute zero, performing implicit feature selection.
  • $L_2$ (Ridge): Penalizes large weight values, smoothing decision boundaries.
  • Dropout (Deep Learning): Randomly deactivates a fraction of neurons during training to prevent co-adaptation.

4. Feature Reduction / Dimensionality Reduction

Remove redundant or noisy features using feature selection algorithms or techniques like Principal Component Analysis (PCA).

5. Early Stopping & Tree Pruning

  • Early Stopping: Monitor validation error during training and halt iterations the moment validation loss begins to increase.
  • Tree Pruning: Restrict max depth, minimum samples per leaf, or max leaf nodes in tree-based models.

Quick Reference Guide

                          Model Performance Issue
                                     │
            ┌────────────────────────┴────────────────────────┐
            ▼                                                 ▼
   [ Both Errors High ]                              [ Large Gap Between ]
    (Model Underfitting)                              (Model Overfitting)
            │                                                 │
  • Add features / interactions                     • Add more training data
  • Reduce regularization                           • Increase regularization
  • Choose a complex model                          • Apply early stopping / pruning
  • Train for more epochs                           • Reduce feature count

Key Takeaway

A successful machine learning pipeline focuses on finding the sweet spot where model complexity matches the inherent signal in the data. Monitor training and validation loss curves continuously to detect underfitting or overfitting early and apply the appropriate remedies.

About Adi Status

Adi Satus is a passionate financial writer with a keen interest in the ever-evolving world of loans, insurance, technology, and cryptocurrency. With years of experience researching and writing on a broad range of financial topics, Hindi Me Gyaan aims to simplify complex concepts and make them accessible for readers. Whether you're looking to secure a loan, navigate the world of insurance, explore the latest tech trends, or understand the intricacies of cryptocurrency, Hindi Me Gyaan provides expert insights and practical advice to help you make informed decisions. Always staying updated with the latest developments, Hindi Me Gyaan is dedicated to bringing you the most relevant, timely, and useful information to guide you on your financial journey.

View all posts by Adi Status →

Leave a Reply

Your email address will not be published. Required fields are marked *