判斷分類性能classification_report

在分類任務(wù)中,可以用classification_report生成每個類別的precision,recall和F1值。
方法:
sklearn.metrics.classification_report(y_true, y_pred, labels=None, target_names=None, sample_weight=None, digits=2, output_dict=False, zero_division='warn')
主要參數(shù):
y_true:目標(biāo)值,格式是列表
y_pred:預(yù)測值,格式是列表
labels:類別的取值范圍,最后打印出來的就是labels里面的分類。格式是列表。
target_names:在打印報告中顯示別名。例如y_true和y_pred都是0和1,但是現(xiàn)在該報告中顯示具體的類別名字,就可以把target_names設(shè)為['name 0', 'name 1'],注意它的順序和y_pred的順序一樣。
digits:輸出浮點值的位數(shù)。

例子:

from sklearn.metrics import classification_report
y_true = [1, 0, 1, 2, 2]
y_pred = [0, 1, 1, 2, 1]
target_names  = ['label 1', 'label 0', 'label 2']
print(classification_report(y_true, y_pred, target_names=target_names,labels=[0, 1, 2]))

                 precision    recall  f1-score   support

     label 1       0.00      0.00      0.00         1
     label 0       0.33      0.50      0.40         2
     label 2       1.00      0.50      0.67         2

    accuracy                             0.40         5
   macro avg       0.44      0.33      0.36         5
weighted avg       0.53      0.40      0.43         5
         

官方參考文檔:

https://scikit-learn.org/stable/modules/generated/sklearn.metrics.classification_report.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容