forked from shashankgarg1/GA-SVN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplots.py
116 lines (100 loc) · 4.19 KB
/
plots.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 14 22:37:50 2017
@author: shashank
"""
import matplotlib.pyplot as plt
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import average_precision_score
from sklearn.preprocessing import label_binarize
import numpy as np
def plot_graph(sol):
accuracies=[]
for i in range(len(sol)):
accuracies.append(sol[i][3])
ind=np.argmax(accuracies)
y_test=sol[ind][9]
y_test = label_binarize(y_test, classes=['B','M'])
y_score=sol[ind][10]
precision_plot, recall_plot, _ = precision_recall_curve(y_test,y_score)
average_precision_plot = average_precision_score(y_test, y_score)
# Compute micro-average ROC curve and ROC area
precision_micro, recall_micro, _ = precision_recall_curve(y_test.ravel(),y_score.ravel())
average_precision_micro = average_precision_score(y_test, y_score,average="micro")
lw = 2
# Plot Precision-Recall curve
plt.clf()
plt.plot(recall_plot, precision_plot, lw=lw, color='navy',label='Precision-Recall curve')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.ylim([0.0, 1.05])
plt.xlim([0.0, 1.0])
plt.title('Precision-Recall: AUC={0:0.2f}'.format(average_precision_plot))
plt.legend(loc="lower left")
plt.show()
###############################################################################
plt.clf()
plt.plot(recall_micro, precision_micro, color='gold', lw=lw,
label='micro-average Precision-recall curve (area = {0:0.2f})'
''.format(average_precision_micro))
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.title('micro-average Precision-Recall curve')
plt.legend(loc="lower right")
plt.show()
#plotting the worst output
ind=np.argmin(accuracies)
y_test=sol[ind][9]
y_test = label_binarize(y_test, classes=['B','M'])
y_score=sol[ind][10]
precision_plot, recall_plot, _ = precision_recall_curve(y_test,y_score)
average_precision_plot = average_precision_score(y_test, y_score)
# Compute micro-average ROC curve and ROC area
precision_micro, recall_micro, _ = precision_recall_curve(y_test.ravel(),y_score.ravel())
average_precision_micro = average_precision_score(y_test, y_score,average="micro")
lw = 2
# Plot Precision-Recall curve
plt.clf()
plt.plot(recall_plot, precision_plot, lw=lw, color='navy',
label='Precision-Recall curve')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.ylim([0.0, 1.05])
plt.xlim([0.0, 1.0])
plt.title('Precision-Recall: AUC={0:0.2f}'.format(average_precision_plot))
plt.legend(loc="lower left")
plt.show()
###############################################################################
#plotting the average output
ind=1
y_test=sol[ind][9]
y_test = label_binarize(y_test, classes=['B','M'])
y_score=sol[ind][10]
precision_plot, recall_plot, _ = precision_recall_curve(y_test,
y_score)
average_precision_plot = average_precision_score(y_test, y_score)
# Compute micro-average ROC curve and ROC area
precision_micro, recall_micro, _ = precision_recall_curve(y_test.ravel(),
y_score.ravel())
average_precision_micro = average_precision_score(y_test, y_score,
average="micro")
lw = 2
# Plot Precision-Recall curve
plt.clf()
plt.plot(recall_plot, precision_plot, lw=lw, color='navy',
label='Precision-Recall curve')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.ylim([0.0, 1.05])
plt.xlim([0.0, 1.0])
plt.title('Precision-Recall: AUC={0:0.2f}'.format(average_precision_plot))
plt.legend(loc="lower left")
plt.show()
###############################################################################
for i, color in zip(range(n_classes), colors):
plt.plot(recall[i], precision[i], color=color, lw=lw,
label='Precision-recall curve of class {0} (area = {1:0.2f})'
''.format(i, average_precision[i]))