如何从Sklearn分类报告中返回精确度,召回率和F1分数的平均分数?

时间:2018-03-08 02:28:09

标签: python scikit-learn

我使用Sklearn计算精确度,召回率和F1分数,得到如下结果:

               precision    recall  f1-score   support

          0       0.82      0.87      0.84      2517
          1       0.86      0.81      0.83      2483

avg / total       0.84      0.84      0.84      5000

我试过这段代码:

 print("precision_score: ",precision_score(test_y, predicted))
 print("recall_score: ",recall_score(test_y, predicted))
 print("f1_score: ",f1_score(test_y, predicted))

它显示标签1的p,r和f1。

 precision_score:  0.857692307692
 recall_score:  0.808296415626
 f1_score:  0.832262077545

但我怎样才能返回avg / total的值?

1 个答案:

答案 0 :(得分:3)

记录在案here in the classification_report page

  

报告的平均值是一个流行加权的宏观平均值   类(相当于precision_recall_fscore_support的   平均='加权'。)

为了获得平均分,你可以做到:

precision, recall, f1, _ = precision_recall_fscore_support(test_y, predicted, 
                                                          average='weighted')