File:Bias-variance decomposition.png

From testwiki
Jump to navigation Jump to search
    Original file (1,000 × 600 pixels, file size: 141 KB, MIME type: image/png)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: Bias-variance decomposition in the case of mean squared loss. The green dots are samples of test label y at a fixed test feature x. Their variance around the mean 𝔼y∼p(⋅|x)[y] is the irreducible error σ2. The red dots are test label predictions f(x|D) as the training set D is randomly sampled. Their variance around the mean 𝔼D[f(x|D)] is the variance VarD[f(x|D)]. The difference between the red dash and the green dash is the bias BiasD[f(x|D)]. 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.

    Python

    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

    image/png

    144,005 byte

    600 pixel

    1,000 pixel

    3e0654031a6b188530435ed4d5355cdec0c90ec6

    File history

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

    Date/TimeThumbnailDimensionsUserComment
    current02:47, 16 September 2024Thumbnail for version as of 02:47, 16 September 20241,000 × 600 (141 KB)wikimediacommons>Cosmia NebulaUploaded while editing "Bias–variance tradeoff" on en.wikipedia.org

    There are no pages that use this file.