Data Science Asked on December 4, 2021
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))
or
print('Accuracy:',metrics.accuracy_score(test_sentiments, predicted_sentiments, pos_label='positive'))
They both fail.
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.
Answered by Ben Reiniger on December 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP