In [1]:
%matplotlib inline
import networkx as nx
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [2]:
G=nx.barbell_graph(10,10)
print('nx.core_number(G) : {}'.format(nx.core_number(G)))
print()
k=max(nx.core_number(G).values())
print('max(nx.core_number(G).values()): {}'.format(max(nx.core_number(G).values())))
nx.draw(G)
In [3]:
k_core = nx.k_core(G)
print('nx.core_number(G) : {}'.format(nx.core_number(G)))
print()
k=max(nx.core_number(G).values())
print('max(nx.core_number(G).values()): {}'.format(max(nx.core_number(G).values())))
nx.draw(k_core)
In [4]:
for node in k_core:
print('Node {} | degree {}'.format(node, G.degree(node)))
In [5]:
for node in k_core:
print('Node {} | degree {}'.format(node, k_core.degree(node)))
In [11]:
PATH = "../../data/raw/"
FILE_NETWORK_SOCIAL_EXAMPLE = "higgs-retweet_network.edgelist"
In [14]:
data = pd.read_csv(PATH + FILE_NETWORK_SOCIAL_EXAMPLE, sep=' ', names = ['source', 'target','weight'])
data.head()
Out[14]:
In [15]:
G1 = nx.DiGraph()
for idx,row in data.iterrows():
G1.add_edge(row['target'], row['source'], weight= row['weight'])
In [18]:
k=max(nx.core_number(G1).values())
print('max(nx.core_number(G).values()): {}'.format(max(nx.core_number(G1).values())))
In [45]:
k_core = nx.k_core(G1)
nx.draw(k_core)
In [43]:
k_core = nx.k_core(G1)
pos = nx.spring_layout(k_core,k=0.2)
nx.draw(k_core,with_labels = True, pos=pos,node_size=500, font_size=8)
In [48]:
nx.isolates(k_core)
Out[48]:
In [42]:
k_core = nx.k_core(G1)
pos = nx.spring_layout(k_core,k=0.2)
nx.draw(k_core,with_labels = True, edgelist=[], pos=pos,node_size=500, font_size=8)
In [21]:
for node in k_core:
print('Node {} | degree {}'.format(node, G1.degree(node)))
In [20]:
for node in k_core:
print('Node {} | degree {}'.format(node, k_core.degree(node)))