-
Notifications
You must be signed in to change notification settings - Fork 3
/
czech_bank_dataloader.py
64 lines (47 loc) · 1.56 KB
/
czech_bank_dataloader.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
import pandas as pd
import networkx as nx
#import swifter
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import collections
import pickle
filename='data/czech-bank/data/trans.csv'
transactions = pd.read_csv(filename).dropna(subset=['account'])
G = nx.DiGraph()
node2idx = {}
counter = 0
def create_edge(transaction):
global G, node2idx, counter
if not node2idx.get(transaction['account_id'], None):
node2idx[transaction['account_id']] = counter
counter += 1
u = node2idx[transaction['account_id']]
if not node2idx.get(transaction['account'], None):
node2idx[transaction['account']] = counter
counter += 1
v = node2idx[transaction['account']]
amount = float(transaction['amount'])
G.add_edge(u, v, weight=amount)
transactions.apply(create_edge, axis=1)
with open('cb.pickle', 'wb+') as f:
pickle.dump(G, f)
def analyze_dataset(G):
outdeg = [G.out_degree(v) for v in G]
indeg = [G.in_degree(v) for v in G]
outdegs, outdegs_counts = np.unique(outdeg, return_counts=True)
indegs, indegs_counts = np.unique(indeg, return_counts=True)
outdegs_counts = outdegs_counts / outdegs_counts.sum()
indegs_counts = indegs_counts / indegs_counts.sum()
plt.figure()
plt.plot(outdegs, outdegs_counts)
plt.title('Outdegree Distribution')
plt.xlabel('Outdegree')
plt.ylabel('Frequency')
plt.figure()
plt.plot(indegs, indegs_counts)
plt.title('Indegree Distribution')
plt.xlabel('Indegree')
plt.ylabel('Frequency')
plt.show()