Skip to content

Commit

Permalink
[backport] fix true negative computation (#106)
Browse files Browse the repository at this point in the history
* Fix true negative computation (#101)

* fix true negatives

* bump version

* Update test/metrics.jl

Co-authored-by: Eric Hanson <[email protected]>

* bump version

---------

Co-authored-by: Eric Hanson <[email protected]>
Co-authored-by: hannahilea <[email protected]>
(cherry picked from commit b1adbe8)

* patch bump

---------

Co-authored-by: Alex Chan <[email protected]>
  • Loading branch information
palday and alexmchan authored Mar 3, 2023
1 parent 9a01347 commit b7e4d4f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Lighthouse"
uuid = "ac2c24cd-07f0-4848-96b2-1b82c3ea0e59"
authors = ["Beacon Biosignals, Inc."]
version = "0.14.18"
version = "0.14.19"

[deps]
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"
Expand Down
2 changes: 1 addition & 1 deletion src/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ function binary_statistics(confusion::AbstractMatrix, class_index::Integer)
actual_positives = sum(view(confusion, :, class_index))
actual_negatives = total - actual_positives
true_positives = confusion[class_index, class_index]
true_negatives = sum(diag(confusion)) - true_positives
false_positives = predicted_positives - true_positives
false_negatives = actual_positives - true_positives
true_negatives = actual_negatives - false_positives
true_positive_rate = (true_positives == 0 && actual_positives == 0) ?
(one(true_positives) / one(actual_positives)) :
(true_positives / actual_positives)
Expand Down
10 changes: 8 additions & 2 deletions test/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@
@test accuracy(c) == percent_agreement == 3 / 8
@test kappa == (3 / 8 - chance) / (1 - chance)
stats = binary_statistics(c, 3)
total = sum(c)
@test total == 8
@test stats.predicted_positives == 2
@test stats.predicted_negatives == 6
@test stats.actual_positives == 2
@test stats.actual_negatives == 6
@test stats.true_positives == 1
@test stats.true_negatives == 2
@test stats.true_negatives == 5
@test stats.false_positives == 1
@test stats.false_negatives == 1
@test stats.true_positive_rate == 0.5
@test stats.true_negative_rate == 1 / 3
@test stats.true_negative_rate == 5 / 6
@test stats.false_positive_rate == 1 / 6
@test stats.false_negative_rate == 0.5
@test stats.precision == 0.5
@test stats.f1 == 0.5
@test stats.true_positives + stats.true_negatives + stats.false_positives +
stats.false_negatives == total
@test stats.actual_positives + stats.actual_negatives == total
@test stats.predicted_positives + stats.predicted_negatives == total

labels = rand(StableRNG(42), 1:3, 100)
hard_label_pairs = zip(labels, labels)
Expand Down

4 comments on commit b7e4d4f

@palday
Copy link
Member Author

@palday palday commented on b7e4d4f Mar 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/78901

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.19 -m "<description of version>" b7e4d4f47d25134298d929ca93cdb3e48ced8e29
git push origin v0.14.19

Also, note the warning: Version 0.14.19 skips over 0.14.18
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

@palday
Copy link
Member Author

@palday palday commented on b7e4d4f Mar 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/78901

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.19 -m "<description of version>" b7e4d4f47d25134298d929ca93cdb3e48ced8e29
git push origin v0.14.19

Please sign in to comment.