forked from UTA-HEP-Computing/EventClassificationDNN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysis.py
More file actions
48 lines (33 loc) · 1.4 KB
/
Analysis.py
File metadata and controls
48 lines (33 loc) · 1.4 KB
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
# Analysis
import numpy as np
import matplotlib as mpl
mpl.use('pdf')
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc
mpColors = ['red', 'darkorange', 'lawngreen', 'green', 'lightseagreen', 'cyan', 'royalblue', 'blue', 'blueviolet', 'magenta', 'hotpink']
def ClassificationAnalysis (MyModel, Test_X, Test_Y, BatchSize, SignalClassIndex=5):
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=mpColors[SignalClassIndex],
lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)
print 'ROC', SignalClassIndex, 'AUC:', roc_auc
pass
def MultiClassificationAnalysis (MyModel, Test_X, Test_Y, BatchSize):
print 'Prediction Analysis.'
result = MyModel.Model.predict (Test_X, batch_size=BatchSize)
NClasses = Test_Y.shape[1]
for ClassIndex in xrange(NClasses):
ClassificationAnalysis (MyModel, Test_X, Test_Y, BatchSize, ClassIndex)
pass
lw=2
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