Created
February 11, 2019 09:50
-
-
Save nithyadurai87/86bd4ec2288d0e9af138a30a7af44a09 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
import matplotlib.pyplot as plt | |
x = [1, 2, 3] | |
y = [1, 2, 3] | |
m = len(y) | |
def cost_function(theta0,theta1): | |
predicted_y = [theta0+(theta1*1), theta0+(theta1*2), theta0+(theta1*3)] | |
sum=0 | |
for i,j in zip(predicted_y,y): | |
sum = sum+((i-j)**2) | |
J = 1/(2*m)*sum | |
return (J) | |
theta0 = [1.5,0,1] | |
theta1 = [0,1.5,0.5] | |
for i,j in zip(theta0,theta1): | |
print ("cost when theta0=%r theta1=%r :"%(i,j), cost_function(i,j)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment