feat: add class_names support to Precision and Recall metrics
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)
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 would raising errors for those condition a better option or should we add full class_name support to fbeta
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?
Could we please clarify Fbeta behavior when class_names is used with average=False/None
I am not sure, adding support for the class names in
fbetawould be easier, butfbetauses theMetricsLambdafor 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.
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?
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.
hey @vfdev-5 I think Fbeta should return a per-class dict if class_names is set, regardless of average.
@rogueslasher ok, let's implement that this way and see if this works as expected
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
@aaishwarymishra ,would love your help in this can you look into it more please
@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 the header rules and other three preview checks are taking insane amount of time . is there any issue
Documentation issue :)
@aaishwarymishra