def test_plot_com_stat(self): g = nx.karate_club_graph() coms = algorithms.louvain(g) coms2 = algorithms.label_propagation(g) viz.plot_com_stat([coms, coms2], evaluation.size) plt.savefig("cluster.pdf") os.remove("cluster.pdf") viz.plot_com_stat(coms, evaluation.size) plt.savefig("cluster.pdf") os.remove("cluster.pdf")
def draw_cluster_violin_map(list_of_communities): viz.plot_com_stat(list_of_communities, evaluation.size) plt.savefig("communities/size.png") viz.plot_com_stat(list_of_communities, evaluation.average_internal_degree) plt.savefig("communities/average_internal_degree.png") viz.plot_com_stat(list_of_communities, evaluation.edges_inside) plt.savefig("communities/edges_inside.png") viz.plot_com_stat(list_of_communities, evaluation.cut_ratio) plt.savefig("communities/cut_ratio.png")
# define the positions here so all the cluster plots in the loop are the same structure pos = nx.fruchterman_reingold_layout(nx_g) #%% # plot the original network with the ground truth communities viz.plot_network_clusters(nx_g, ground_truth_com, pos, figsize=(5, 5)) #nx.draw_networkx_labels(nx_g, pos=pos) plt.title(f'Ground Truth of {graph_name}') plt.show() #%% evaluate ground communitiy metrics viz.plot_com_properties_relation(ground_truth_com, evaluation.size, evaluation.internal_edge_density) plt.show() #%% viz.plot_com_stat(ground_truth_com, evaluation.conductance) plt.show() viz.plot_com_stat(ground_truth_com, evaluation.average_internal_degree) plt.show() algo_dict = {'louvain': algorithms.louvain, 'leidan': algorithms.leiden, 'greed_modularity': algorithms.greedy_modularity, 'label_prop': algorithms.label_propagation, 'walktrap': algorithms.walktrap, 'infomap': algorithms.infomap, 'eigenvector': algorithms.eigenvector, 'spinglass': algorithms.spinglass} # %% define algorithms and their names to iterate through algo_dict = {'louvain': algorithms.louvain,