'Numpy Solving two matrices
I have two matrix, A & B and i'm trying to find the Coeficients to make them fit. I know what i should be finding but i can't get anywhere close to it (Matrix C is the excpected results). I tested linear regression but I don't get the expected result
What is the way to find the good Results
import numpy as np
from sklearn.linear_model import LinearRegression
A = np.array([40, -25, 60, 0,-30,-12.5,-12.5,-30,50,30,-50])
B = np.array([[1,1,1,0,0,-1,-1,-1,0,0],
[1,1,1,0,0,-1,-1,0,-1,0],
[1,0,0,1,1,-1,0,0,-1,-1],
[1,0,0,1,1,0,0,-1,-1,-1],
[0,1,1,1,0,0,-1,-1,-1,0],
[0,1,1,0,1,0,-1,-1,0,-1],
[1,1,1,0,0,0,-1,0,-1,-1],
[1,1,1,0,0,-1,0,0,-1,-1],
[0,0,1,1,1,-1,0,0,-1,-1],
[1,0,1,1,0,-1,-1,-1,0,0],
[1,0,0,1,1,0,-1,-1,-1,0]])
C = np.array([-30.50,0.00,-56.00,36.50,-31.75,-65.50,-38.25,8.25,40.50,-60.75]) #expected Result
At = np.transpose(B).dot(A)
Bt = np.transpose(B).dot(B)
reg = LinearRegression().fit(Bt, At)
print("Regression result : " + reg.coef_)
Output :
[-10.75 19.75 -36.25 56.25 -12. -45.75 -18.5 28. 60.25 -41. ]
Process finished with exit code 0
After Transposing :
Result :
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|



