Sathiya
Sathiya

Reputation: 11

Implementing Logistic Regression "TypeError: fit() missing 1 required positional argument: 'y'"

What i am Doing?
Trying to implement Logistic Regression algorithm to classify features as PASS or FAIL.

Code:

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)

Error:

TypeError Traceback (most recent call last) in ----> 1 parameters = fit(X, y, theta)

TypeError: fit() missing 1 required positional argument: 'y'

What is the mistake here?

Upvotes: 1

Views: 170

Answers (1)

mcskinner
mcskinner

Reputation: 2748

You should remove the self parameter.

That is for when your method is part of a class. Based on your usage example, it is just a function that does not belong to a class.

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)

Upvotes: 2

Related Questions