繁体   English   中英

实现逻辑回归“TypeError: fit() missing 1 required positional argument: 'y'”

[英]Implementing Logistic Regression “TypeError: fit() missing 1 required positional argument: '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参数。

这适用于当您的方法是 class 的一部分时。 根据您的使用示例,它只是一个不属于 class 的 function。

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM