评估指标与 Sklearn 函数的手动计算不匹配

Mismatch of manual computation of a evaluation metrics with Sklearn functions

我想将精确度和召回率的手动计算与 scikit-learn 函数进行比较。但是,recall_score()precision_score() of scikit-learn 函数给了我不同的结果。不知道为什么!你能给我一些建议为什么我得到不同的结果吗?谢谢!

我的混淆矩阵:

tp, fn, fp, tn = confusion_matrix(y_test, y_test_pred).ravel()
print('Outcome values : \n', tp, fn, fp, tn)
Outcome values : 
 3636933 34156 127 151
FDR=tp/(tp+fn) # TPR/Recall/Sensitivity
print('Recall: %.3f' % FDR)
Recall: 0.991
precision=tp/(tp + fp)
print('Precision: %.3f' % precision)
Precision: 1.000
precision = precision_score(y_test, y_test_pred)
print('Precision: %f' % precision)
recall = recall_score(y_test, y_test_pred)
print('Recall: %f' % recall)
Precision: 0.004401
Recall: 0.543165

应该是(检查 return 值的排序):

tn, fp, fn, tp = confusion_matrix(y_test, y_test_pred).ravel()

请参考:here