File:Traintest uk.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 720 × 270 pixels, file size: 38 KB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
English: Plots showing a training set and a test set from the same statistical population. Two curves are fit to the training set, one of which is an overfit. By plotting these curves with the test data, the overfitting can be seen. Labelled in Ukrainian.
Українська: Графіки, що показують тренувальний та випробувальний набори з однієї й тієї же статистичної сукупності. До тренувального набору допасовано дві криві, одна з яких є перенавченою. Відклавши ці криві разом з випробувальними даними, можливо побачити це перенавчання.
Date
Source
Author
Other versions

[edit]

SVG development
InfoField
 
The SVG code is valid.
 
This plot was created with Matplotlib.
Source code
InfoField

Python code

import numpy as np
import matplotlib.pyplot as plt

m = 0.2 ## сітка на абсцисі
s = 3 ## стандартне відхилення похибок

def pdesign(X, d):
    """Породити поліноміальну матрицю плана на X порядку d."""
    V = X[:,np.newaxis]
    F = [V**k for k in range(d+1)]
    D = np.concatenate(F, axis=1)
    return D

def regfit(Y, D):
    """Побудувати регресію Y на D із застосуванням найменших квадратів."""
    U,S,Vt = np.linalg.svd(D,0)
    V = np.transpose(Vt)
    return np.dot(U, np.dot(np.transpose(U), Y))

X = np.arange(-2, 2, m, dtype=np.float64)

D1 = pdesign(X, 3)
D2 = pdesign(X, 13)

EY = X + X**3
Y1 = EY + np.random.normal(size=len(X))*s ## [-7.901482, -2.764213, -1.383876, -8.100520, -2.873116, -0.344636, -1.117144, -4.933910, -0.848361, 3.265164, 1.842207, 2.015817, 9.534801, 0.891035, 5.092503, 5.912057, -1.226368, 7.750029, 5.670956, -1.648104]
Y2 = EY + np.random.normal(size=len(X))*s ## [-8.637744, -6.147082, -7.329850, -4.124987, -2.021752, 0.551831, -0.123082, 1.197885, -3.256714, 2.690225, 0.156213, 3.253439, -0.812854, -1.382195, 0.785456, 4.674591, 7.013887, 8.200408, 12.500000, 5.590095]

Yhat1 = regfit(Y1, D1)
Yhat2 = regfit(Y1, D2)

plt.clf()
plt.figure(figsize=(8,3))
ax1 = plt.axes([0.06,0.1,0.4,0.8])
plt.title("Тренувальний набір")
plt.plot(X, Y1, 'o')
#plt.hold(True)
plt.plot(X, Yhat1, '-', color='green')
plt.plot(X, Yhat2, '-', color='orange')
ax1.set_ylim(-10, 10)
ax1.set_xticks([-2,-1,0,1,2])
ax2 = plt.axes([0.56,0.1,0.4,0.8])
plt.title("Випробувальний набір")
plt.plot(X, Y2, 'o')
plt.plot(X, Yhat1, '-', color='green')
plt.plot(X, Yhat2, '-', color='orange')
ax2.set_xticks([-2,-1,0,1,2])
ax2.set_ylim(-10, 10)
plt.savefig("traintest uk.png")
plt.savefig("traintest uk.svg")

print(((Yhat1-Y1)**2).mean())
print(((Yhat2-Y1)**2).mean())

print(((Yhat1-Y2)**2).mean())
print(((Yhat2-Y2)**2).mean())

Licensing[edit]

w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 3.0 Unported 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.

File history

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

Date/TimeThumbnailDimensionsUserComment
current09:39, 6 July 2020Thumbnail for version as of 09:39, 6 July 2020720 × 270 (38 KB)Olexa Riznyk (talk | contribs)Uploaded a work by * File:Traintest.svg: {{Ut|Skbkekas}} * derivative work: {{Ut|Olexa Riznyk}} from * File:Traintest.svg with UploadWizard

File usage on other wikis

Metadata