Work in progress
This commit is contained in:
21
PytorchTutorialCodes/1_linearregression_1.py
Normal file
21
PytorchTutorialCodes/1_linearregression_1.py
Normal file
@ -0,0 +1,21 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Valódi mért adatok
|
||||
x_real = np.array([1,2,3,4,5,6,7,8,9,10])
|
||||
y_real = np.array([6,8,9,11,13,14,15,17,18,20])
|
||||
|
||||
# Lineáris regresszió illesztése
|
||||
coeffs = np.polyfit(x_real, y_real, 1) # 1. fokú polinom = egyenes || Visszaad egy tömböt, ami az egyenes együtthatóit tartalmazza: [meredekség, tengelymetszet].
|
||||
print(coeffs)
|
||||
lin_y = coeffs[0]*x_real + coeffs[1] # Kiszámolja az egyenes y értékeit minden x_real pontra. y = mx + n
|
||||
|
||||
# Ábrázolás
|
||||
plt.scatter(x_real, y_real, color='blue', label='Valódi mért pontok')
|
||||
plt.plot(x_real, lin_y, color='black', linestyle='--', label='Lineáris regresszió')
|
||||
plt.xlabel('Reklámba fektetett összeg (millió Ft)')
|
||||
plt.ylabel('Eladott jegyek (ezer db)')
|
||||
plt.title('Valódi adatok és lineáris regresszió')
|
||||
plt.legend()
|
||||
plt.grid(True)
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user