Skip to content

Instantly share code, notes, and snippets.

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