Created
August 25, 2017 03:28
-
-
Save kangeugine/46adce00db7c072ad157958fa5b29c39 to your computer and use it in GitHub Desktop.
sample python code
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 | |
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