-
Notifications
You must be signed in to change notification settings - Fork 2
/
Analysis.py
75 lines (48 loc) · 1.99 KB
/
Analysis.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Analysis
import numpy as np
def ClassificationAnalysis(MyModel,Test_X,Test_Y,BatchSize, SignalClassIndex=5):
import matplotlib as mpl
mpl.use('pdf')
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc
print "Prediction Analysis."
result = MyModel.Model.predict(Test_X, batch_size=BatchSize)
fpr, tpr, _ = roc_curve(Test_Y[:,SignalClassIndex],
result[:,SignalClassIndex])
roc_auc = auc(fpr, tpr)
lw=2
plt.plot(fpr,tpr,color='darkorange',
lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)
print "ROC AUC: ",roc_auc
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.legend(loc="lower right")
plt.savefig(MyModel.OutDir+"/ROC.pdf")
mpColors=["blue","green","red","cyan","magenta","yellow","black","white"]
def MultiClassificationAnalysis(MyModel,Test_X,Test_Y,BatchSize):
import matplotlib as mpl
mpl.use('pdf')
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc
print "Prediction Analysis."
result = MyModel.Model.predict(Test_X, batch_size=BatchSize)
NClasses=Test_Y.shape[1]
for ClassIndex in xrange(0,NClasses):
fpr, tpr, _ = roc_curve(Test_Y[:,ClassIndex],
result[:,ClassIndex])
roc_auc = auc(fpr, tpr)
lw=2
plt.plot(fpr,tpr,color=mpColors[ClassIndex],
lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)
print "ROC ",ClassIndex," AUC: ",roc_auc
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.legend(loc="lower right")
plt.savefig(MyModel.OutDir+"/ROC.pdf")
return result