Skip to content

Instantly share code, notes, and snippets.

@curiousily
Last active April 1, 2019 21:13
Show Gist options
  • Save curiousily/913c83b8334d6fa5a4cb8444c83686a5 to your computer and use it in GitHub Desktop.
Save curiousily/913c83b8334d6fa5a4cb8444c83686a5 to your computer and use it in GitHub Desktop.
class LinearRegression:
def predict(self, X):
return np.dot(X, self._W)
def _gradient_descent_step(self, X, targets, lr):
predictions = self.predict(X)
error = predictions - targets
gradient = np.dot(X.T, error) / len(X)
self._W -= lr * gradient
def fit(self, X, y, n_iter=100000, lr=0.01):
self._W = np.zeros(X.shape[1])
for i in range(n_iter):
self._gradient_descent_step(x, y, lr)
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment