Skip to content

Bug: Precision and recall calculations #323

@jonnygw1

Description

@jonnygw1

Description:
I discovered that the Precision and Recall have their logic reversed, the Precision metric is actually calculating Recall, and the Recall metric is calculating Precision.

The Issue:
In the Precision implementation, when counting false positives in binary classification:

if y_pred.get(i) == y_true.get(i) {
    if classes == 2 {
        if *y_true.get(i) == T::one() {
            tp += 1;
        }
    } else {
        tp += 1;
    }
} else if classes == 2 {
    if *y_true.get(i) == T::one() {
        fp += 1;
    }
}

This checks if y_true == 1 when predictions don't match. However, this is counting false negatives (when true=1 but pred=0), not false positives. False positives should be when we predict 1 but true label is 0.

Similarly, in the Recall implementation, when counting false negatives:


if y_pred.get(i) == y_true.get(i) {
    if classes == 2 {
        if *y_true.get(i) == T::one() {
            tp += 1;
        }
    } else {
        tp += 1;
    }
} else if classes == 2 {
    if *y_true.get(i) != T::one() {
        fne += 1;
    }
}

This checks if y_true == 0 when predictions don't match, which actually counts false positives (when true=0 but pred=1), not false negatives.

Impact:

  • Precision scores are actually Recall scores
  • Recall scores are actually Precision scores
  • F-beta scores with beta ≠ 1 are incorrect

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions