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)



  • $\begingroup$ 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. $\endgroup$ Jun 3, 2021 at 1:11

2 Answers 2


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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.