Skip to content

Instantly share code, notes, and snippets.

@damntoochill
Last active March 10, 2019 00:28
Show Gist options
  • Save damntoochill/e9391862dadaa82817bf2d51a68ecb21 to your computer and use it in GitHub Desktop.
Save damntoochill/e9391862dadaa82817bf2d51a68ecb21 to your computer and use it in GitHub Desktop.
WildRoyalPhases created by damntoochill - https://repl.it/@damntoochill/WildRoyalPhases
import numpy as np
def Gradient_Descent(x,y):
iterations = 1000
n = len(x)
lr = 0.01
w_curr = b_curr = 0 #initialising the weights as 0
for i in range(iterations):
yhat = w_curr*x + b_curr
cost_func = sum((y-yhat)**2)
dw = -(1/n)*sum(2*x*(y-yhat))
db = -(1/n)*sum(2*(y-yhat))
w_curr = w_curr - lr*dw
b_curr = b_curr - lr*db
print("w {}, b {}, cost_val {}".format(w_curr, b_curr, cost_func))
x = np.array([1,2,3])
y = np.array([3,5,7])
Gradient_Descent(x,y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment