-
-
Save SwampThingPaul/077f338f87a22dd12ccb01a523121596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from numpy.linalg import inv | |
import statsmodels.api as sm | |
# from scratch | |
x = sm.add_constant(x) # add constant in the 0 index | |
b = inv(x.T.dot(x)).dot(x.T).dot(y) | |
yest_ols = np.array([b[2]*v**2 + b[1]*v + b[0] for v in x.T[0]]) | |
# with using numpy.linalg.lstsq | |
b1, b2, c = np.linalg.lstsq(sm.add_constant(x).T[[1,2,0]].T, y_data, rcond=None)[0] | |
yest_ols_ = np.array([b2*v**2 + b1*v + c for v in data]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment