Vlasta commited on
Commit
d406c9d
1 Parent(s): ebbf28c

Add compute code

Browse files
Files changed (1) hide show
  1. pr_auc.py +6 -5
pr_auc.py CHANGED
@@ -15,6 +15,7 @@
15
 
16
  import evaluate
17
  import datasets
 
18
 
19
 
20
  # TODO: Add BibTeX citation
@@ -28,7 +29,7 @@ year={2020}
28
 
29
  # TODO: Add description of the module here
30
  _DESCRIPTION = """\
31
- This new module is designed to solve this great ML task and is crafted with a lot of care.
32
  """
33
 
34
 
@@ -86,10 +87,10 @@ class PRAUC(evaluate.Metric):
86
  # TODO: Download external resources if needed
87
  pass
88
 
89
- def _compute(self, predictions, references):
90
  """Returns the scores"""
91
- # TODO: Compute the different scores of the module
92
- accuracy = sum(i == j for i, j in zip(predictions, references)) / len(predictions)
93
  return {
94
- "accuracy": accuracy,
95
  }
 
15
 
16
  import evaluate
17
  import datasets
18
+ from sklearn.metrics import precision_recall_curve, auc
19
 
20
 
21
  # TODO: Add BibTeX citation
 
29
 
30
  # TODO: Add description of the module here
31
  _DESCRIPTION = """\
32
+ Computes the area under precision-recall curve. Implementation details taken from https://sinyi-chou.github.io/python-sklearn-precision-recall/
33
  """
34
 
35
 
 
87
  # TODO: Download external resources if needed
88
  pass
89
 
90
+ def _compute(self, prediction_scores, references):
91
  """Returns the scores"""
92
+ precision, recall, thresholds = precision_recall_curve(references, prediction_scores)
93
+ auc_precision_recall = auc(recall, precision)
94
  return {
95
+ "pr_auc": auc_precision_recall,
96
  }