text_plain_output_1.png
import matplotlib.pyplot as plt

import networkx as nx

import numpy as np

import pandas as pd

nodes = pd.read_csv('../input/tolokers/nodes.tsv', sep='\t', index_col='id')
nodes

edges = pd.read_csv('../input/tolokers/edges.tsv', sep='\t')
edges

G = nx.Graph()
G.add_edges_from(edges.values)

node_degrees = {}
for node in G.nodes():
    node_degrees[node] = len(list(G.neighbors(node)))

def freedman_diaconis(data):
    IQR = np.percentile(data, 75) - np.percentile(data, 25)
    bin_width = 2 * IQR / len(data) ** (1 / 3)
    data_range = max(data) - min(data)
    num_bins = int(np.ceil(data_range / bin_width))
    return num_bins

degrees_dist = np.array(list(node_degrees.values()))
plt.hist(degrees_dist, bins=freedman_diaconis(degrees_dist))
plt.xlim([0, 500])
plt.xlabel('Degree')
plt.ylabel('Frequency')
plt.show()