# Error when trying to obtain accuracy score for classifiers

I am trying to get an accuracy score for the classifiers but I keep getting this error

TypeError: predict() missing 1 required positional argument: 'X'

Can anyone help?

from sklearn.metrics import accuracy_score

classifiers = [SVC, sgd, naive_bayes]

# for each classifier get the accuracy score
scores = [accuracy_score(clf.predict(test_X), test_y) for clf in classifiers]

index = np.argmax(scores)

print(scores)

print(classifiers[index])
print(scores[index])


• Hi, it could be helpful to try it with an sklearn dataset (and add that into the code in your snippet) so that people can completely reproduce your error. Jun 3 at 1:11

I do not see your whole example but this usually happens when you have not initialized your classifier.

Even more, to test, you first have to train your classifier (e.g. clf().fit(X_train, y_train)).

nocibambi is correct...to piggy back on his a simple implementation would look something like the following. I haven't run this as I'm at work, but hopefully it points you in the right direction.

# example classifier
svclassifier = SVC(kernel='linear')

# fit
svclassifier.fit(X_train, y_train)

# predict
y_pred = svclassifier.predict(X_test)

# score
print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred))