# When calculating the loss function , Always reporting mistakes
# existing :X by (97, 2) Of dataframe
#y by (97,1) Of dataframe
#theta by (1,2) Of dataframe
# The code is as follows :
def Compute_cost(theta, X, y): total_cost = (X*theta.T-y)**2 m = len(y) J = total_cost/(2*m) return J
print(Compute_cost(theta,X,y))
# Operation results and error reporting contents
Unable to coerce to DataFrame, shape must be (97, 2): given (2, 1)
# Guess it might be dataframe Of type problem , use np.mat() transformation theta After that, the problem still exists
【 Graduation project recommend
List of articles Data acquisi