Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def linear_regression(X, y, m_current=0, b_current=0, epochs=1000, learning_rate=0.0001):
- N = float(len(y))
- for i in range(epochs):
- y_current = (m_current * X) + b_current
- cost = sum([data**2 for data in (y-y_current)]) / N
- m_gradient = -(2/N) * sum(X * (y - y_current))
- b_gradient = -(2/N) * sum(y - y_current)
- m_current = m_current - (learning_rate * m_gradient)
- b_current = b_current - (learning_rate * b_gradient)
- return m_current, b_current, cost
Add Comment
Please, Sign In to add comment