【发布时间】:2020-06-09 12:42:25
【问题描述】:
我正在将 scikit-learn(版本 0.22.1)用于机器学习应用程序。
我正在使用随机森林算法,但在使用精度和召回率评估算法性能时遇到了一些问题。我有我的测试集 (Y_test) 的标签和使用随机森林算法 (Y_pred) 预测的标签。两个数据都包含两个标签(1 和 0)
详细来说,我有这个矩阵:
print(confusion_matrix(y_true=Y_test, y_pred=Y_pred, labels=[1,0]))
[[78 20]
[36 41]]
因此:
True Positive (tp) = 78
False Negative (fn) = 36
False Positive (fp) = 20
所以:
PRECISION = tp/(tp+fn) = 78/(78+36) = 0.7959183673469388
RECALL = = tp/(tp+fp) = 78/(78+20) 0.6842105263157895
但是,使用此代码:
precision = precision_score(Y_test, Y_pred, pos_label=1)
recall = recall_score(y_true=Y_test, y_pred=Y_pred, pos_label=1)
print("precision: ",precision)
print("recall: ",recall)
我得到以下输出:
recall: 0.7959183673469388
precision: 0.6842105263157895
似乎在使用标准 sklearn 函数计算值时交换了值。 我做错什么了吗? 请问,你能给我一些建议吗?
谢谢,
丹尼尔
【问题讨论】:
-
在您的计算中,您混淆了公式。例如,精度为
tp/(tp+fp)。
标签: python machine-learning scikit-learn confusion-matrix precision-recall