-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistic_neighbors.py
90 lines (75 loc) · 2.28 KB
/
statistic_neighbors.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from tqdm import tqdm
user_ne_items_path = "saved/Electronics_5/user_ne_items.txt"
user_ne_users_path = "saved/Electronics_5/user_ne_30.txt"
item_ne_users_path = "saved/Electronics_5/item_ne_users.txt"
item_ne_items_path = "saved/Electronics_5/item_ne.txt"
"""
user:
sum_user_ne_items
sum_user_ne_users
avg_user_ne_items
avg_user_ne_users
item:
sum_item_ne_users
sum_item_ne_items
avg_item_ne_users
avg_item_ne_items
"""
sum_user_ne_items = 0
sum_user_ne_users = 0
avg_user_ne_items = 0
avg_user_ne_users = 0
sum_item_ne_users = 0
sum_item_ne_items = 0
avg_item_ne_users = 0
avg_item_ne_items = 0
with open(user_ne_items_path, 'r', encoding="utf-8") as fin:
lines = fin.readlines()
num_users = len(lines)
for line in tqdm(lines):
num_ne = len(line.split()) - 1
sum_user_ne_items += num_ne
avg_user_ne_items = sum_user_ne_items / num_users
with open(user_ne_users_path, 'r', encoding="utf-8") as fin:
lines = fin.readlines()
num_users = len(lines)
for line in tqdm(lines):
num_ne = len(line.split()) - 1
sum_user_ne_users += num_ne
avg_user_ne_users = sum_user_ne_users / num_users
with open(item_ne_users_path, 'r', encoding="utf-8") as fin:
lines = fin.readlines()
num_items = len(lines)
for line in tqdm(lines):
num_ne = len(line.split()) - 1
sum_item_ne_users += num_ne
avg_item_ne_users = sum_item_ne_users / num_items
with open(item_ne_items_path, 'r', encoding="utf-8") as fin:
lines = fin.readlines()
num_items = len(lines)
for line in tqdm(lines):
num_ne = len(line.split()) - 1
sum_item_ne_items += num_ne
avg_item_ne_items = sum_item_ne_items / num_items
print("""
user:
sum_user_ne_items = {}
sum_user_ne_users = {}
avg_user_ne_items = {}
avg_user_ne_users = {}
item:
sum_item_ne_users = {}
sum_item_ne_items = {}
avg_item_ne_users = {}
avg_item_ne_items = {}
""".format(
sum_user_ne_items,
sum_user_ne_users,
avg_user_ne_items,
avg_user_ne_users,
sum_item_ne_users,
sum_item_ne_items,
avg_item_ne_users,
avg_item_ne_items
)
)