🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #194

Underfitting

Underfitting is overfitting's opposite failure mode — a model too simple to capture the real pattern in the data, performing poorly on training data and new data alike.

The Clearest Signal

Unlike overfitting's large train/validation gap, underfitting shows both scores being poor and close together — the model isn't failing to generalize a pattern it learned; it never learned an adequate pattern to begin with.

SymptomOverfittingUnderfitting
Training performanceVery highPoor
Validation performanceNoticeably worse than trainingAlso poor, similar to training
Train/val gapLargeSmall

Common Causes

CauseWhy It Underfits
Model too simple for the true relationshipA linear model can't capture a genuinely curved pattern
Too much regularizationOver-penalizing complexity can suppress genuinely useful signal
Insufficient or poorly engineered featuresThe model never sees the information it would need
Training stopped too earlyThe model hasn't had enough iterations to fit even the real pattern

Diagnosing It in Code

from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score

model = LinearRegression().fit(X_train, y_train)
train_r2 = r2_score(y_train, model.predict(X_train))
val_r2 = r2_score(y_val, model.predict(X_val))

print(f"Train R²: {train_r2:.3f}, Validation R²: {val_r2:.3f}")
# Both low and close together (e.g. 0.35 and 0.33) -> underfitting,
# not the large-gap pattern that signals overfitting

The Fixes

  • Use a more flexible model (e.g. polynomial features, a tree-based model instead of linear)
  • Reduce regularization strength, if it was set too aggressively
  • Add more, or better-engineered, features — see Feature Engineering
  • Train longer / increase model capacity, for iterative or capacity-limited models

Practical Use Cases

Underfitting is the useful check to run when a model performs surprisingly poorly on everything, not just on new data — it points squarely at model capacity or feature quality, not generalization technique.

Common Mistakes

  • Applying overfitting fixes (more regularization, simpler model) to a genuinely underfitting model — this makes underfitting worse.
  • Assuming a simple model is always "safer" — an overly simple model is just a different, equally real failure mode.

Interview Relevance

Q: "Your model has 60% training accuracy and 58% validation accuracy. Is this overfitting?" No — both scores are poor and close together, the signature of underfitting, not overfitting; the fix here is more model capacity or better features, not more regularization or early stopping.

Practice Question

A linear regression model shows R²=0.3 on both training and validation data for a target you suspect has a genuinely curved relationship with the features. What would you try first?

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Underfitting – FAQs

Quick answers about learning Underfitting in Machine Learning.

This free note from CodingNow 2.0 explains Underfitting in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including Underfitting, is 100% free with no signup required.
With focused practice, most students grasp Underfitting 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