I am executing this code which works perfectly for me:

(I only have 'positive' and 'negative' sentiments):

from sklearn import metrics
print('Accuracy:',metrics.accuracy_score(test_sentiments, predicted_sentiments))  
print('Precision:',metrics.precision_score(test_sentiments, predicted_sentiments, pos_label='positive'))

My question is: how come accuracy_score recognizes the positive label and precision_score does not?

ps: if I execute:

print('Precision:',metrics.precision_score(test_sentiments, predicted_sentiments))


print('Accuracy:',metrics.accuracy_score(test_sentiments, predicted_sentiments, pos_label='positive')) 

They both fail.


1 Answer 1


Accuracy is symmetric in the naming of positive/negative classes, but precision is not: for accuracy, it doesn't matter which class is "positive." So accuracy_score doesn't have a parameter pos_label, and will error if you try to pass that parameter; meanwhile precision_score has default pos_label=1, so if your labels don't include 1 and you leave the parameter to the default, you'll get an error.


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.