Last active
October 28, 2017 17:13
-
-
Save yvan/4ac67e0eb8998ba3544fa5241f943678 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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
# calculate the cost at -5 | |
def f(w1): | |
return np.mean((w1*data['speed'] - data['dist'])**2) | |
w1 = -5 | |
h = 0.1 | |
x_tan = np.linspace(-10, 0, 15) | |
gradient = (f(w1+h)-f(w1))/h # derivative | |
tan = f(w1)+gradient*(x_tan-w1) # tangent | |
# plot the costs | |
plt.plot(range(-10,11,1), costs) | |
plt.plot(x_tan, tan, color='red') | |
plt.plot([-5], [f(-5)], marker='o', color='red') | |
plt.xlabel('w1') | |
plt.ylabel('cost') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment