Skip to content

Commit

Permalink
Update F1 score implementation (#87)
Browse files Browse the repository at this point in the history
* alternate f1 implementation

* add tests

* bump patch version
  • Loading branch information
alexmchan authored Jul 14, 2022
1 parent cf5f2a4 commit aef6df0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 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.11"
version = "0.14.12"

[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 @@ -87,7 +87,7 @@ function binary_statistics(confusion::AbstractMatrix, class_index::Integer)
(false_negatives / actual_positives)
precision = (true_positives == 0 && predicted_positives == 0) ? NaN :
(true_positives / predicted_positives)
f1 = (2 * precision * true_positive_rate) / (precision + true_positive_rate)
f1 = true_positives / (true_positives + 0.5 * (false_positives + false_negatives))
return (; predicted_positives, predicted_negatives, actual_positives, actual_negatives,
true_positives, true_negatives, false_positives, false_negatives,
true_positive_rate, true_negative_rate, false_positive_rate,
Expand Down
27 changes: 27 additions & 0 deletions test/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@
@test isnan(stats.precision)
@test isnan(stats.f1)

c = [0 0
0 8]
stats = binary_statistics(c, 1)
@test stats.true_positives == 0
@test stats.true_negatives == 8
@test stats.false_positives == 0
@test stats.false_negatives == 0
@test isnan(stats.f1)

c = [0 2
0 6]
stats = binary_statistics(c, 1)
@test stats.true_positives == 0
@test stats.true_negatives == 6
@test stats.false_positives == 2
@test stats.false_negatives == 0
@test stats.f1 == 0

c = [0 0
2 6]
stats = binary_statistics(c, 1)
@test stats.true_positives == 0
@test stats.true_negatives == 6
@test stats.false_positives == 0
@test stats.false_negatives == 2
@test stats.f1 == 0

for p in 0:0.1:1
@test Lighthouse._cohens_kappa(p, p) == 0
if p > 0
Expand Down

4 comments on commit aef6df0

@alexmchan
Copy link
Member Author

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.

Error while trying to register: Register Failed
@alexmchan, it looks like you are not a publicly listed member/owner in the parent organization (beacon-biosignals).
If you are a member/owner, you will need to change your membership to public. See GitHub Help

@alexmchan
Copy link
Member Author

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/64281

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.12 -m "<description of version>" aef6df0086462d1bea150854f8d8e310be2737d3
git push origin v0.14.12

Please sign in to comment.