Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

num_classes should not be required when using micro averaging #2837

Open
edmcman opened this issue Nov 13, 2024 · 2 comments
Open

num_classes should not be required when using micro averaging #2837

edmcman opened this issue Nov 13, 2024 · 2 comments
Assignees
Labels
bug / fix Something isn't working help wanted Extra attention is needed v1.6.x

Comments

@edmcman
Copy link

edmcman commented Nov 13, 2024

🐛 Bug

When using micro averaging on multiclass_accuracy, it is required to pass in num_classes, even though it's not part of the calculation.

To Reproduce

from torchmetrics.functional.classification import multiclass_accuracy
import torch
x = torch.Tensor([0, 0, 0])
y = torch.Tensor([0, 1, 1])

print(multiclass_accuracy(x, y, average="macro", num_classes=2))
print(multiclass_accuracy(x, y, num_classes=2))
print(multiclass_accuracy(x, y, average="micro", num_classes=2))
try:
  print(multiclass_accuracy(x, y, average="micro"))
except:
  print("Need num_classes even for micro, why?")

Expected behavior

In general, I expect the metric to be computed. In the above code sample, I expect 0.33 to be returned, rather than an exception.

Environment

@edmcman edmcman added bug / fix Something isn't working help wanted Extra attention is needed labels Nov 13, 2024
Copy link

Hi! thanks for your contribution!, great first issue!

@Borda Borda added the v1.6.x label Nov 13, 2024
@Borda Borda changed the title num_classes should not be required when using micro averaging num_classes should not be required when using micro averaging Nov 13, 2024
@Borda
Copy link
Member

Borda commented Nov 13, 2024

The micro-averaged accuracy metric is calculated by considering all the individual predictions across classes as a single pool, so it doesn’t require knowing the number of classes in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed v1.6.x
Projects
None yet
Development

No branches or pull requests

3 participants