Challenge

Supervised Learning - Prediction Week 3 Challenge

import numpy as np
def gradient_descent(x,y):
#values of m and b
m_curr = b_curr = 0
#Initializing number of steps
iterations=1000
#Number of data points(n)
n=len(x)
#Learning rate
learning_rate = 0.001

for i in range(iterations):
y_p = m_curr * x + b_curr
cost= (1/n) * sum([val**2 for val in (y - y_p)])
md = -(2/n) * sum(x * (y - y_p))
bd = -(2/n) * sum(y - y_p)
m_curr = m_curr - learning_rate * md
b_curr = b_curr -learning_rate * bd
print(" m {} , b {} , cost {} , iterations {} , " .format(m_curr,b_curr,cost,iterations))
x = np.array([1,2,3,4,5])
y = np.array([5,7,9,11,13])

gradient_descent(x,y)

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.