I have the following X and y matrices:
for which I want to calculate the best value for theta for a linear regression equation using the normal equation approach with:
theta = inv(X^T * X) * X^T * y
the results for theta should be : [188.400,0.3866,-56.128,-92.967,-3.737]
I implement the steps with:
X=np.matrix([[1,1,1,1],[2104,1416,1534,852],[5,3,3,2],[1,2,2,1],[45,41,30,36]])
y=np.matrix([460,232,315,178])
XT=np.transpose(X)
XTX=XT.dot(X)
inv=np.linalg.inv(XTX)
inv_XT=inv.dot(XT)
theta=inv_XT.dot(y)
print(theta)
But I dont't get the desired results. Instead it throws an error with:
Traceback (most recent call last): File "C:/", line 19, in theta=inv_XT.dot(y) ValueError: shapes (4,5) and (1,4) not aligned: 5 (dim 1) != 1 (dim 0)
What am I doing wrong?