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

2024-03-28 14:42:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将人工计算的精度和召回率与scikit学习函数进行比较。然而,scikit学习函数的recall_score()precision_score() 给了我不同的结果。不知道为什么!你能给我一些建议为什么我会得到不同的结果吗?谢谢

我的困惑矩阵:

enter image description here

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

1条回答
网友
1楼 · 发布于 2024-03-28 14:42:31

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

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

请参阅:here

相关问题 更多 >