BUG Inconsistent f1_score behavior when combining label indicator input with labels attribute
See original GitHub issueDescription
When using label indicator inputs for y_pred and y_true, metrics.f1_score calculates the macro average over all label-specific f-scores whenever the labels parameter includes column index 0. It should only average over the label-specific scores indicated by the labels parameter, as it does when 0 is not present in the labels parameter.
Steps/Code to Reproduce
import numpy as np
from sklearn.metrics import f1_score, precision_recall_fscore_support
y_true = np.array([[0, 1, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0]])
y_pred = np.array([[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0]])
p, r, f, s = precision_recall_fscore_support(y_true, y_pred)
print(f)
print(f1_score(y_true, y_pred, labels=[0,1], average='macro'))
print(f1_score(y_true, y_pred, labels=[0,1,2], average='macro'))
print(f1_score(y_true, y_pred, labels=[1,3], average='macro'))
print(f1_score(y_true, y_pred, labels=[1,2,3], average='macro'))
Expected Results
[ 0. 0.66666667 0. 0. ]
0.333333333333
0.222222222222
0.333333333333
0.222222222222
Actual Results
[ 0. 0.66666667 0. 0. ]
0.166666666667
0.166666666667
0.333333333333
0.222222222222
Versions
Windows-7-6.1.7601-SP1 Python 3.5.3 |Anaconda custom (64-bit)| (default, May 15 2017, 10:43:23) [MSC v.1900 64 bit (AMD64)] NumPy 1.13.1 SciPy 0.19.0 Scikit-Learn 0.19.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Common validation errors when creating issue forms
Checkboxes must have unique labels ... name: "Bug report" body: - type: input id: name attributes: label: First name - type: input id:...
Read more >Applied Sciences | Free Full-Text | Dynamic Fire Risk Classification ...
Stadium fires can easily cause massive casualties and property damage. The early risk prediction of stadiums will be able to reduce the incidence...
Read more >A Comprehensive Survey on Graph Anomaly Detection ... - arXiv
graph anomaly detection also identifies graph-level anomalies, ... the structure reconstruction error and attribute reconstruction error.
Read more >Graph2GO: a multi-modal attributed network embedding ...
Then, we combine these two embeddings and use them to predict the protein functions with a feedforward neural network model. As far as...
Read more >Multi-Class Classification Tutorial with the Keras Deep ...
This dataset is well studied and makes a good problem for practicing on neural networks because all four input variables are numeric and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can I take this up?
I just noticed this. This actually is fixed by https://github.com/scikit-learn/scikit-learn/pull/10377 . I independently tried to fix that in that PR. I think it correctly fixes this issue as well.