-
Notifications
You must be signed in to change notification settings - Fork 3
/
degree_closeness_enron.py
executable file
·73 lines (51 loc) · 1.24 KB
/
degree_closeness_enron.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
import pandas as pd
import numpy as np
import networkx as nx
import pickle
dataset_edges = pd.read_csv('enrondatasetfinal.csv')
dataset_nodes = pd.read_csv('Enron.true', sep = ';', header = None)
node_from = dataset_edges.iloc[:,0].values
node_to = dataset_edges.iloc[:,1].values
num_nodes = len(dataset_nodes)
print num_nodes
# Creare graph
G = nx.Graph()
for i, j in zip(node_from, node_to):
G.add_edge(i, j)
d = G.degree(G.nodes())
# print d
max_ = 0
ind = 0
for a, b in d:
if b > max_:
max_ = b
ind = a
print max_, ind
'''
output = open('degree_list_tup.pkl', 'wb')
pickle.dump(d, output)
output.close()
'''
pkl_file = open('degree_list_tup.pkl','rb')
d = pickle.load(pkl_file)
pkl_file2 = open('closeness_dict.pkl', 'rb')
d_closeness = pickle.load(pkl_file2)
closeness_nodes = []
for k,v in d_closeness.iteritems():
if v>0.25:
closeness_nodes.append(k)
cnt = 0
for item in d:
if item[0] in closeness_nodes and item[1]>70:
cnt += 1
print cnt
cnt = [item for item in d if item[1]>70]
print len(cnt)
outfile = open('degree_enron_data.txt', 'w')
for i, j in d:
if j > 70:
outfile.write(str(i) + " 1\n")
else:
outfile.write(str(i) + " 0\n")
outfile.close()
pkl_file.close()