CDPL Logo
Cinute Digital
Home
ServicesEventMentors
BlogContact

Data Science

  • Data Science - OverviewComprehensive Data Science and AI - Master ProgramMachine Learning and Data Science with PythonDeep Learning, NLP and Generative AIAdvanced Data Science & Machine Learning MasterclassMachine Learning Algorithms using python ProgrammingMachine Learning and Data Visualization using R ProgrammingPython Programming

Artificial Intelligence(AI)

  • Artificial Intelligence (AI) - OverviewPrompt Engineering with Gen AI

Software Testing Courses

  • Software Testing - OverviewManual Software TestingAPI Testing using POSTMAN and RestAPIsDatabase Management System using MySQLETL Testing CourseAdvanced Software TestingAdvanced Automation TestingAdvanced Manual and Automation TestingAdvanced Manual and Automation TestingJava Programming

Digital Marketing

  • Digital Marketing - OverviewDigital Marketing and Analytics - Master ProgramDigital Marketing and AI (For Business Owners)Digital Marketing With AI Bootcamp

Business Development(BI)

  • Business Intelligence (BI) - OverviewAdvanced Data Analytics - Hero ProgramAdvanced Data Analytics with Python LibrariesExcel for Data Analytics & VisualizationData Analytics & Visualization with TableauData Analytics & Visualization with Power BIData Analytics With BI And Big Data Engineering - Master Program

Blogs

  • BlogsSoftware TestingData ScienceWeb DevelopmentAI & Machine LearningDigital Marketing

Services

  • Campus to CorporateCustom TrainingExpert TalksFaculty DevelopmentGovt & Public Sector TrainingIndustrial VisitsInternship ProgramOn Job TrainingShort Term Training Program (STTP)Train the TrainerWorkshops

Certifications and Accreditation

  • AAA CertificationACTD CertificationValidate Your Certificate

Events

  • Business Analytics Course (Aldel Institute)MoU Signing (St. Francis)Job Fair (Nirmala Memorial)Industrial Visit (VIVA Institute)National Conference on AI (MKES)FDP on Power BI & Tableau (Bhavans College)Internship Program (DJ Sanghvi)TechoutsavIndustrial Visit (Thakur College)Placement Drive (Tech Mahindra)

Follow Us On

Follow Us On

Institute

  • HomeCMS LoginMock TestISTQB RegistrationServicesEventsMentorsPlacementsLive JobsJob OpeningsCareersAbout CDPLOur TeamReviewsAffiliate ProgramContact Us

Loading...

Loading...

All BlogsWeb DevelopmentData SciencePython ProgrammingArtificial Intelligence and Machine Learning (AI/ML)Digital MarketingBusiness Intelligence (BI)Software TestingArtificial IntelligenceAll Categories

Loading...

Ready for Career Guidance?

At CDPL Ed-tech Institute, we provide expert career advice and counselling in AI, ML, Software Testing, Software Development, and more. Apply this checklist to your content strategy and elevate your skills. For personalized guidance, book a session today.

City Wise

Software Testing City Wise

  • Software Testing Course in MumbaiSoftware Testing Course in DelhiSoftware Testing Course in AhmedabadSoftware Testing Course in ChennaiSoftware Testing Course in BengaluruSoftware Testing Course in PuneSoftware Testing Course in KolkataSoftware Testing Course in Hyderabad

Data Science City Wise

  • Data Science Course in MumbaiData Science Course in DelhiData Science Course in AhmedabadData Science Course in ChennaiData Science Course in BengaluruData Science Course in PuneData Science Course in KolkataData Science Course in Hyderabad

Business Intelligence City Wise

  • Business Intelligence Course in MumbaiBusiness Intelligence Course in delhiBusiness Intelligence Course in AhmedabadBusiness Intelligence Course in ChennaiBusiness Intelligence Course in BengaluruBusiness Intelligence Course in PuneBusiness Intelligence Course in KolkataBusiness Intelligence Course in Hyderabad

Artificial Intelligence City Wise

  • Artificial Intelligence Course in MumbaiArtificial Intelligence Course in delhiArtificial Intelligence Course in AhmedabadArtificial Intelligence Course in ChennaiArtificial Intelligence Course in BengaluruArtificial Intelligence Course in PuneArtificial Intelligence Course in KolkataArtificial Intelligence Course in Hyderabad

Digital Marketing City Wise

  • Digital Marketing Course in MumbaiDigital Marketing Course in delhiDigital Marketing Course in AhmedabadDigital Marketing Course in ChennaiDigital Marketing Course in BengaluruDigital Marketing Course in PuneDigital Marketing Course in KolkataDigital Marketing Course in Hyderabad
View All
Cinute Digital logo

Cinute Digital

Get In Touch

Head Office (CDPL)

Office #1, 2nd Floor, Ashley Tower, Kanakia Road, Vagad Nagar, Beverly Park, Mira Road, Mira Bhayandar, Mumbai, Maharashtra 401107

Study Center MeghMehul Classes (Vasai)

Shop No 7, Laxmi Palace, Opposite Vidhyavardhini Degree Engineering College, Gurunanak Nagar, Vasai West, Mumbai, Maharashtra - 401202
contact@cinutedigital.com
+91 78-883-837-88|+91 84-889-889-84
MSME
Skill India
Trustpilot
ISO 27001 Certified
ISO 9001 Certified
Privacy PolicyCookies PolicyTerms and ConditionsCancellation/Refund Policy

ISO 9001:2015 (QMS) 27001:2013 (ISMS) Certified Company.

© 2026 Cinute Digital Pvt. Ltd. — All Rights Reserved.

Powered By

Testriq_logo

Overfitting vs Underfitting with Pictures

Shoeb Shaikh
Shoeb Shaikh

Shoeb Shaikh is a seasoned Software Testing and Data Science Expert and a Mentor with over 14 years of experience in the field. Specialist in designing and managing processes, and leading high-performing teams to deliver impactful results.

November 6, 2025•5 min read
Overfitting vs Underfitting with Pictures

See what overfitting and underfitting look like with simple charts. Learn the bias variance trade off, how to detect issues with learning curves and validation, and how to fix them with regularization and better data.

A clear, picture first guide by CDPL that explains overfitting and underfitting, bias variance trade off, detection methods, and practical fixes with scikit learn examples.

Introduction

Overfitting and underfitting are the most common reasons machine learning models fail to generalize. This CDPL picture first guide shows exactly what each one looks like, explains the bias variance trade off, and gives quick checks and fixes you can apply in scikit learn.

Quick Definitions

Blog Image
  • Underfitting: the model is too simple to learn the pattern. It has high bias and performs poorly on both train and test data.
  • Overfitting: the model is too complex and memorizes noise. It has high variance, high train accuracy, but poor test accuracy.

Visual Intuition: Lines and Curves

Blog Image

The same dataset can be modeled with different complexity. The pictures below are the fastest way to build intuition.

  • Underfitting (linear line on curved data): the model misses curvature and shows large errors everywhere.
  • Good fit: the curve follows the trend without chasing every point.
  • Overfitting (wiggly curve): the model bends through every point, including noise, and fails on new data.

Bias Variance Trade Off

Blog Image

Model error = bias² + variance + irreducible noise. Increasing complexity reduces bias but increases variance; simplifying reduces variance but increases bias. You want the minimum of total error on unseen data.

How to Detect Overfitting and Underfitting

Blog Image

Fast checks

  • Train vs validation gap: huge gap = overfitting; both bad = underfitting.
  • Learning curves: plot score vs number of training examples.
  • Cross validation: stable scores across folds signal generalization.
# Learning curve example (scikit-learn)
from sklearn.model_selection import learning_curve
from sklearn.linear_model import Ridge
from sklearn.datasets import make_regression
from sklearn.metrics import r2_score
import numpy as np

X, y = make_regression(n_samples=1500, n_features=20, noise=15, random_state=42)
est = Ridge(alpha=1.0)
train_sizes, train_scores, val_scores = learning_curve(
    est, X, y, cv=5, scoring="r2", train_sizes=np.linspace(0.1, 1.0, 6), random_state=42
)
print(train_sizes, train_scores.mean(axis=1), val_scores.mean(axis=1))

Use learning curves to see if more data helps and if the gap is shrinking

How to Fix Underfitting

Blog Image
  • Increase model capacity (polynomial features, deeper trees, kernels).
  • Reduce regularization strength (lower alpha for Ridge/Lasso, lower C in SVM).
  • Add better features (domain signals, interactions, non linear transforms).
  • Decrease bias in algorithms (switch from linear to tree based or kernel methods).

How to Fix Overfitting

Blog Image
  • Regularize: L1/L2, dropout for deep nets, pruning for trees.
  • Simplify: reduce depth, fewer parameters, early stopping.
  • More and cleaner data: collect more examples, remove label noise, stratify splits.
  • Cross validation and ensembling: average models to reduce variance.
# Regularization and polynomial features
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LassoCV

model = make_pipeline(
    PolynomialFeatures(degree=8, include_bias=False),
    LassoCV(cv=5, random_state=42)
)
model.fit(X, y)  # high-degree curve with regularization to tame variance

Use regularization when you need expressive features but want control over variance

Pictures You Can Recreate Quickly

Blog Image
# Underfit vs good fit vs overfit on 1D curve
import numpy as np, matplotlib.pyplot as plt
rng = np.random.default_rng(42)
X = np.linspace(-3, 3, 80).reshape(-1, 1)
y = np.sin(X).ravel() + 0.2 * rng.normal(size=X.shape[0])

from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import Ridge

m_under = LinearRegression()
m_good = make_pipeline(PolynomialFeatures(5), Ridge(alpha=0.5))
m_over = make_pipeline(PolynomialFeatures(16), Ridge(alpha=1e-6))

for m in [m_under, m_good, m_over]:
    m.fit(X, y)

xx = np.linspace(-3, 3, 400).reshape(-1, 1)
plt.scatter(X, y, s=18)
plt.plot(xx, m_under.predict(xx), label="Underfit")
plt.plot(xx, m_good.predict(xx), label="Good fit")
plt.plot(xx, m_over.predict(xx), label="Overfit")
plt.legend(); plt.show()

Three curves on the same data make the differences obvious for teams and reports

Checklist for Projects at CDPL

Blog Image
  • Always keep a validation set separate from training.
  • Plot learning curves before scaling up complexity.
  • Track train vs validation metrics in one dashboard.
  • Prefer simple models that meet the target metric; complexity must justify maintenance cost.

FAQ

Blog Image

Does more data always fix overfitting Often but not always. If labels are noisy or features leak, more data will not help.

Is regularization mandatory When features are many or correlated, yes. It stabilizes estimates and improves generalization.

Tree models do not need scaling; can they still overfit Yes. Limit depth, use min samples per split, and try ensembles like Random Forests.

Conclusion

Overfitting and underfitting are two sides of the same generalization problem. Use visuals, validation, and learning curves to diagnose quickly, then apply regularization, data improvements, and the right level of model complexity. With these habits, CDPL learners and partner teams can ship models that perform well on real world data.

Tags

#overfitting#underfitting#bias variance trade off#machine learning basics#model generalization#learning curves#regularization#scikit learn#cdpl cinute digital
Shoeb Shaikh
Shoeb Shaikh

Shoeb Shaikh is a seasoned Software Testing and Data Science Expert and a Mentor with over 14 years of experience in the field. Specialist in designing and managing processes, and leading high-performing teams to deliver impactful results.

November 6, 2025•5 min read

Share this article

TwitterLinkedInFacebook

Related Posts

1

Learn Prompt Engineering from Scratch (No Code Needed)

Artificial Intelligence
2

Agentic AI & Autonomous Workflows

Artificial Intelligence
3

AI Agents 101: Tools, Memory, and Planning

Artificial Intelligence
4

What Is Artificial Intelligence? Types, Examples, and Use Cases

Artificial Intelligence

Categories

Web Development7Data Science16Python Programming2Artificial Intelligence and Machine Learning (AI/ML)2Digital Marketing7Business Intelligence (BI)8Software Testing13Artificial Intelligence5
View All Categories

Newsletter

Get the latest articles and insights delivered directly to your inbox.

No spam. Unsubscribe anytime.

Popular Tags

#Python#Backend Development#Web Development#Django#Flask#Data Engineering#Apache Spark#IT Careers India#Fresher Jobs#PySpark