Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def step_gradient(c_current, m_current, points, learning_rate):
- # Gradient descent
- c_gradient = 0
- m_gradient = 0
- N = float(len(points))
- # Iterate
- for i in range(0, len(points)):
- x = points[i, 0]
- y = points[i, 1]
- c_gradient += -(2 / N) * (y - ((m_current * x) + c_current))
- m_gradient += -(2 / N) * x * (y - ((m_current * x) + c_current))
- # Update m and c
- new_c = c_current - (learning_rate * c_gradient)
- new_m = m_current - (learning_rate * m_gradient)
- return [new_c, new_m]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement