Home / Machine Learning

The Bias-Variance Tradeoff

Explicitly control Bias and Variance to understand how models generalize. Use the Resample button to visualize the instability of High Variance models!

80%
10%
System Diagnosis

IDEAL BALANCE

Model accurately captures the trend without memorizing the noise.
Live Fit View
Train Data
Val Data
Model Prediction
True Function
Click "Resample Data" repeatedly to visualize Variance!

Training Error (MSE)

Error on the blue dots. High Error indicates High Bias (Underfitting). 0.000

Variance Gap

Difference between Val and Train. High Gap indicates High Variance (Overfitting). 0.000

Total Error (Val MSE)

Overall performance on unseen orange dots. The ultimate metric. 0.000

Deconstructing the Bias-Variance Tradeoff

The Bias-Variance Tradeoff is one of the most fundamental concepts in machine learning. It describes the delicate balance between a model's ability to fit the training data and its ability to generalize to new, unseen data. Mastering this concept is key to diagnosing model performance and building effective predictive models. This interactive lab lets you directly manipulate bias and variance to see their effects in real-time.

Core Concepts: Bias vs. Variance

Every machine learning model's error can be decomposed into three parts: Bias, Variance, and Irreducible Error. We'll focus on the first two.

High Bias (Underfitting)

Bias represents the simplifying assumptions made by a model to make the target function easier to learn. A high-bias model is too simple; it fails to capture the underlying trend in the data. This leads to high error on both the training and validation datasets. Think of it as a rigid, stubborn model that ignores the data's complexity.

High Variance (Overfitting)

Variance represents the model's sensitivity to small fluctuations in the training data. A high-variance model is too complex; it pays too much attention to the noise in the training data. It fits the training data extremely well but fails to generalize to new data. Think of it as a nervous, flexible model that memorizes the data instead of learning from it.

The "tradeoff" implies that you can't just minimize both at the same time. Increasing a model's complexity will typically decrease its bias but increase its variance, and vice-versa.

Interpreting the Visualization

This lab gives you direct control over a model's bias and variance to see how they affect the fit.

  • The Sliders: The Bias slider controls the model's rigidity. High bias forces a simpler model (like a straight line). The Variance slider controls the model's flexibility or "wiggliness." High variance allows the model to contort itself to fit every data point.
  • The Data: The blue and orange dots represent your dataset, sampled from a "true" underlying function (the dashed line), with some random noise added.
  • The Goal: Your goal is to find a balance that minimizes the Total Error (Val MSE). This is the ultimate measure of your model's performance on unseen data.
  • The "Resample Data" Button: This is the most important button! Clicking it simulates getting a completely new dataset from the same underlying source. It powerfully demonstrates the concept of variance: a high-variance model will change drastically with each new sample, while a low-variance model will remain stable.

Guided Experiments

Try these experiments to build a strong intuition.

  1. Simulate High Bias (Underfitting): Set the Bias slider to a high value (e.g., 90%) and Variance to a low value (e.g., 10%). Notice that the model is a very simple curve that fails to capture the true trend. The Training Error is high. Now, click Resample Data several times. The model's prediction curve barely moves. This is the definition of low variance but high bias.
  2. Simulate High Variance (Overfitting): Set Bias to a low value (e.g., 10%) and Variance to a high value (e.g., 90%). The model will weave through the training points almost perfectly, resulting in a very low Training Error. However, the Variance Gap will be huge, indicating poor generalization. Now, click Resample Data repeatedly. The prediction curve will change wildly each time, chasing the noise in the new sample. This is a high-variance model.
  3. Find the "Sweet Spot": Start with both sliders in the middle. Try to adjust them to find the lowest possible Total Error (Val MSE). You'll likely find this "sweet spot" somewhere in the middle, where the model is complex enough to capture the trend but not so complex that it memorizes the noise. This is the essence of the tradeoff.

Key Takeaways

  • The Goal is Generalization: A low training error is meaningless if the validation error is high. The goal is always to build a model that performs well on data it has never seen before.
  • Underfitting (High Bias): Your model is too simple. Symptoms: High training error and high validation error.
  • Overfitting (High Variance): Your model is too complex. Symptoms: Very low training error but high validation error. The gap between them is large.
  • The Tradeoff is Real: As you decrease bias by making your model more complex (e.g., adding more features or layers), you almost always increase its variance. The art of machine learning is finding the right level of complexity for the given data.
Cheat sheet

Bias vs Variance

Explicitly control Bias and Variance to understand how models generalize. Use the Resample button to visualize the instability of High Variance models!

MACHINE LEARNING · vizlearn.in/machine_learning/bias_vs_variance.html