我使用Python,Pandas和NLTK运行Naive Bayes分类器。
我了解一般如何计算精度和召回的内容和方法,但我不明白为什么在使用以下命令时有一对精度和一对召回
from featx import precision_recall
nb_precisions, nb_recalls = precision_recall(nb_classifier, test_feats)
training_n = int(data_n * 0.25) ### changeable
featuresets = [(first_letter(name), ethnicity) for index, (name, ethnicity, last_name) in df.iterrows()] ### changeable
train_feats, test_feats = featuresets[training_n:], featuresets[:training_n]
nb_classifier = NaiveBayesClassifier.train(train_feats)
# Performance
print "Accuracy: " + str(accuracy(nb_classifier, test_feats))
# Precision and recall
nb_precisions, nb_recalls = precision_recall(nb_classifier, test_feats)
print "Precision +: " + str(nb_precisions[ethnic_target1])
print "Precision -: " + str(nb_precisions[ethnic_non_target])
print "Recall +: " + str(nb_recalls[ethnic_target1])
print "Recall -: " + str(nb_recalls[ethnic_non_target])
Accuracy: 0.99632
Precision +: None
Precision -: 0.99632
Recall +: 0.0
Recall -: 1.0
使用人名(特征)的第一个字母对中国人和非中国人进行分类。
Gold standard
Chinese non-Chinese
Predicted Chinese A C
non-Chinese B D
我的理解是精度= A /(A + C) 并召回= D /(B + D)