x=[300,400,400,550,720,850,900,950]
y=[300,350,490,500,600,610,700,660]
import numpy as np
x_array = np.array(x)
y_array = np.array(y)
x_mean = np.mean(x_array)
y_mean = y_array.mean()
print(x_mean, y_mean)
a=((x_array-x_mean).dot(y_array-y_mean))/((x_array-x_mean)@(x_array-x_mean))
b=y_mean-a*x_mean
print(a,b)
633.75 526.25
0.530960991635149 189.75347155122432
import matplotlib.pyplot as plt
plt.plot(x,y, "ro")
m = np.linspace(0, 1000, 100)
plt.plot(m, a*m+b)
plt.xlabel("X")
plt.ylabel("Y")
plt.title("linear regression")
plt.show()