Created
August 25, 2017 03:31
-
-
Save kangeugine/3bc6fc098ca058f3204a459655332fd0 to your computer and use it in GitHub Desktop.
Ordinary Least Square
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
def ols(x,y): | |
x_mean = x.mean() | |
y_mean = y.mean() | |
beta_1 = np.multiply((x - x_mean), (y - y_mean)).sum() / np.square((x - x_mean)).sum() | |
beta_0 = y_mean - (beta_1 * x_mean) | |
def lin_model(new_x, slope=beta_1, intercept=beta_0): | |
return new_x * slope + intercept | |
return lin_model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment