-
-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Closed
Description
Description
The Macro and weighted Average in sklearn.metrics.classification_report is wrong. The argument zero_division is missing here.
I have created a pull request for correcting this small error
Steps/Code to Reproduce
from sklearn.metrics import classification_report, precision_recall_fscore_support
y_pred = ['N', 'Af', 'Ab']
y_true = ['N', 'Au', 'Ab']
print(classification_report(y_true, y_pred, zero_division=1, labels=['N', 'Au', 'Af', 'Ab', 'T']))
print(precision_recall_fscore_support(y_true, y_pred, zero_division=1, average='macro',labels=['N', 'Au', 'Af', 'Ab', 'T']))
print(precision_recall_fscore_support(y_true, y_pred, zero_division=1, average='weighted',labels=['N', 'Au', 'Af', 'Ab', 'T']))
Expected Results
The expected output of
classification_report(y_true, y_pred, zero_division=1, labels=['N', 'Au', 'Af', 'Ab', 'T'])
precision recall f1-score support
N 1.00 1.00 1.00 1
Au 1.00 0.00 0.00 1
Af 0.00 1.00 0.00 0
Ab 1.00 1.00 1.00 1
T 1.00 1.00 1.00 0
micro avg 0.67 0.67 0.67 3
macro avg 0.80 0.80 0.60 3
weighted avg 1.00 0.67 0.67 3
Actual Results
The output of
classification_report(y_true, y_pred, zero_division=1, labels=['N', 'Au', 'Af', 'Ab', 'T'])
precision recall f1-score support
N 1.00 1.00 1.00 1
Au 1.00 0.00 0.00 1
Af 0.00 1.00 0.00 0
Ab 1.00 1.00 1.00 1
T 1.00 1.00 1.00 0
micro avg 0.67 0.67 0.67 3
macro avg 0.40 0.40 0.40 3
weighted avg 0.67 0.67 0.67 3
But the macro avg and weighted average is wrong in the second part. it should be
precision_recall_fscore_support(
y_true,
y_pred,
zero_division=1,
average='macro',
labels=['N', 'Au', 'Af', 'Ab', 'T'])
(0.8, 0.8, 0.6, None)
precision_recall_fscore_support(
y_true,
y_pred,
zero_division=1,
average='weighted',
labels=['N', 'Au', 'Af', 'Ab', 'T'])
(1.0, 0.6666666666666666, 0.6666666666666666, None)
Versions
System:
python: 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0]
executable: /opt/conda/bin/python
machine: Linux-4.15.0-47-generic-x86_64-with-debian-buster-sid
Python dependencies:
pip: 19.3.1
setuptools: 41.4.0
sklearn: 0.22
numpy: 1.17.3
scipy: 1.4.0rc1
Cython: None
pandas: 0.25.3
matplotlib: 3.2.0rc1
joblib: 0.14.0
Built with OpenMP: True