I wonder if you all know if backend of sklearn's LinearRegression Module uses something different to calculate the optimal beta coefficients. I implemented my own using the closed form solution
if self.solver == "Closed Form Solution":
### optimal beta = (XTX)^{-1}XTy
XtX = np.transpose(X, axes=None) @ X
XtX_inv = np.linalg.inv(XtX)
Xty = np.transpose(X, axes=None) @ y_true
self.optimal_beta = XtX_inv @ Xty
However, I do not get an exact match when I print the coefficients comparing with sklearn's one. I thought that having a closed form solution may guarantee similar results (my code doesn't handle not invertible).
I noticed the MSE are not that far apart, but it just makes me wonder if my implementation is wrong (i took in account of biases)
The deviations seem to appear in the intercept:
SKLEARN INTERCEPT 1.2490009027033011e-15
HN INTERCEPT 4.440892098500626e-16
First Value HN 183.22200150945497
First Value SKLEARN 183.22200150945548
HN MSE 3.1084228599404546e-27
SKLEARN MSE 2.126667544039961e-25