![](/img/trans.png)
[英]Can you explain the classification report (Recall and Precision) on provided example?
[英]Why not look at the precision and recall of both classes combined in a classification report?
我正在查看 sklearn 的分類報告。 我想知道,為什么他們省略了潛在的第三行,同時包含兩個類的精度和召回值? 他們為什么分開,將這些指標與兩個類別結合起來考慮有什么缺點?
“兩個類的精度和召回值一起”包含在classification_report
中,作為精度、召回率和 f1 分數的宏觀平均值和加權平均值。
將classification_report
中的列與調用precision_score(y_true, y_pred)
時計算的值進行比較:
from sklearn.metrics import classification_report
from sklearn.metrics import precision_score
y_true = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]
y_pred = [0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 0]
print(classification_report(y_true, y_pred))
print(round(precision_score(y_true, y_pred, average='macro'), 2))
print(round(precision_score(y_true, y_pred, average='weighted'), 2))
運行結果如下。 請注意,宏平均精度為 0.64,加權平均精度為 0.67,兩者都列在表的底部行中:
precision recall f1-score support
0 0.43 0.60 0.50 5
1 0.50 0.57 0.53 7
2 1.00 0.57 0.73 7
accuracy 0.58 19
macro avg 0.64 0.58 0.59 19
weighted avg 0.67 0.58 0.60 19
0.64
0.67
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.