-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmetrics.py
28 lines (19 loc) · 841 Bytes
/
metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
# coding: utf-8
# In[1]:
from sklearn.metrics import precision_recall_curve, auc, log_loss
def compute_prauc(pred, gt):
prec, recall, thresh = precision_recall_curve(gt, pred)
prauc = auc(recall, prec)
return prauc
def calculate_ctr(gt):
positive = len([x for x in gt if x == 1])
ctr = positive/float(len(gt))
return ctr
def compute_rce(pred, gt):
cross_entropy = log_loss(gt, pred)
data_ctr = calculate_ctr(gt)
strawman_cross_entropy = log_loss(gt, [data_ctr for _ in range(len(gt))])
return (1.0 - cross_entropy/strawman_cross_entropy)*100.0
#ground_truth = read_predictions("gt.csv") # will return data in the form (tweet_id, user_id, labed (1 or 0))
#predictions = read_predictions("predictions.csv") # will return data in the form (tweet_id, user_id, prediction)