Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Possible error in the
ap_per_class
function when calculating the precision-recall curveHello,
I have identified a possible error in the
ap_per_class
function when calculating the metrics for the precision-recall curve. Below, I provide an example to explain it more clearly:Let’s assume the
unique_classes
list is[0, 1, 2]
, and the model never predicted class 1. In this case, on line 583 of theutils/metrics.py
file, the loop will skip to the next class (class 2) becausen_p == 0
for class 1.However, before moving on to the next class, a zero-filled array corresponding to class 1 should be added to the
prec_values
list. Otherwise, the precision-recall curve for class 2 will incorrectly appear as if it belongs to class 1, and the legend will also fail to show the correct label for class 2.To fix this behavior, before the
continue
statement, the code should be modified as follows:I hope my explanation is clear, and I have correctly identified the issue. While this is a rare case where the model never predicts one of the classes in the dataset, it is still something to consider to avoid errors in the precision-recall curve visualizations.
Best regards.