def computeStep(X, y, theta):
'''YOUR CODE HERE'''
function_result = np.array([0,0], dtype= np.float)
m = float(len(X))
d1 = 0.0
d2 = 0.0
for i in range(len(X)):
h1 = np.dot(theta.transpose(), X[i])
c1 = h1 - y[i]
d1 = d1 + c1
j1 = d1/m
for u in range(len(X)):
h2 = np.dot(theta.transpose(), X[u])
c2 = (h2 - y[u]) * X[u][1]
d2 = d2 + c2
j2 = d2/m
function_result[0] = j1
function_result[1] = j2
return function_result
# Part 4: Implement the cost function calculation
评论列表
文章目录