-
Notifications
You must be signed in to change notification settings - Fork 16
/
Evaluate.py
26 lines (21 loc) · 938 Bytes
/
Evaluate.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
from sklearn.metrics import confusion_matrix, roc_curve, auc
import numpy as np
def evaluate_accuracy(predictions, targets):
accuracy = np.mean(predictions == targets)
return accuracy
def evaluate_stat(predictions, targets, prob_pred):
""" compute evaluation statistics"""
accuracy = evaluate_accuracy(predictions, targets)
tp = np.sum(predictions[np.where(targets)])
tn = np.sum(predictions[np.where(targets==0)]==0)
sensitivity = tp / np.sum(targets)
specificity = tn / np.sum(targets==0)
precision = tp / np.sum(predictions)
recall = tn / np.sum(predictions == 0)
fpr, tpr, thresholds = roc_curve(targets, prob_pred, pos_label=0)
auc_value = auc(fpr, tpr)
return (accuracy, sensitivity, specificity, precision, recall, auc_value)
def evaluate_confusion(predictions, targets):
""" compute confusion matrix"""
cm = confusion_matrix(targets, predictions)
return cm