Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #257 from DeepRank/mcc_bug
Browse files Browse the repository at this point in the history
handle division by zero bug with mcc
  • Loading branch information
DarioMarzella committed Feb 15, 2023
2 parents 3d36229 + 41d1208 commit 46d4449
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion deeprank/learn/classMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ def mcc(yp, yt):
fp = false_positive(yp, yt)
fn = false_negative(yp, yt)
tp, tn, fp, fn = map(np.float64, [tp, tn, fp, fn])
mcc = (tp * tn - fp * fn) / np.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn))

denominator = np.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn))
# if denominator is zero and causes an error, set it to 1 (source: https://en.wikipedia.org/wiki/Phi_coefficient)
if denominator == 0:
mcc = 0
else:
mcc = (tp * tn - fp * fn) / denominator

return mcc

def true_positive(yp, yt):
Expand Down

0 comments on commit 46d4449

Please sign in to comment.