In [1]:
from sklearn.cluster import KMeans

In [2]:
km = KMeans(3)

In [15]:
class mage(object):
    def calc(self, x):
        return x + x
    
class muji(object):
    def calc(self, x):
        return 3 * x
    
class mister(mage, muji):
    def calc(self, x):
        y1 = super(mister, self).calc(x)
        y2 = super(mage, self).calc(x)
        return y1 + y2

In [16]:
ms = mister()

In [17]:
ms.calc(5)


Out[17]:
25

In [22]:
import pandas
import numpy

In [19]:
const = pandas.read_pickle("data/const/diff_degree_polblogs_0.05.pkl")

In [38]:
elist = numpy.array(pandas.read_pickle('data/polblogs_edge.pkl'))
labels = numpy.array(pandas.read_pickle('data/polblogs_label.pkl'))

In [29]:
degs = [(elist == i + 1).sum() for i in range(elist.max() - 1)]

In [30]:
for i, j in const:
    print(degs[i], degs[j])


0 48
0 88
0 162
0 11
0 1
0 51
0 37
0 0
0 33
0 0
0 4
0 22
0 2
0 13
0 2
0 0
0 2
0 16
0 24
0 40
4 48
4 88
4 162
4 11
4 1
4 51
4 37
4 0
4 33
4 0
4 4
4 22
4 2
4 13
4 2
4 0
4 2
4 16
4 24
4 40
1 48
1 88
1 162
1 11
1 1
1 51
1 37
1 0
1 33
1 0
1 4
1 22
1 2
1 13
1 2
1 0
1 2
1 16
1 24
1 40
0 48
0 88
0 162
0 11
0 1
0 51
0 37
0 0
0 33
0 0
0 4
0 22
0 2
0 13
0 2
0 0
0 2
0 16
0 24
0 40
0 48
0 88
0 162
0 11
0 1
0 51
0 37
0 0
0 33
0 0
0 4
0 22
0 2
0 13
0 2
0 0
0 2
0 16
0 24
0 40
1 48
1 88
1 162
1 11
1 1
1 51
1 37
1 0
1 33
1 0
1 4
1 22
1 2
1 13
1 2
1 0
1 2
1 16
1 24
1 40
351 48
351 88
351 162
351 11
351 1
351 51
351 37
351 0
351 33
351 0
351 4
351 22
351 2
351 13
351 2
351 0
351 2
351 16
351 24
351 40
4 48
4 88
4 162
4 11
4 1
4 51
4 37
4 0
4 33
4 0
4 4
4 22
4 2
4 13
4 2
4 0
4 2
4 16
4 24
4 40
0 48
0 88
0 162
0 11
0 1
0 51
0 37
0 0
0 33
0 0
0 4
0 22
0 2
0 13
0 2
0 0
0 2
0 16
0 24
0 40
2 48
2 88
2 162
2 11
2 1
2 51
2 37
2 0
2 33
2 0
2 4
2 22
2 2
2 13
2 2
2 0
2 2
2 16
2 24
2 40
7 48
7 88
7 162
7 11
7 1
7 51
7 37
7 0
7 33
7 0
7 4
7 22
7 2
7 13
7 2
7 0
7 2
7 16
7 24
7 40
150 48
150 88
150 162
150 11
150 1
150 51
150 37
150 0
150 33
150 0
150 4
150 22
150 2
150 13
150 2
150 0
150 2
150 16
150 24
150 40
124 48
124 88
124 162
124 11
124 1
124 51
124 37
124 0
124 33
124 0
124 4
124 22
124 2
124 13
124 2
124 0
124 2
124 16
124 24
124 40
4 48
4 88
4 162
4 11
4 1
4 51
4 37
4 0
4 33
4 0
4 4
4 22
4 2
4 13
4 2
4 0
4 2
4 16
4 24
4 40
7 48
7 88
7 162
7 11
7 1
7 51
7 37
7 0
7 33
7 0
7 4
7 22
7 2
7 13
7 2
7 0
7 2
7 16
7 24
7 40
49 48
49 88
49 162
49 11
49 1
49 51
49 37
49 0
49 33
49 0
49 4
49 22
49 2
49 13
49 2
49 0
49 2
49 16
49 24
49 40
0 48
0 88
0 162
0 11
0 1
0 51
0 37
0 0
0 33
0 0
0 4
0 22
0 2
0 13
0 2
0 0
0 2
0 16
0 24
0 40
19 48
19 88
19 162
19 11
19 1
19 51
19 37
19 0
19 33
19 0
19 4
19 22
19 2
19 13
19 2
19 0
19 2
19 16
19 24
19 40
10 48
10 88
10 162
10 11
10 1
10 51
10 37
10 0
10 33
10 0
10 4
10 22
10 2
10 13
10 2
10 0
10 2
10 16
10 24
10 40
5 122
5 42
5 12
5 85
5 23
5 2
5 0
5 3
5 20
5 25
5 23
5 0
5 20
5 68
5 1
5 7
5 17
5 13
5 20
5 0
0 122
0 42
0 12
0 85
0 23
0 2
0 0
0 3
0 20
0 25
0 23
0 0
0 20
0 68
0 1
0 7
0 17
0 13
0 20
0 0
2 122
2 42
2 12
2 85
2 23
2 2
2 0
2 3
2 20
2 25
2 23
2 0
2 20
2 68
2 1
2 7
2 17
2 13
2 20
2 0
7 122
7 42
7 12
7 85
7 23
7 2
7 0
7 3
7 20
7 25
7 23
7 0
7 20
7 68
7 1
7 7
7 17
7 13
7 20
7 0
34 122
34 42
34 12
34 85
34 23
34 2
34 0
34 3
34 20
34 25
34 23
34 0
34 20
34 68
34 1
34 7
34 17
34 13
34 20
34 0
3 122
3 42
3 12
3 85
3 23
3 2
3 0
3 3
3 20
3 25
3 23
3 0
3 20
3 68
3 1
3 7
3 17
3 13
3 20
3 0
13 122
13 42
13 12
13 85
13 23
13 2
13 0
13 3
13 20
13 25
13 23
13 0
13 20
13 68
13 1
13 7
13 17
13 13
13 20
13 0
3 122
3 42
3 12
3 85
3 23
3 2
3 0
3 3
3 20
3 25
3 23
3 0
3 20
3 68
3 1
3 7
3 17
3 13
3 20
3 0
0 122
0 42
0 12
0 85
0 23
0 2
0 0
0 3
0 20
0 25
0 23
0 0
0 20
0 68
0 1
0 7
0 17
0 13
0 20
0 0
1 122
1 42
1 12
1 85
1 23
1 2
1 0
1 3
1 20
1 25
1 23
1 0
1 20
1 68
1 1
1 7
1 17
1 13
1 20
1 0
45 122
45 42
45 12
45 85
45 23
45 2
45 0
45 3
45 20
45 25
45 23
45 0
45 20
45 68
45 1
45 7
45 17
45 13
45 20
45 0
0 122
0 42
0 12
0 85
0 23
0 2
0 0
0 3
0 20
0 25
0 23
0 0
0 20
0 68
0 1
0 7
0 17
0 13
0 20
0 0
1 122
1 42
1 12
1 85
1 23
1 2
1 0
1 3
1 20
1 25
1 23
1 0
1 20
1 68
1 1
1 7
1 17
1 13
1 20
1 0
138 122
138 42
138 12
138 85
138 23
138 2
138 0
138 3
138 20
138 25
138 23
138 0
138 20
138 68
138 1
138 7
138 17
138 13
138 20
138 0
5 122
5 42
5 12
5 85
5 23
5 2
5 0
5 3
5 20
5 25
5 23
5 0
5 20
5 68
5 1
5 7
5 17
5 13
5 20
5 0
0 122
0 42
0 12
0 85
0 23
0 2
0 0
0 3
0 20
0 25
0 23
0 0
0 20
0 68
0 1
0 7
0 17
0 13
0 20
0 0
40 122
40 42
40 12
40 85
40 23
40 2
40 0
40 3
40 20
40 25
40 23
40 0
40 20
40 68
40 1
40 7
40 17
40 13
40 20
40 0
15 122
15 42
15 12
15 85
15 23
15 2
15 0
15 3
15 20
15 25
15 23
15 0
15 20
15 68
15 1
15 7
15 17
15 13
15 20
15 0
0 122
0 42
0 12
0 85
0 23
0 2
0 0
0 3
0 20
0 25
0 23
0 0
0 20
0 68
0 1
0 7
0 17
0 13
0 20
0 0

In [39]:
numpy.unique(elist).size


Out[39]:
1224

In [37]:
elist


Out[37]:
array([[ 266, 1393],
       [ 266,  482],
       [ 266, 1050],
       ..., 
       [1132, 1422],
       [1132, 1407],
       [1132, 1151]])

In [41]:
labels.size


Out[41]:
1490

In [42]:
id_map = {nid: index for index, nid in enumerate(numpy.unique(elist))}

In [44]:
labels_ = [labels[nid] for nid in numpy.unique(elist)]

In [45]:
labels_


Out[45]:
[0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,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
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 1,
 ...]

In [46]:
edge_list = []
for e1, e2 in elist:
    edge_list.append((id_map[e1], id_map[e2]))

In [49]:
numpy.array(edge_list).max()


Out[49]:
1223

In [50]:
pandas.to_pickle(edge_list, "data/polblogs_edge.pkl")
pandas.to_pickle(labels_, "data/polblogs_label.pkl")

In [51]:
elist = numpy.array(pandas.read_pickle('data/polbooks_edge.pkl'))
labels = numpy.array(pandas.read_pickle('data/polbooks_label.pkl'))

In [53]:
elist.max()


Out[53]:
104

In [55]:
numpy.unique(elist).size


Out[55]:
105

In [56]:
elist = numpy.array(pandas.read_pickle('data/football_edge.pkl'))
labels = numpy.array(pandas.read_pickle('data/football_label.pkl'))

In [58]:
elist.max()


Out[58]:
114

In [60]:
numpy.unique(elist).size


Out[60]:
115

In [ ]: