Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scikit classification report - change the format of displayed results

Scikit classification report would show precision and recall scores with two digits only. Is it possible to make it display 4 digits after the dot, I mean instead of 0.67 to show 0.6783?

 from sklearn.metrics import classification_report
 print classification_report(testLabels, p, labels=list(set(testLabels)), target_names=['POSITIVE', 'NEGATIVE', 'NEUTRAL'])
                     precision    recall  f1-score   support

         POSITIVE       1.00      0.82      0.90     41887
         NEGATIVE       0.65      0.86      0.74     19989
         NEUTRAL        0.62      0.67      0.64     10578

Also, should I worry about a precision score of 1.00? Thanks!

like image 846
Crista23 Avatar asked Feb 25 '14 18:02

Crista23


People also ask

What is Sklearn classification report?

A Classification report is used to measure the quality of predictions from a classification algorithm. How many predictions are True and how many are False. More specifically, True Positives, False Positives, True negatives and False Negatives are used to predict the metrics of a classification report as shown below.

What is support value in classification report?

support. Support is the number of actual occurrences of the class in the specified dataset. Imbalanced support in the training data may indicate structural weaknesses in the reported scores of the classifier and could indicate the need for stratified sampling or rebalancing.


1 Answers

I just came across this old question. It is indeed possible to have more precision points in classification_report. You just need to pass in a digits argument.

classification_report(y_true, y_pred, target_names=target_names, digits=4)

From the documentation:

digits : int Number of digits for formatting output floating point values

Demonstration:

from sklearn.metrics import classification_report
y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]
target_names = ['class 0', 'class 1', 'class 2']

print(classification_report(y_true, y_pred, target_names=target_names))

Output:

       precision    recall  f1-score   support

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

avg / total       0.70      0.60      0.61         5

With 4 digits:

print(classification_report(y_true, y_pred, target_names=target_names, digits=4))

Output:

             precision    recall  f1-score   support

    class 0     0.5000    1.0000    0.6667         1
    class 1     0.0000    0.0000    0.0000         1
    class 2     1.0000    0.6667    0.8000         3

avg / total     0.7000    0.6000    0.6133         5
like image 71
CentAu Avatar answered Sep 17 '22 15:09

CentAu