【发布时间】:2021-11-16 01:00:00
【问题描述】:
我想将手动计算的精度和召回率与 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
【问题讨论】:
-
请提供示例数据(最小可重复示例)。当我尝试使用示例时,无论是手动计算还是使用 sklearn 函数计算的值都匹配。
-
@SoniaSamipillai 我有大量数据集。为了方便起见,我添加了混淆矩阵。
标签: python machine-learning scikit-learn classification precision-recall