torchmetrics icon indicating copy to clipboard operation
torchmetrics copied to clipboard

Fix/multiclass recall macro avg ignore index

Open rittik9 opened this issue 1 year ago • 6 comments

What does this PR do?

Fixes #2441

Details
  • [x] Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • [x] Did you read the contributor guideline, Pull Request section?
  • [ ] Did you make sure to update the docs?
  • [x] Did you write any new necessary tests?

Did you have fun?

Yes

Issue:

  • The root of the problem seems to be that the ignore_index information is not being properly propagated to the final averaging step i.e. the _adjust_weights_safe_divide function doesn't know that which class should be ignored.

Solution:

  • To address this issue, I updated the code to ensure that the ignore_index information is preserved throughout the entire process, making sure it is correctly passed through all intermediate steps up to the final averaging stage i.e. _adjust_weights_safe_divide function .
  • Updated the _adjust_weights_safe_divide function to accept an additional ignore_index parameter, which is passed through the _precision_recall_reduce function, called in the compute method of the MulticlassRecall class. This change adjusts the weights in the _adjust_weights_safe_divide function, setting the weight of the ignored class to 0.

📚 Documentation preview 📚: https://torchmetrics--2710.org.readthedocs.build/en/2710/

rittik9 avatar Sep 01 '24 20:09 rittik9

looks good, can we add also test for this case...

Sure

rittik9 avatar Sep 02 '24 22:09 rittik9

@Borda What do I have to modify?

rittik9 avatar Sep 06 '24 14:09 rittik9

@rittik9 mind checking the changed docstest values and whether it is correct?

Borda avatar Sep 11 '24 12:09 Borda

@rittik9 mind checking the changed docstest values and whether it is correct?

@Borda I checked the tests I wrote, I believe they are correct. I am planning to take a detailed look on tests which are failing later.

rittik9 avatar Sep 12 '24 06:09 rittik9

Any update on when this PR could be merged? It would really help if we could update from the 0.9.3 version once this fix is merged.

JeroenMandersloot avatar Oct 20 '24 15:10 JeroenMandersloot

Any update on when this PR could be merged? It would really help if we could update from the 0.9.3 version once this fix is merged.

the tests/doctests need to be fixed, are you interested in submitting a suggestion on what else needs to be fixed/chnaged?

Borda avatar Oct 20 '24 15:10 Borda

Just to chime in, I think this issue is present in pretty much all metrics that make use of _adjust_weights_safe_divide.

I see this PR fixes, some of them, but others, such as JaccardIndex are left as is.

DimitrisMantas avatar Nov 04 '24 22:11 DimitrisMantas

Shall we then fix the unittest, or was it in the meantime already resolved with sklearn?

Borda avatar Jul 02 '25 20:07 Borda

I think we gotta fix the unit tests first

rittik9 avatar Jul 02 '25 20:07 rittik9