程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The problem of computing Python matrix

編輯:Python

# 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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved