Overfitting vs underfitting: the bias-variance trade-off explained
A model that memorises fails on new data; a model that is too simple fails everywhere. How to recognise overfitting and underfitting, what bias and variance mean, and the practical fixes.
Overfitting means a model has memorised its training data, including noise, so it performs well there but poorly on new data. Underfitting means the model is too simple to capture the real pattern and performs poorly everywhere. The bias-variance trade-off describes the balance between them, and the goal is a model that generalises to data it has never seen.
Every machine learning project runs into this problem, and it is one of the most common interview topics. The good news is that it is easy to detect if you split your data properly, and there are reliable fixes.
What do overfitting and underfitting look like?
What are bias and variance?
How do you detect overfitting?
Hold out data the model never trains on. Split your data into training, validation and test sets, or use cross-validation for smaller datasets. If training accuracy is much higher than validation accuracy, the model is overfitting. Plotting training and validation loss over time shows the moment validation loss starts rising while training loss keeps falling.
Data leakage creates fake good results: information from the test set sneaking into training, such as scaling data before splitting or using features that would not be known at prediction time. Leakage hides overfitting until the model fails in production.
How do you fix overfitting?
How do you fix underfitting?
What does this look like in a real project?
Suppose you predict delivery times for a food platform in Bengaluru. A linear model on distance alone underfits: it ignores traffic and restaurant load. A very deep tree trained on a small dataset overfits: it memorises that one restaurant was slow on one rainy Tuesday. A gradient-boosted model with sensible features such as distance, time of day, weather and restaurant load, tuned with cross-validation, generalises well. Testing on later weeks, not random rows, confirms it works on the future.
Does this apply to deep learning and LLMs?
Yes, though large models behave in some surprising ways, sometimes generalising well despite having more parameters than training examples. Fine-tuning a language model on a small dataset can still overfit: it starts repeating training examples or loses general ability. Evaluation on held-out data remains the safeguard. Our guide to evaluating LLM applications covers that side.
How much data do you need to avoid overfitting?
There is no fixed number; it depends on the model’s complexity and how noisy the problem is. A useful rule is to compare learning curves: train on increasing amounts of data and watch validation performance. If it keeps improving, more data will help; if it has flattened, you need better features or a different model instead. Transfer learning, starting from a pretrained model, sharply reduces how much data you need for images and text.
What is the difference between validation and test sets?
The validation set guides your choices during development: which model, which settings, when to stop training. The test set is touched once, at the very end, to report how the final model performs on unseen data. If you tune against the test set, it stops being an honest estimate, and your reported results will be optimistic.
How do you explain this in an interview?
State the definitions, describe how you detected the problem with a validation set or curves, explain the fix you chose and why, and mention leakage. A concrete example from your own project is far more convincing than textbook definitions. Our guide to data science portfolio projects shows how to present that.
Program Zero covers model evaluation, cross-validation and the bias-variance trade-off in its classical machine learning phase and regularisation for neural networks in the deep learning phase.
Program Zero runs live online, so you can learn this from anywhere in India: metros such as Chennai, Hyderabad, Bengaluru and Pune, growing cities such as Coimbatore, Kochi, Indore and Nagpur, and smaller towns such as Ranchi, Patna, Bhubaneswar and Raipur. Every learner joins the same evening classes, at the same fee.
Want to learn this live, with mentors?
Program Zero is Careers Ninza’s 18-month live programme in AI, LLMs and full-stack development: classes Monday to Friday, 9:00–10:30 PM IST, all recorded, Saturday projects and Sunday doubt sessions. ₹17,999 for all 18 months; the batch starts 9 January 2027.
Learn AI, large language models and full-stack development live with mentors: from your first line of code to building and deploying your own language model.
Frequently asked questions
Related reading
We teach this, live
Every article here comes from something we teach. Sit in on a free masterclass and judge the mentors yourself.