forked from tgao1337/detecting-fake-text
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_analyze_test.py
74 lines (52 loc) · 1.45 KB
/
json_analyze_test.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
# analyzes json files
import pandas as pd
import json
'''
df = pd.read_csv('titanic.csv')
print(df)
df = df.drop(['Name', 'Siblings/Spouses Aboard', 'Parents/Children Aboard'], axis=1)
print(df.head(8))
print(df['Survived'][4])
'''
def get_top_k_count(real_topk, top1 = 10, top2 = 100, top3 = 1000):
# takes in the json part for real_topk and returns the counts of top1,2,3,4
# top4 is just whatever is past the last number, for example >1000
t1 = 0
t2 = 0
t3 = 0
t4 = 0
for item in real_topk:
if(item[0] < top1):
t1 = t1 + 1
elif(item[0] < top2):
t2 = t2 + 1
elif(item[0] < top3):
t3 = t3 + 1
else:
t4 = t4 + 1
return [t1, t2, t3, t4]
def get_frac_p(real_topk, pred_topk):
res = []
for i in range(len(real_topk)):
res.append(real_topk[i][1] / pred_topk[i][0][1])
return res
with open('test_json.json') as json_file:
file = json.load(json_file)
realtk = file["result"]["real_topk"]
predtk = file["result"]["pred_topk"]
print(realtk)
realdf = pd.DataFrame(realtk)
print(realdf)
preddf = pd.DataFrame(predtk)
print(preddf)
print(preddf[19][0][1])
#realdf.to_csv("real.csv")
print(realdf.describe())
lst = []
for item in file["result"]["pred_topk"]:
lst.append(item[0][1])
'''for L in lst:
f = open("top_pred.txt", "w")
f.writelines(str(L)+'\n')'''
print(get_top_k_count(realtk))
print(get_frac_p(realtk, predtk))