Skip to content

Instantly share code, notes, and snippets.

@yvan
Last active October 28, 2017 16:26
Show Gist options
  • Save yvan/d58e474560660fa7817e9e05eeb49354 to your computer and use it in GitHub Desktop.
Save yvan/d58e474560660fa7817e9e05eeb49354 to your computer and use it in GitHub Desktop.
# performs the gradient descent for linear regression
def calc_regression_simple(w1, frames, x_data, y_data):
learn_rate = 0.001
ys = []
for i in range(frames):
# get the gradient and update the parameter
w1_gradient = 2*np.mean(x_data*(w1*x_data - y_data))
w1 = w1 - (w1_gradient*learn_rate)
# calculate the predictions from this new function
x = np.linspace(0,30)
ys.append(w1 * x)
# returns each linear regsession y values
# at each step, x values don't change
return ys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment