Add compute code
Browse files
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 |
-
|
| 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,
|
| 90 |
"""Returns the scores"""
|
| 91 |
-
|
| 92 |
-
|
| 93 |
return {
|
| 94 |
-
"
|
| 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 |
}
|