question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG Inconsistent f1_score behavior when combining label indicator input with labels attribute

See original GitHub issue

Description

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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
anerishah97commented, Dec 14, 2017

Can I take this up?

0reactions
gxydcommented, Dec 31, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found