Skip to content

Commit b1adbe8

Browse files
alexmchanericphansonhannahilea
authored
Fix true negative computation (#101)
* fix true negatives * bump version * Update test/metrics.jl Co-authored-by: Eric Hanson <5846501+ericphanson@users.noreply.github.com> * bump version --------- Co-authored-by: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Co-authored-by: hannahilea <hannahilea@users.noreply.github.com>
1 parent 4e1371d commit b1adbe8

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Lighthouse"
22
uuid = "ac2c24cd-07f0-4848-96b2-1b82c3ea0e59"
33
authors = ["Beacon Biosignals, Inc."]
4-
version = "0.15.1"
4+
version = "0.15.2"
55

66
[deps]
77
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"

src/metrics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ function binary_statistics(confusion::AbstractMatrix, class_index::Integer)
7070
actual_positives = sum(view(confusion, :, class_index))
7171
actual_negatives = total - actual_positives
7272
true_positives = confusion[class_index, class_index]
73-
true_negatives = sum(diag(confusion)) - true_positives
7473
false_positives = predicted_positives - true_positives
7574
false_negatives = actual_positives - true_positives
75+
true_negatives = actual_negatives - false_positives
7676
true_positive_rate = (true_positives == 0 && actual_positives == 0) ?
7777
(one(true_positives) / one(actual_positives)) :
7878
(true_positives / actual_positives)

test/metrics.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,26 @@
1010
@test accuracy(c) == percent_agreement == 3 / 8
1111
@test kappa == (3 / 8 - chance) / (1 - chance)
1212
stats = binary_statistics(c, 3)
13+
total = sum(c)
14+
@test total == 8
1315
@test stats.predicted_positives == 2
1416
@test stats.predicted_negatives == 6
1517
@test stats.actual_positives == 2
1618
@test stats.actual_negatives == 6
1719
@test stats.true_positives == 1
18-
@test stats.true_negatives == 2
20+
@test stats.true_negatives == 5
1921
@test stats.false_positives == 1
2022
@test stats.false_negatives == 1
2123
@test stats.true_positive_rate == 0.5
22-
@test stats.true_negative_rate == 1 / 3
24+
@test stats.true_negative_rate == 5 / 6
2325
@test stats.false_positive_rate == 1 / 6
2426
@test stats.false_negative_rate == 0.5
2527
@test stats.precision == 0.5
2628
@test stats.f1 == 0.5
29+
@test stats.true_positives + stats.true_negatives + stats.false_positives +
30+
stats.false_negatives == total
31+
@test stats.actual_positives + stats.actual_negatives == total
32+
@test stats.predicted_positives + stats.predicted_negatives == total
2733

2834
labels = rand(StableRNG(42), 1:3, 100)
2935
hard_label_pairs = zip(labels, labels)

0 commit comments

Comments
 (0)