打印classification_report的时候有时候会出现

2022-07-13  本文已影响0人  波洛的汽车电子世界
y_pred = [1, 1, 2]
y_true = [1, 1, 1]
print(classification_report(y_true, y_pred, labels=[1, 2]))
                 precision    recall  f1-score   support

          1       1.00      0.67      0.80         3
          2       0.00      0.00      0.00         0

   accuracy                           0.67         3
  macro avg       0.50      0.33      0.40         3
weighted avg       1.00      0.67      0.80         3

y_pred = [1, 1, 2]
y_true = [1, 1, 1]
print(classification_report(y_true, y_pred, labels=[1, 2, 3]))

                precision    recall  f1-score   support

           1       1.00      0.67      0.80         3
           2       0.00      0.00      0.00         0
           3       0.00      0.00      0.00         0

   micro avg       0.67      0.67      0.67         3
   macro avg       0.33      0.22      0.27         3
weighted avg       1.00      0.67      0.80         3
y_pred = [1, 1, 2]
y_true = [1, 1, 1]
print(classification_report(y_true, y_pred, labels=[1, 0]))      


              precision    recall  f1-score   support

           1       1.00      0.67      0.80         3
           0       0.00      0.00      0.00         0

   micro avg       1.00      0.67      0.80         3
   macro avg       0.50      0.33      0.40         3
weighted avg       1.00      0.67      0.80         3

例子1:labels里面的值和y_pred的值一样,打印出accuracy
例子2:labels里面有的值没有在y_pred出现
例子3:y_pred的值没有在labels里面出现
labels里面的值是我们最后想要打印出precision和recall的类别名字。如果labels和y_pred的取值范围一样,就会打印accuracy,如果不一样,就会打印micro avg。

上一篇下一篇

猜你喜欢

热点阅读