Last active
March 10, 2019 00:28
-
-
Save damntoochill/e9391862dadaa82817bf2d51a68ecb21 to your computer and use it in GitHub Desktop.
WildRoyalPhases created by damntoochill - https://repl.it/@damntoochill/WildRoyalPhases
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 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