Jump to content

File:Bias-variance decomposition.png

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file (1,000 × 600 pixels, file size: 141 KB, MIME type: image/png)

Summary

Description
English: Bias-variance decomposition in the case of mean squared loss. The green dots are samples of test label at a fixed test feature . Their variance around the mean is the irreducible error . The red dots are test label predictions as the training set is randomly sampled. Their variance around the mean is the variance . The difference between the red dash and the green dash is the bias . The bias-variance decomposition is then visually clear: the mean squared error between the red dots and the green dots is the sum of the three components.

Matplotlib code

import numpy as np
import matplotlib.pyplot as plt

# Set random seed for reproducibility
np.random.seed(42)

# Create figure and axis
fig, ax = plt.subplots(figsize=(10, 6))

# Remove y-axis and x-ticks
ax.yaxis.set_visible(False)
ax.set_xticks([])

# Set x_0
x_0 = 0

xmin, xmax = -np.pi /3 , np.pi/3
x = np.linspace(xmin, xmax, 1000)

# Plot curves
for _ in range(200):
    epsilon = np.random.normal(0, 0.1)
    y = 1 + (1 + epsilon) * np.cos(x) + epsilon
    ax.plot(x, y, color='blue', alpha=0.1)

n_points = 500
x_jitter = np.random.normal(x_0, 0.01, n_points)
y_values = 1 + (1 + np.random.normal(0, 0.1, n_points)) * np.cos(x_0) + np.random.normal(0, 0.2, n_points)
ax.scatter(x_jitter, y_values, color='red', alpha=0.5, s=1, label=r"$f(x

Date
Source Own work
Author Cosmia Nebula

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

15 September 2024

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current01:47, 16 September 2024Thumbnail for version as of 01:47, 16 September 20241,000 × 600 (141 KB)Cosmia NebulaUploaded while editing "Bias–variance tradeoff" on wiki.riteme.site

The following page uses this file:

Metadata