По умолчанию pos_label
из precision_score
и recall_score
составляют 1
.
from sklearn.metrics import confusion_matrix,precision_score,recall_score,classification_report
y_true = [0]*1568 + [1]*58
y_pred = [0]*1555 + [1]*13 + [0]* 9+ [1]* 49
print('confusion matrix :\n',confusion_matrix(y_true,y_pred))
print('precision_score :\n',precision_score(y_true,y_pred,pos_label=1))
print('recall_score :\n',recall_score(y_true,y_pred,pos_label=1))
print('classification_report :\n',classification_report(y_true,y_pred))
confusion matrix :
[[1555 13]
[ 9 49]]
precision_score :
0.7903225806451613
recall_score :
0.8448275862068966
classification_report :
precision recall f1-score support
0 0.99 0.99 0.99 1568
1 0.79 0.84 0.82 58
micro avg 0.99 0.99 0.99 1626
macro avg 0.89 0.92 0.90 1626
weighted avg 0.99 0.99 0.99 1626
Если вы хотите получить precision_score
и recall_score
из label=1
. Вы можете установить pos_label=0
для установки класса.
print('precision_score :\n',precision_score(y_true,y_pred,pos_label=0))
print('recall_score :\n',recall_score(y_true,y_pred,pos_label=0))
precision_score :
0.9942455242966752
recall_score :
0.9917091836734694