损失函数的代码表示 import numpy as np def computeCost(X, y, theta): inner = np.power(((X*theta.T) - y), 2) return np.sum(inner) / (2*len(X)) 正规方程的代码表示 import numpy as np def normalEqn(X, y): theta = np.linalg.inv(X.T@X)@X.T@y #X.T@X 等价于 X.T.dot(X)