Created
October 7, 2018 04:45
-
-
Save bgreatfit/56b87629c83f85991b964da18e2c56a1 to your computer and use it in GitHub Desktop.
Gradient Descent
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
| #gradient descent | |
| def gradientDescent(X,y,theta,iters,alpha): | |
| cost = np.zeros(iters) | |
| for i in range(iters): | |
| theta = theta - (alpha/len(X)) * np.sum(X * (X @ theta.T - y), axis=0) | |
| cost[i] = computeCost(X, y, theta) | |
| return theta,cost | |
| #running the gd and cost function | |
| g,cost = gradientDescent(X,y,theta,iters,alpha) | |
| print(g) | |
| finalCost = computeCost(X,y,g) | |
| print(finalCost) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment