【问题标题】:Implementing Logistic Regression "TypeError: fit() missing 1 required positional argument: 'y'"实现逻辑回归“TypeError:fit() 缺少 1 个必需的位置参数:'y'”
【发布时间】:2020-07-25 16:48:59
【问题描述】:

我在做什么?
尝试实现逻辑回归算法将特征分类为 PASS 或 FAIL。

代码:

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)

错误:

TypeError Traceback(最近调用 最后)在 ----> 1 个参数 = fit(X, y, theta)

TypeError: fit() 缺少 1 个必需的位置参数:'y'

这里有什么错误?

【问题讨论】:

标签: python regression typeerror


【解决方案1】:

您应该删除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)

【讨论】:

    猜你喜欢
    • 2019-03-08
    • 1970-01-01
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    • 2020-11-15
    相关资源
    最近更新 更多