def gradient(X,y,theta):
grad = np.zeros(theta.shape)#创建一个行列和数组theta相同的0数组
error = (model(X,theta)-y).ravel()#model上一个博客的预测函数
for j in range(len(theta.ravel())):
term = np.multiply(error,X[:,j])
grad[0,j] = np.sum(term)/len(X)
return grad
def gradient(X,y,theta):
grad = np.zeros(theta.shape)#创建一个行列和数组theta相同的0数组
error = (model(X,theta)-y).ravel()#model上一个博客的预测函数
for j in range(len(theta.ravel())):
term = np.multiply(error,X[:,j])
grad[0,j] = np.sum(term)/len(X)
return grad