def computeCost(x, y, theta):#代价函数
inner=np.power(((x*theta.T)-y),2)
return np.sum(inner)/(2*len(x))
data.insert(0,'ones',1)#data加一列1
#print(data.head())
cols=data.shape[1]#cols=data列数
X=data.iloc[:,0:cols-1]#pandas iloc提取前两列
Y=data.iloc[:,cols-1:cols]#pandas iloc提取后1列
x=np.matrix(X.values)
y=np.matrix(Y.values)
theta=np.matrix(np.array([0,0]))
#print(x.shape,theta.shape,y.shape)#看矩阵维度
print(computeCost((x, y, theta)))
Traceback (most recent call last):
File "D:\pythonProject\ml\work1.py", line 24, in
print(computeCost((x, y, theta)))
TypeError: computeCost() missing 2 required positional arguments: 'y' and 'theta'
函数computeCost缺少 2 个必需 位置参数
我这里不是已经定义了y和theta了吗?
想请教一下是哪里出了问题
把print(computeCost((x, y, theta))改成print(computeCost(x, y, theta))