Navigating the Bias-Variance Trade-Off: A Balancing Act in Machine Learning

data science Sep 29, 2023
bias variance trade off

Are you curious about what 'bias-variance trade-off' means in data science and machine learning

Wondering why it matters so much when you're trying to build accurate machine learning models?

Let's break it down:

In this article you will learn

Data Science Explained In 20 Infographics

“Data Science Made Simple: Learn It All Through 20 Engaging Infographics (Completely Free)"


Bias-variance tradeoff using Analogy

Let me explain the bias variance tradeoff using an analogy.

Let’s say you are given a task to predict a mouse's height based on its weight.

To do this, you initially collect data on a bunch of mice and record their weights and heights as below. 

Then you have plotted the height and weight in a bias variance trade off graph as below.

 

The x-axis represents the weight of each mouse.  

 The y-axis represents the height of each mouse.

 

Now that you have the data plotted in a bias variance trade off graph, let’s see a couple of approaches on how you can use it to predict the height of a new mouse based on its weight and how the bias and variance trade off in machine learning plays around.

Understanding bias

Bias is when your model always predicts the same height for every mouse, regardless of its weight. 

 For e.g, if you draw a red horizontal line in the bias variance trade off graph below, it predicts the same height irrespective of the mouse’s weight, right?

 Looking at the arrows, if there is a mouse with weight as 26 grams, your model will predict the height as 3.2 cm.  

 If a mouse weighs 34 grams, then also your model predicts the height as 3.2 cm.

  
This would be a very simple model , right?

 This doesn't take into account the relationship between weight and height of the mouse. 

 Your model would have high bias in this case, and it would consistently make the wrong predictions.

"Bias is a systematic error that happens because the model is very simple and returns incorrect results."

With this understanding let’s see what variance means.

 

Understanding variance

Variance is when our model predicts wildly different heights for mice that have similar weights. 

 For e.g, instead of drawing a horizontal line, let’s say now you draw a red squiggly line in bias variance trade off graph as below.

 This would be a very complex model that tries to capture every little detail in the data, including noise or irrelevant patterns. 

 Looking at the arrows, if there is a mouse with weight as 25.5 grams, your model will predict the height as 3.8 cm, which is very tall for a small mouse.

 If a mouse weighs 29 grams, then your model predicts the height as 2.6 cm, which is short height for a reasonably weighing mouse.

 As you can , in this case your model would have high variance, and it would make unreliable predictions for new mice based on their weight.

"Variance is the measure of how much it deviates from the mean position and a high variance can make your model predict unreliable results."

Now that you have got a hold of a bias variance trade off in machine learning, and how a model either with high bias or high variance yields wrong results, let me explain what a balanced model with low bias & low variance looks like.

 Stay tuned!

 

Finding the sweet spot: Balancing bias and variance

To get the right balance between bias vs variance and understand the trade off between bias and variance in machine learning, , you need to build a model that can capture the underlying pattern between weight and height, without being too rigid or too flexible. 

 For instance, you build a model that says, on average, heavier mice tend to be taller, but there is also some variation in height for a given weight. 

 Look at the bias variance trade off graph,  the line doesn’t necessarily touch every data point and thereby it doesn’t have high variance.  

 Also notice that the line is also not simple as a straight line and so it doesn’t have high bias.

 Now your model captures the underlying pattern and it would have low bias and low variance.

 Now your model would make more accurate predictions for new mice based on their weight.

  So you understood what a model with low bias and low variance looks like. Let me explain how it applies in machine learning.

 

How does it apply in Machine Learning?

You want to find the right balance between bias and variance in machine learning to build a model that accurately predicts outcomes for new data.

"Your model should capture the underlying patterns in the data, but not be too rigid or too flexible in its predictions."

I also want you not to be surprised when someone says “a machine learning model is simple”.  

 Read below to know what it means when someone says “a machine learning model is simple” 

 

What do you mean by “a machine learning model is Simple”?

 If the model is too simple, it will have high bias and consistently make the wrong predictions. This is when our model tries to predict the same height for every mouse.

 Ok so do you know what it means when one says “a machine learning model is complex”

 

When do we say “a model is Complex”?

If the model is too complex, it will have high variance and make wildly different predictions for similar inputs. 

 This is when our model tries to predict using a complex squiggly line and captures all noises.

 Now that you have got the nuances on what it means a model is simple or complex, let me explain what the bias variance trade off in machine learning is?

 

What is the bias variance trade-off?

" Bias-variance trade-off simply means that you need to find the right balance between the bias and variance for the machine learning model to predict the outcomes optimally."

 This is called bias-variance trade-off

 

 

 

 



 

What is Underfitting?

What has Underfitting to do with bias-variance trade-off? High bias is generally associated with underfitting, which means your model is too simple and cannot capture the underlying patterns in the data. 

 In other words, your model is not fitting the training data well enough, and as a result, it also does not perform well on new data. 

When your model has high bias, it tends to make consistent but incorrect predictions for both the training and new data. 

 This is when your model tries to predict the same height for every mouse.

What is Overfitting?

High variance is generally associated with overfitting, which means your model is too complex and is fitting too closely to the training data, including noise or irrelevant patterns in the data. 

As a result, your model may not generalize well to new data and make different predictions for similar but new data

 This is when your model tries to predict weirdly different heights for the mouse.

 So anytime you hear “underfitting” , based on the above reading,  remember  keywords like “high-bias”, “red horizontal line graph”,  “model is too simple”, “makes consistent, but incorrect predictions”. They are all one and the same.

 

So anytime you hear “overfitting” , remember  keywords like “high-variance”, “red squiggly line graph”,  “model is too complex”, “records noise”,  “makes weird different predictions for similar but new data”

 

 

 

To achieve a good balance between bias and variance, you want to find the right level of model complexity that can capture the underlying patterns in the data without overfitting or underfitting.

  

Conclusion

In concluding our exploration of the bias-variance trade-off in machine learning, let's recap the key insights discussed

  • Explaining Bias and Variance: First, we looked at how simple models with bias often predict the same wrong things, while complex models with variance can be all over the place.

  • Balancing Bias and Variance: Next, we talked about why models should catch patterns without being too strict or too flexible. It's like finding a perfect balance.

  • Applying in Machine Learning: Then, we highlighted why having balanced models is so important. They help make accurate predictions when we use them on new information in real-life situations.

  • Dealing with Underfitting and Overfitting: We also discussed underfitting (when models are too simple) and overfitting (when models are too complex) as challenges to be aware of.

  • Why the Balance Matters: Lastly, we stressed how finding the right balance between bias and variance is a big deal for making the best predictions in machine learning. It really affects how well models work and how accurate they are. 

The Data Science Aspirant's 90-Day Proven Roadmap

Get INSTANT ACCESS to This Proven Roadmap To Become a Data Scientist in 90 Days,

Even Without Prior Data Science Experience - Guaranteed.

 


Question For You

In machine learning, what is the bias-variance trade-off primarily concerned with?

A) Minimizing the complexity of a model to make it more interpretable. 

B) Finding the right balance between underfitting and overfitting in a model. 

C) Maximizing the number of features in a dataset for better performance. 

D) Reducing the amount of training data to save computational resources.

Let me know in the comments!

Stay connected with weekly strategy emails!

Join our mailing list & be the first to receive blogs like this to your inbox & much more.

Don't worry, your information will not be shared.