Home›Blog›Data Science
Data Science

Overfitting and Underfitting Explained (With Examples)

The two ways machine learning models go wrong — explained with analogies anyone can follow.

Over & Underfitting The balance every model has to strike.

Key takeaways

  • Overfitting is memorising the training data instead of learning the pattern.
  • Underfitting is failing to learn the pattern at all — too simple a model.
  • The goal is the balance between them: a model that generalises.
  • You spot them by comparing performance on seen vs unseen data.
  • Both are fixable once you know what you're looking at.

Two of the most important concepts in machine learning are overfitting and underfitting, and understanding them explains why models succeed or fail. They sound technical, but the ideas behind them are intuitive and even a little funny once you see them clearly. Get these two concepts, and a great deal of machine learning suddenly makes sense — including why a model that looks brilliant in testing can be useless in the real world. This guide explains both with simple analogies and shows you how to spot and fix each.

The two ways a model can fail

When you train a machine-learning model, you want it to learn the underlying pattern in your data so it can make good predictions on new, unseen data. That last part — new, unseen data — is the whole point. A model that only works on data it has already seen is useless, because the reason we build models is to handle the future, not to describe the past. Overfitting and underfitting are the two ways this goal goes wrong: one where the model learns too much of the wrong thing, and one where it learns too little. Understanding both is understanding the central challenge of machine learning.

The student analogy

Picture two students preparing for an exam. The first memorises the exact answers to last year's past paper without understanding the subject. On that specific paper they score perfectly, but when the real exam asks slightly different questions, they fail, because they memorised rather than learned. That is overfitting. The second student barely studies and grasps only the vaguest sense of the subject. They do poorly on the past paper and the real exam alike, because they never learned enough. That is underfitting. The ideal student actually understands the subject, so they handle both the past paper and new questions well. That is the balance we want in a model.

What overfitting is

Overfitting happens when a model learns the training data too well — including its noise, quirks and random details that are not part of the real pattern. Like the memorising student, it performs beautifully on data it has seen and poorly on new data. This usually happens when a model is too complex for the amount of data, giving it enough flexibility to essentially memorise the training examples rather than generalise from them. Overfitting is dangerous precisely because it looks like success at first: your model scores wonderfully in training, and only when it meets real, unseen data does its failure become clear. Recognising it early saves you from deploying a model that will disappoint.

What underfitting is

Underfitting is the opposite: the model is too simple to capture the real pattern in the data, so it performs poorly even on the training data, let alone new data. Like the student who barely studied, it never learned enough to be useful. This happens when a model lacks the flexibility to represent the underlying relationship, or when it has not been trained enough. Underfitting is at least honest — it looks bad from the start rather than hiding until deployment — but it is equally useless. A model that cannot even fit the data it was trained on will not help you predict anything.

The balance you want

Between these two failures lies the goal: a model that has learned the genuine underlying pattern well enough to generalise to new data, without memorising noise. This is often called a model that generalises well, and achieving it is much of the art of machine learning. You want enough complexity to capture the real pattern, but not so much that the model starts memorising quirks. Finding this sweet spot for a given problem and dataset is a central skill, and it is why machine learning is as much craft as science. The whole practice, in a sense, is a search for this balance.

How to spot each problem

The key tool for spotting both is comparing your model's performance on data it was trained on versus data it has not seen — which is exactly why you split your data. If your model performs well on training data but noticeably worse on unseen test data, that gap signals overfitting: it learned the training set too specifically. If your model performs poorly on both training and test data, that signals underfitting: it never learned the pattern well enough. This simple comparison — training performance versus test performance — is how practitioners diagnose which problem they have, and it is the foundation of knowing what to fix.

Fixing overfitting

Once you have diagnosed overfitting, several approaches help. You can use more training data, giving the model more examples so it must learn the general pattern rather than memorising a few. You can simplify the model so it has less capacity to memorise noise. You can use techniques specifically designed to discourage over-complexity and keep the model general. And you can stop training before the model starts memorising. You do not need the technical details as a beginner; the important idea is that overfitting is fixable by reducing the model's ability to memorise and encouraging it to generalise. Diagnosis points you to the remedy.

Fixing underfitting

Underfitting is addressed in largely opposite ways. You can use a more capable model with enough flexibility to capture the pattern. You can give the model better or more informative features to learn from, so the real relationship is easier to find. You can train it longer or more thoroughly. And you can ensure your data actually contains the signal you are hoping to learn. Again, the details matter less than the concept: underfitting means the model needs more capacity or better inputs to learn the pattern. Once you recognise it, the direction of the fix is clear.

The trade-off between them

Overfitting and underfitting sit at two ends of a trade-off, and pushing away from one moves you towards the other. Make a model more complex to cure underfitting, and you risk overfitting; simplify it to cure overfitting, and you risk underfitting. This is why machine learning involves careful tuning and judgement rather than a single correct setting. The aim is to land in the balanced middle for your particular data and problem, using the training-versus-test comparison to guide you. Accepting that this is a balance to be found, not a formula to be applied, is itself an important step in becoming a capable practitioner.

The bottom line

Overfitting and underfitting are the two ways machine-learning models fail: overfitting memorises the training data and flops on new data, while underfitting never learns the pattern at all. The goal between them is a model that generalises. You diagnose which you have by comparing performance on seen versus unseen data, and you fix each by adjusting the model's complexity and inputs in opposite directions. Understand this balance and how to navigate it, and you understand one of the most fundamental ideas in all of machine learning.

Why this matters beyond the exam room

It is easy to treat overfitting and underfitting as academic concepts, but they have very real consequences the moment a model meets the world. Imagine a bank deploys a loan-repayment model that overfitted its training data: in testing it looked superb, but on new applicants it makes poor, unreliable predictions, leading to bad lending decisions and real financial loss. Or picture a health screening tool that underfitted: it never learned the pattern well enough, so it misses cases it should catch. In both cases the failure is not abstract — it costs money, trust, or even wellbeing. Understanding these concepts is therefore not just theory; it is what stands between a model that helps and one that quietly harms.

This is also why the discipline of honest evaluation, covered in related guides, matters so much. The only reason you can catch overfitting before it does damage is that you tested your model on data it had never seen and noticed the gap between training and test performance. A practitioner who skips that step, dazzled by great training results, ships overfitted models without knowing it. So these ideas connect directly to responsible, trustworthy machine learning: you build models that genuinely work in the real world by respecting the balance between overfitting and underfitting, and by always measuring performance honestly on unseen data before you rely on anything.

Frequently asked questions

What is overfitting in simple terms?
Overfitting is when a model memorises the training data — including its noise and quirks — instead of learning the real pattern. Like a student who memorises past-paper answers, it does brilliantly on seen data but fails on new, unseen data.
What is underfitting?
Underfitting is when a model is too simple to capture the real pattern, so it performs poorly even on the training data, let alone new data. Like a student who barely studied, it never learned enough to be useful.
How do I know if my model is overfitting or underfitting?
Compare its performance on training data versus unseen test data. Good on training but worse on test means overfitting. Poor on both means underfitting. This simple comparison is how practitioners diagnose which problem they have.
Why is overfitting dangerous?
Because it looks like success at first — the model scores wonderfully on training data — and its failure only appears when it meets real, unseen data. That hidden failure can lead you to deploy a model that disappoints in the real world.
How do I fix overfitting?
Reduce the model's ability to memorise and encourage generalisation: use more training data, simplify the model, apply techniques that discourage over-complexity, or stop training before it memorises. The diagnosis points you to the remedy.
How do I fix underfitting?
Give the model more capacity or better inputs: use a more capable model, provide better or more informative features, train it more thoroughly, and ensure the data actually contains the signal you want to learn.
What is the trade-off between them?
They sit at opposite ends of a scale — making a model more complex risks overfitting, simplifying it risks underfitting. Machine learning involves tuning to find the balanced middle for your data, guided by the training-versus-test comparison.
Where can I learn these machine learning concepts properly?
Ghana School of Artificial Intelligence teaches core concepts like overfitting, underfitting and generalisation with clear explanations and hands-on practice, so you build genuine understanding rather than just memorising terms.
Do overfitting and underfitting matter in real applications?
Very much. An overfitted loan model makes unreliable decisions on new applicants despite great test scores; an underfitted health tool misses cases it should catch. These failures cost money, trust or wellbeing, so understanding the balance is practical, not just theoretical.
Is some overfitting or underfitting always present?
In practice, yes — no model is perfectly balanced, so there is always a little of one or the other. The goal is not perfection but landing close enough to the balanced middle that the model generalises well to new data. You manage it, rather than eliminating it entirely.
Does more data help with overfitting?
Often, yes. More good training data gives the model more examples to learn the genuine pattern from, making it harder to simply memorise noise. It is one of the most reliable ways to reduce overfitting, alongside simplifying the model or using techniques that discourage over-complexity.

Your AI journey can start in Kasoa — or anywhere in Ghana

Turn what you have learned into real, job-ready skills. Learn on campus in Opeikuma, Kasoa, or live online, build a portfolio of real projects, and earn a verifiable certificate with career support until you land the role.

GH

Ghana School of Artificial Intelligence

We train beginners and professionals into job-ready AI builders through hands-on, project-based learning — on campus in Kasoa and live online across Ghana. Every article is written to be practical, accurate and genuinely useful for Ghanaians.