python - 实现逻辑回归“TypeError:fit() 缺少 1 个必需的位置参数:'y'”
问题描述
我在做什么?
尝试实现逻辑回归算法将特征分类为通过或失败。
代码:
def fit(self, theta, x, y):
opt_weights = fmin_tnc(func = cost_function, x0 = theta, fprime = gradient, args = (x, y.flatten()))
return opt_weights
parameters = fit(X, y, theta)
错误:
----> 1 个参数中的 TypeError Traceback (最近一次调用最后一次) = fit(X, y, theta)
类型错误:fit() 缺少 1 个必需的位置参数:'y'
这里有什么错误?
解决方案
您应该删除该self
参数。
那是当您的方法是类的一部分时。根据您的使用示例,它只是一个不属于某个类的函数。
def fit(theta, x, y):
opt_weights = fmin_tnc(func = cost_function, x0 = theta, fprime = gradient, args = (x, y.flatten()))
return opt_weights
parameters = fit(X, y, theta)
推荐阅读
- mpdf - 解析使用 GD 库创建的临时文件图像对象以解析 PNG 图像的 PNG 图像时出错
- firebase - 使用颤振(或 Android)的 Firebase 存储规则
- sql - 如何更快地搜索一个有 8000 万条记录的表?
- web - 只需单击恶意/病毒链接,我的 PC 会被黑客入侵吗?(2020 更新)
- html - 如何从 html 按钮添加下载 .app 文件
- ruby-on-rails - 如何防止我的 sidekiq 工作人员超出其数据库连接限制?
- string - 使用 dart 从字符串中获取单词
- spring - 如何修复 Spring Mongo 组聚合中的空值?
- prolog - Prolog 通过给类点数进行分类
- swift - UNUserNotificationCenter.getNotificationSettings 中的计时器失败