Guest User

Untitled

a guest
Mar 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. def linear_regression(X, y, m_current=0, b_current=0, epochs=1000, learning_rate=0.0001):
  2. N = float(len(y))
  3. for i in range(epochs):
  4. y_current = (m_current * X) + b_current
  5. cost = sum([data**2 for data in (y-y_current)]) / N
  6. m_gradient = -(2/N) * sum(X * (y - y_current))
  7. b_gradient = -(2/N) * sum(y - y_current)
  8. m_current = m_current - (learning_rate * m_gradient)
  9. b_current = b_current - (learning_rate * b_gradient)
  10. return m_current, b_current, cost
Add Comment
Please, Sign In to add comment