计算代价函数 ????(????)=12????Σ(ℎ????(????(????))−????(????))2
def computeCost(X,y,theta):
inner = np.power(X*theta.T - y, 2)
return np.sum(inner,axis=None)/(len(X)*2)
X = np.random.randint(low=10,size=(3,4))
y = np.random.randint(low=10,size=(3,1))
theta = np.random.rand(4,1)
Cost = computeCost(X,y,theta)
print(Cost )