Scikit classification report - change the format of displayed results
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
No, it is not possible to display more digits with classification_report
. The format string is hardcoded, see here.
edit: there is an update, see CentAu's answer