apex03 2022-09-13 21:47 采纳率: 100%
浏览 13
已结题

python程序的报错小问题

刚开始学做机器学习的时候遇到的问题

问题相关代码 python

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 <module>
    print(computeCost((x, y, theta)))
TypeError: computeCost() missing 2 required positional arguments: 'y' and 'theta'

函数computeCost缺少 2 个必需 位置参数
我这里不是已经定义了y和theta了吗?
想请教一下是哪里出了问题

  • 写回答

2条回答 默认 最新

  • 亖夕 Python领域新星创作者 2022-09-13 21:49
    关注

    把print(computeCost((x, y, theta))改成print(computeCost(x, y, theta))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月22日
  • 已采纳回答 9月14日
  • 创建了问题 9月13日

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动