-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_compare.py
54 lines (50 loc) · 1.6 KB
/
data_compare.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
#!/usr/bin/env python
# encoding: utf-8
'''
@author: caopeng
@license: (C) Copyright 2016-2020, Big Bird Corporation Limited.
@contact: [email protected]
@software: garner
@file: data_compare.py
@time: 2019/7/11 23:17
@desc:
'''
import codecs
def getXPredictLabelList(filePath):
fileReadObj = codecs.open(filePath, 'r', encoding='utf8')
lines = fileReadObj.readlines()
labelList = []
for line in lines:
if line.strip('\n').strip('\r').strip(' ') == '':
continue
s = line.strip('\n').strip('\r').strip(' ').split(' ')
x = float(s[0])
if x>0.5:
labelList.append(1)
else:
labelList.append(0)
return labelList
def getXLabelList(filePath):
fileReadObj = codecs.open(filePath, 'r', encoding='utf8')
lines = fileReadObj.readlines()
labelList = []
for line in lines:
if line.strip('\n').strip('\r').strip(' ') == '':
continue
s = line.strip('\n').strip('\r').strip(' ').split(' ')
x = int(s[0])
labelList.append(x)
return labelList
if __name__ == '__main__':
filePredictPath = './test_data/test_data_domainAttention_result-0712.txt'
fileLabelPath = './test_data/test_data_domain_label.txt'
filePredictList = getXPredictLabelList(filePredictPath)
fileLabelList = getXLabelList(fileLabelPath)
size = len(filePredictList)
equalSize = 0
for ii in range(size):
if filePredictList[ii] == fileLabelList[ii]:
equalSize = equalSize + 1
print(' === size : ' , size)
print(' === equalSize : ', equalSize)
print(1.0*equalSize/size)