Ukandu commited on
Commit
2bf8d09
·
verified ·
1 Parent(s): 6a5607a

Create results_parser.py

Browse files
Files changed (1) hide show
  1. app/services/results_parser.py +39 -0
app/services/results_parser.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from sklearn.metrics import (
3
+ roc_auc_score,
4
+ average_precision_score,
5
+ f1_score,
6
+ precision_recall_curve
7
+ )
8
+
9
+ def parse_results(pred_path, gold_path, threshold=0.5):
10
+ pred = pd.read_csv(pred_path, sep="\t")
11
+ gold = pd.read_csv(gold_path, sep="\t")
12
+
13
+ gold_edges = set(
14
+ zip(gold.iloc[:, 0], gold.iloc[:, 1])
15
+ )
16
+
17
+ y_true = []
18
+ y_score = []
19
+
20
+ for _, row in pred.iterrows():
21
+ edge = (row[0], row[1])
22
+ y_true.append(1 if edge in gold_edges else 0)
23
+ y_score.append(row[2])
24
+
25
+ auroc = roc_auc_score(y_true, y_score)
26
+ auprc = average_precision_score(y_true, y_score)
27
+
28
+ y_pred = [1 if s >= threshold else 0 for s in y_score]
29
+ f1 = f1_score(y_true, y_pred)
30
+
31
+ precision, recall, _ = precision_recall_curve(y_true, y_score)
32
+
33
+ return {
34
+ "auroc": auroc,
35
+ "auprc": auprc,
36
+ "f1": f1,
37
+ "precision_curve": precision.tolist(),
38
+ "recall_curve": recall.tolist()
39
+ }