-
-
Save amankharwal/a76b437b56be07115c36fceccb6d5e7f to your computer and use it in GitHub Desktop.
This file contains 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
# Batch Gradient Descent | |
import numpy as np | |
eta = 0.1 # learning rate | |
n_iterations = 1000 | |
m = 100 | |
X = 2 * np.random.rand(100, 1) | |
y = 4 + 3 * X + np.random.randn(100, 1) | |
X_b = np.c_[np.ones((100, 1)), X] # add x0 = 1 to each instance | |
theta = np.random.randn(2,1) #random initilization | |
for iteration in range(n_iterations): | |
gradients = 2/m * X_b.T.dot(X_b.dot(theta)-y) | |
theta = theta - eta * gradients | |
print(theta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment