jkushwaha commited on
Commit
06ac6db
·
verified ·
1 Parent(s): 316f3f2

Create metric.py

Browse files
Files changed (1) hide show
  1. metric.py +20 -0
metric.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def calculate_precision_recall(df, gt_col, pred_col):
2
+ true_positives = 0
3
+ false_positives = 0
4
+ false_negatives = 0
5
+
6
+ for index, row in df.iterrows():
7
+ gt_value = row[gt_col]
8
+ pred_value = row[pred_col]
9
+
10
+ if gt_value and pred_value:
11
+ true_positives += 1
12
+ elif not gt_value and pred_value:
13
+ false_positives += 1
14
+ elif gt_value and not pred_value:
15
+ false_negatives += 1
16
+
17
+ precision = true_positives / (true_positives + false_positives) if (true_positives + false_positives) > 0 else 0
18
+ recall = true_positives / (true_positives + false_negatives) if (true_positives + false_negatives) > 0 else 0
19
+
20
+ return precision, recall