Find Coefficients

import numpy as np
import matplotlib.pyplot as plt
x = np.array([1, 2, 3, 4, 4])
y = np.array([2, 4, 6, 8, 9])
print(x)
[1 2 3 4 4]
print(y)
[2 4 6 8 9]
size = np.size(x)
x_mean = np.mean(x)
print(x_mean)
2.8
y_mean = np.mean(y)
print(y_mean)
5.8
SS_xy = np.sum(y * x - (size * y_mean * x_mean))
print(SS_xy)
-309.99999999999994
SS_xx = np.sum(x * x - (size * x_mean * x_mean))
print(SS_xx)
-149.99999999999997
# Calculate regression coefficients
a1 = SS_xy / SS_xx
b1 = y_mean - (a1 * x_mean)
coeff = b1, a1
print(coeff)
(0.013333333333332753, 2.066666666666667)