forked from thunlp/OpenNRE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_pr.py
More file actions
33 lines (28 loc) · 1.18 KB
/
plot_pr.py
File metadata and controls
33 lines (28 loc) · 1.18 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
import numpy as np
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import average_precision_score
import matplotlib.pyplot as plt
import numpy as np
plt.clf()
filename = ['CNN+ATT','Hoffmann','MIMLRE','Mintz','PCNN+ATT']
color = ['red', 'turquoise', 'darkorange', 'cornflowerblue', 'teal']
for i in range(len(filename)):
precision = np.load('./data/'+filename[i]+'_precision.npy')
recall = np.load('./data/'+filename[i]+'_recall.npy')
plt.plot(recall,precision,color = color[i],lw=2,label = filename[i])
#ATTENTION: put the model iters you want to plot into the list
model_iter = [10900]
for one_iter in model_iter:
y_true = np.load('./data/allans.npy')
y_scores = np.load('./out/sample_allprob_iter_'+str(one_iter)+'.npy')
precision,recall,threshold = precision_recall_curve(y_true,y_scores)
average_precision = average_precision_score(y_true, y_scores)
plt.plot(recall[:], precision[:], lw=2, color='navy',label='BGRU+2ATT')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.ylim([0.3, 1.0])
plt.xlim([0.0, 0.4])
plt.title('Precision-Recall Area={0:0.2f}'.format(average_precision))
plt.legend(loc="upper right")
plt.grid(True)
plt.savefig('iter_'+str(one_iter))