Created
March 13, 2018 19:31
-
-
Save llSourcell/f198dfd4ef5bd373500c9f0950eb54b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment