Skip to content

Instantly share code, notes, and snippets.

@codeperfectplus
Last active June 3, 2020 10:41
Show Gist options
  • Save codeperfectplus/a7dca4f25c45804909e08ed241e74162 to your computer and use it in GitHub Desktop.
Save codeperfectplus/a7dca4f25c45804909e08ed241e74162 to your computer and use it in GitHub Desktop.
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=100, n_features=1, noise=0.1)
def LinearRegression(X, y, m_current=0, b_current=0, epochs=2000, learning_rate = 0.001):
N = float(len(y))
for i in range(epochs):
y_current = m_current * X + b_current
m_gradient = (-2/N) * sum(y-y_current) * X
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
m, b = LinearRegression(X, y)
print(m , b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment