Created
October 27, 2019 15:05
-
-
Save josetapadas/7aee41c14eca05d0013c81a3166f0ad2 to your computer and use it in GitHub Desktop.
Sample simple linear regression with 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
# initial values | |
b = 30 | |
m = 3 | |
db = 1 | |
dm = 1 | |
limit = 0.00001 | |
learning_rate = 0.001 | |
step_size_b = -3 | |
step_size_m = -3 | |
i = 0 | |
while abs(step_size_m) > limit: | |
i += 1 | |
step_size_b = db * learning_rate | |
b = b - step_size_b | |
db = (1/4) * ((-2*(50-(m*5+b))-2*(72-(m*10+b))-2*(76-(m*15+b))-2*(90-(m*20+b)))) | |
print("******** iteration: ", i) | |
print("b", b) | |
print("db", db) | |
print("step_size_b", step_size_b) | |
step_size_m = dm * learning_rate | |
m = m - step_size_m | |
dm = (1/4) * (-10*(50-(m*5+b))-20*(72-(m*10+b))-30*(76-(m*15+b))-40*(90-(m*20+b))) | |
print("m", m) | |
print("dm", dm) | |
print("step_size_m", step_size_m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment