Skip to content

Commit e859849

Browse files
author
codebasics
committed
sgd
1 parent 33084b6 commit e859849

File tree

8 files changed

+1503
-0
lines changed

8 files changed

+1503
-0
lines changed

DeepLearningML/8_sgd_vs_gd/gd_and_sgd.ipynb

Lines changed: 707 additions & 0 deletions
Large diffs are not rendered by default.

DeepLearningML/8_sgd_vs_gd/gradient_descent.ipynb

Lines changed: 91 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import numpy as np
2+
3+
def gradient_descent(x,y,epochs):
4+
m_curr = b_curr = 0
5+
n = len(x)
6+
learning_rate = 0.08
7+
8+
for i in range(epochs):
9+
y_predicted = m_curr * x + b_curr
10+
cost = (1/n) * sum([val**2 for val in (y-y_predicted)])
11+
md = -(2/n)*sum(x*(y-y_predicted))
12+
bd = -(2/n)*sum(y-y_predicted)
13+
m_curr = m_curr - learning_rate * md
14+
b_curr = b_curr - learning_rate * bd
15+
print ("m {}, b {}, cost {} iteration {}".format(m_curr,b_curr,cost, i))
16+
17+
x = np.array([1,2,3,4,5])
18+
y = np.array([5,7,9,11,13])
19+
20+
gradient_descent(x,y, 500)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
area,bedrooms,age,price
2+
2600,3,20,550000
3+
3000,4,15,565000
4+
3200,3,18,610000
5+
3600,3,30,595000
6+
4000,5,8,760000
7+
4100,6,8,810000
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
area,bedrooms,price
2+
1056,2,39.07
3+
2600,4,120
4+
1440,3,62
5+
1521,3,75
6+
1200,2,51
7+
1170,2,38
8+
2732,4,135
9+
3300,4,155
10+
1310,3,50
11+
3700,5,167
12+
1800,3,82
13+
2785,4,140
14+
1000,2,38
15+
1100,2,40
16+
2250,3,101
17+
1175,2,42
18+
1180,3,48
19+
1540,3,60
20+
2770,3,102
21+
800,1,32

DeepLearningML/8_sgd_vs_gd/hp.jpg

20.9 KB
Loading

0 commit comments

Comments
 (0)