我遇到了以下代碼:
from sklearn.metrics import classification_report
y_true = [2,1,1,1]
y_pred = [False,True,False,True]
print(classification_report(y_true, y_pred))
precision recall f1-score support
0 0.00 0.00 0.00 0
1 1.00 0.67 0.80 3
2 0.00 0.00 0.00 1
accuracy 0.50 4
macro avg 0.33 0.22 0.27 4
weighted avg 0.75 0.50 0.60 4
我無法理解 sklearn 如何在標簽y_true和y_pred陣列之間執行映射。也就是說,它如何確定是否False與 相同2或1與 相同True?
我沒有在檔案中找到任何細節。
uj5u.com熱心網友回復:
在 python 中,True=1和False=0.
所以,
y_pred = [False,True,False,True]
意思是一樣的
y_pred = [0,1,0,1]
這意味著,此代碼將產生與您的代碼完全相同的結果:
y_true = [2,1,1,1]
y_pred = [0,1,0,1]
print(classification_report(y_true, y_pred))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/462416.html
下一篇:如何獲得精確召回曲線下的面積
