-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval.py
42 lines (33 loc) · 991 Bytes
/
eval.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
#!/usr/bin/env python3
import sys
import numpy as np
import matplotlib.pyplot as plt
from dataset import DataSet
from classifier import Classifier
if len(sys.argv) < 2:
print('Usage: eval.py source')
sys.exit(-1)
source = sys.argv[1]
dataset = DataSet(source)
documents = dataset.all_documents
classifier = Classifier(documents)
evaluation = classifier.eval()
fig, ax = plt.subplots()
plt.suptitle(source)
ax.axis(xmin=-0.05, xmax=1.05, ymin=-0.05, ymax=1.05)
ax.set_xlabel('recall')
ax.set_ylabel('precision')
ax.grid()
linesep = '-' * 50
print(linesep)
print('number of documents: {}'.format(len(documents)))
print(linesep)
for name, scores in evaluation.items():
for scoring, values in scores.items():
print('{:20} {:10}: {:5.3f} (std={:5.3f})'.format(name, scoring, np.mean(values), np.std(values)))
print(linesep)
x = scores['recall']
y = scores['precision']
ax.plot(x, y, 'o', label=name, alpha=0.5)
ax.legend(loc='lower right')
plt.show()