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 #221 from DeepRank/fix_classmetrics_dtype
Browse files Browse the repository at this point in the history
Change data type from int64 to float64 for classMetrics
  • Loading branch information
CunliangGeng committed Mar 17, 2021
2 parents 66184e7 + b4b8ab1 commit c982c85
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion deeprank/learn/classMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def specificity(yp, yt):
if n == 0:
warnings.warn(
f'Number of negative cases is 0, '
f'TNR or sepcificity is assigned as inf')
f'TNR or specificity is assigned as inf')
tnr = float('inf')
else:
tnr = tn / n
Expand All @@ -62,6 +62,7 @@ def precision(yp, yt):
"""
tp = true_positive(yp, yt)
fp = false_positive(yp, yt)
tp, fp = map(np.float64, [tp, fp])
if tp + fp == 0:
warnings.warn(
f'Total number of true positive and false positive cases is 0, '
Expand All @@ -86,6 +87,7 @@ def accuracy(yp, yt):
tn = true_negative(yp, yt)
p = positive(yt)
n = negative(yt)
tp, tn, p, n = map(np.float64, [tp, tn, p, n])
acc = (tp + tn) / (p + n)
return acc

Expand All @@ -103,6 +105,7 @@ def F1(yp, yt):
tp = true_positive(yp, yt)
fp = false_positive(yp, yt)
fn = false_negative(yp, yt)
tp, fp, fn = map(np.float64, [tp, fp, fn])
f1 = 2 * tp / (2 * tp + fp + fn)
return f1

Expand All @@ -120,6 +123,7 @@ def mcc(yp, yt):
tn = true_negative(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))
return mcc

Expand Down

0 comments on commit c982c85

Please sign in to comment.