实现Logistic回归“ TypeError:fit()缺少1个必需的位置参数:'y'”

时间:2020-04-13 06:30:44

标签: python regression typeerror

我在做什么?
尝试实现Logistic回归算法将要素分类为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跟踪(最近的呼叫 最后) ----> 1个参数= fit(X,y,theta)

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

这是什么错误?

1 个答案:

答案 0 :(得分:2)

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