lulu
lulu

Reputation: 183

How to return average score for precision, recall and F1-score from Sklearn Classification report?

I computed precision, recall and F1-score with Sklearn and get result as below:

               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

I tried this code:

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

It shows p, r and f1 for label 1.

 precision_score:  0.857692307692
 recall_score:  0.808296415626
 f1_score:  0.832262077545

But how can I return the value for avg/total only?

Upvotes: 2

Views: 2474

Answers (1)

Vivek Kumar
Vivek Kumar

Reputation: 36599

Its documented here in the classification_report page:

The reported averages are a prevalence-weighted macro-average across classes (equivalent to precision_recall_fscore_support with average='weighted').

So to get the avg score you can do:

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

Upvotes: 4

Related Questions