-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy patheval.py
More file actions
executable file
·88 lines (62 loc) · 1.97 KB
/
Copy patheval.py
File metadata and controls
executable file
·88 lines (62 loc) · 1.97 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
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
#!/usr/bin/python -tt
# dialect detection evlaution code.
#
# Copyright (C) 2016, Qatar Computing Research Institute, HBKU (author: Ahmed Ali)
#
from __future__ import division
import sys
reload(sys)
import itertools
import numpy as np
sys.setdefaultencoding('utf8')
langList = ['EGY', 'GLF', 'LAV', 'MSA','NOR']
_len = len(langList)
if len(sys.argv) != 3 :
print 'usage: eval.py ref hyp'
sys.exit (1)
testFeatFile = sys.argv[1]
predFile = sys.argv[2]
truth = []
with open(testFeatFile) as f:
content = f.readlines()
for line in content: truth.append (langList.index(line.split ( )[-1]));
f.close()
claasifier =[]
with open(predFile) as f:
content = f.readlines()
for line in content: claasifier.append (langList.index(line.split ( )[-1]));
f.close()
results = np.zeros((_len, _len))
for _t, _g in zip(truth, claasifier):
_truthIdx = int(_t) - 1
_claasifierIdx = int(_g) - 1
results[_truthIdx][_claasifierIdx] += 1
total_accuracy = np.zeros((_len))
total_i = total_accuracy [:]
total_j = total_accuracy [:]
total_accuracy = np.diagonal(results)
total_i = np.sum(results, axis=1)
total_j = np.sum(results, axis=0)
recall=[]
prec=[]
for _acc, _pre, _rec in itertools.izip(total_accuracy, total_i, total_j):
recall.append('%0.2f' % (_acc/_pre*100))
prec.append('%0.2f' % (_acc/_rec*100))
print 'Overal Accuracy : %0.2f' % (sum(total_accuracy)/sum(total_i)*100)+'%'
print 'Average Precision: %0.2f' % (sum(float(item) for item in prec)/_len)+'%'
print 'Avergae Recall : %0.2f' % (sum(float(item) for item in recall)/_len)+'%'
print "\t\t ", "Predicted dialects", "\t\t\tTotalTruth Precision:"
for i in range(_len):
print langList[i], "\t\t",
for j in range(_len):
print results[i][j], "\t",
print '||',total_i[i], "\t",
print '%s' % (prec[i])+'%'
print "\ntotalClass:\t",
for item in total_j:
print item,"\t",
print ''
print "Recall:\t\t",
for item in recall:
print '%s' % (item)+'%',
print '\n\n'