Network analysis: when things get out of control

mediumThis post was originally published by Gonzalo Ferreiro Volpi at Medium [AI]

Eigenvector centrality

import networkx as nxfull_net = nx.Graph()
full_net.add_nodes_from(list_of_nodes)full_net.add_edges_from(edges_from_node_to_node)
eigen_original = nx.eigenvector_centrality(full_net)
def get_centrality_df(centrality):    cent_dict_cust = {‘node’:[],’centrality’:[]}    for node, c in zip(centrality.keys(), centrality.values()):        cent_dict_cust[‘node’].append(node)        cent_dict_cust[‘centrality’].append(c)    cent_df = pd.DataFrame(cent_dict_cust)    return cent_df
full_centrality_df = get_centrality_df(eigen_original)
full_centrality_df.sort_values(by=’centrality’, ascending=False)

Projected networks

import networkx as nxcust_vs_all_network = nx.Graph()
cust_vs_all_network.add_nodes_from(customers, bipartite=0)cust_vs_all_network.add_nodes_from(all_other_nodes, bipartite=1)cust_vs_all_network.add_edges_from(edges_from_customers_to_others)
customers_proj = bipartite.projected_graph(cust_vs_all_network, customers)cust_all_others_proj = bipartite.projected_graph(cust_vs_all_network, all_other_nodes)
print(‘Number of connections for top 10:’)sorted([x for x in list(customers_proj.degree())],key=lambda x: x[1], reverse=True)[:10]
Spread the word

This post was originally published by Gonzalo Ferreiro Volpi at Medium [AI]

Related posts