1
$\begingroup$

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

$\endgroup$
1
  • $\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 at 1:11
2
$\begingroup$

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

$\endgroup$
0
$\begingroup$

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))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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