Skip to content

Commit

Permalink
[#179] Create precision() and recall() functions in core.model_metrics
Browse files Browse the repository at this point in the history
_get_aggregate_metrics() now calls these core library functions.
  • Loading branch information
riley-harper committed Dec 11, 2024
1 parent c166ace commit df9b463
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 18 additions & 0 deletions hlink/linking/core/model_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@ def mcc(tp: int, tn: int, fp: int, fn: int) -> float:
else:
mcc = 0
return mcc


def precision(tp: int, fp: int) -> float:
if (tp + fp) == 0:
precision = np.nan
else:
precision = tp / (tp + fp)

return precision


def recall(tp: int, fn: int) -> float:
if (tp + fn) == 0:
recall = np.nan
else:
recall = tp / (tp + fn)

return recall
10 changes: 2 additions & 8 deletions hlink/linking/model_exploration/link_step_train_test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,14 +774,8 @@ def _get_aggregate_metrics(
Return a tuple of (precision, recall, Matthews Correlation Coefficient).
"""
if (true_positives + false_positives) == 0:
precision = np.nan
else:
precision = true_positives / (true_positives + false_positives)
if (true_positives + false_negatives) == 0:
recall = np.nan
else:
recall = true_positives / (true_positives + false_negatives)
precision = metrics_core.precision(true_positives, false_positives)
recall = metrics_core.recall(true_positives, false_negatives)
mcc = metrics_core.mcc(
true_positives, true_negatives, false_positives, false_negatives
)
Expand Down

0 comments on commit df9b463

Please sign in to comment.