Code:
testdata = np.array([[20.5, 765], [32.7, 826], [51.0, 873], [73.2,942], [95.7,1032]])
def LinearLeastSquares(data):
x=np.array(data[:,:1])
y=np.array(data[:,1:2])
n=len(data)
A=np.sum(np.array([[x**2 , x ], [x , n]]))
B=np.sum(np.array([x*y , y]))
print(A,B) #To check outputs
return
The result I'm looking for is a 2x2 array and a 2x1 array, where each position is represented by summing through each value of testdata array (depending on what is required) and outputting numbers. My primary issue is that I am expecting a 2x2 array and a 2x1 array to be returned, but instead I am getting the following for A and B respectively when I run LinearLeastSquares(testdata):
[[ 466.25]
[1139.69]
[2708. ]
[5509.64]
[9354.89]] 259370.5
On top of the output not having the correct dimensions, the calculations aren't correct either although there are some numbers that are relatively close, but not all of them. Any help is appreciated.