#在計算損失函數時,總是報錯
#已有:X 為(97, 2)的dataframe
#y為(97,1)的dataframe
#theta為(1,2)的dataframe
#代碼如下:
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))
#運行結果及報錯內容
Unable to coerce to DataFrame, shape must be (97, 2): given (2, 1)
#猜測可能是dataframe的type問題,用np.mat()轉換theta 後問題依然存在