ignite icon indicating copy to clipboard operation
ignite copied to clipboard

feat: add class_names support to Precision and Recall metrics

Open aniketpandey05 opened this issue 7 months ago • 12 comments

Fixes #1466

Description: Adds an optional class_names parameter to _BasePrecisionRecall, allowing compute() to return a labeled dict instead of an unnamed tensor when average=False or average=None. Useful for per-class metric tracking where knowing which score belongs to which class matters for logging and visualization.

Check list:

  • [x] New tests are added (if a new feature is added)
  • [x] New doc strings: description and/or example code are in RST format
  • [ ] Documentation is updated (if required)

aniketpandey05 avatar Apr 14 '26 11:04 aniketpandey05

ok so like wont this code break fbeta metric when precision and recall have average=False and they have class_names, we need to update the fbeta too to support this.

There can be more metrics that can benefit from this change. I am not sure though.

aaishwarymishra avatar Apr 15 '26 05:04 aaishwarymishra

@aaishwarymishra would raising errors for those condition a better option or should we add full class_name support to fbeta

aniketpandey05 avatar Apr 16 '26 12:04 aniketpandey05

I am not sure, adding support for the class names in fbeta would be easier, but fbeta uses the MetricsLambda for overloading operator we can update them, I am not sure @vfdev-5 what you think would be appropriate?

aaishwarymishra avatar Apr 16 '26 15:04 aaishwarymishra

Could we please clarify Fbeta behavior when class_names is used with average=False/None

steaphenai avatar Apr 20 '26 19:04 steaphenai

I am not sure, adding support for the class names in fbeta would be easier, but fbeta uses the MetricsLambda for overloading operator we can update them, I am not sure @vfdev-5 what you think would be appropriate?

If we can compute F1 score per class than we should propagate the dict structure until the output of the F1 otherwise, take .values() of the dict output from precision and recall.

vfdev-5 avatar Apr 21 '26 08:04 vfdev-5

Hey @vfdev-5 , would adding a helper in metric.py to handle dict arithmetic in all operator overloads so the dict propagates through to the Fbeta output be a good approach? Also when average=True and class_names is set, should Fbeta return a scalar float or propagate the dict as is?

aniketpandey05 avatar Apr 27 '26 14:04 aniketpandey05

Hey @vfdev-5 , would adding a helper in metric.py to handle dict arithmetic in all operator overloads so the dict propagates through to the Fbeta output be a good approach? Also when average=True and class_names is set, should Fbeta return a scalar float or propagate the dict as is?

I do not know, what would you suggest? Let's try to make it the most simple possible and intuitively clear.

vfdev-5 avatar May 03 '26 16:05 vfdev-5

hey @vfdev-5 I think Fbeta should return a per-class dict if class_names is set, regardless of average.

aniketpandey05 avatar May 21 '26 15:05 aniketpandey05

@rogueslasher ok, let's implement that this way and see if this works as expected

vfdev-5 avatar May 21 '26 16:05 vfdev-5

Hey @vfdev-5, would adding a _dict_aware_op helper in metric.py and updating all operator overloads to use it for element-wise dict arithmetic, and skipping average in fbeta.py when class_names is set be a good idea? It touches all operator overloads in metric.py which affects all metrics.

i am worried since it touches all operators overloads

aniketpandey05 avatar Jun 09 '26 10:06 aniketpandey05

@aaishwarymishra ,would love your help in this can you look into it more please

aniketpandey05 avatar Jun 17 '26 17:06 aniketpandey05

@rogueslasher well , I am not sure to be honest i wont touch the metric operators as it kind of affect every metric, for a case which can be only relevant for very few metrics, I think we should modify Fbeta directly.

aaishwarymishra avatar Jun 19 '26 12:06 aaishwarymishra

@aaishwarymishra the header rules and other three preview checks are taking insane amount of time . is there any issue

aniketpandey05 avatar Jun 30 '26 13:06 aniketpandey05

Documentation issue :)

aaishwarymishra avatar Jun 30 '26 14:06 aaishwarymishra

@aaishwarymishra

aniketpandey05 avatar Jul 01 '26 09:07 aniketpandey05