首页 > 解决方案 > 评估指标的手动计算与 Sklearn 函数不匹配

问题描述

我想将精度和召回率的手动计算与 scikit-learn 函数进行比较。然而, recall_score()scikit precision_score() -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

标签: pythonmachine-learningscikit-learnclassificationprecision-recall

解决方案


它应该是(检查返回值的顺序):

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

请参考:这里


推荐阅读