aff = run_rwr(subgraph, 0.2, 1000) y_test = [] for node1, node2 in node_pairs: y_test.append(aff[int(node1)][int(node2)]) print( f"ROC AUC Score with Random Walk: {roc_auc_score(df['link'], y_test)}\n" f"Average Precision with Random Walk: {average_precision_score(df['link'], y_test)}" ) if __name__ == '__main__': nodes_file = "data/facebook_large/musae_facebook_target.csv" edges_file = "data/facebook_large/musae_facebook_edges.csv" features_file = 'data/facebook_large/musae_facebook_features.json' facebook_graph = read_graph(nodes_file, edges_file, features_file, 'facebook') subgraph, df = create_samples(facebook_graph) node_pairs = [tuple(x) for x in df[['id_1', 'id_2']].to_numpy()] link_prediction_with_metrics(subgraph, node_pairs, df) link_prediction_with_random_walk(subgraph, node_pairs, df) nodes_file = "data/git_web_ml/musae_git_target.csv" edges_file = "data/git_web_ml/musae_git_edges.csv" features_file = 'data/git_web_ml/musae_git_features.json' git_graph = read_graph(nodes_file, edges_file, features_file, 'git') subgraph, df = create_samples(git_graph) node_pairs = [tuple(x) for x in df[['id_1', 'id_2']].to_numpy()]
sorted_hubs = sorted(hubs.keys(), key=lambda x: hubs[x], reverse=True) with open(file_hubs, 'w') as f: for user in sorted_hubs: f.write(str(user) + " : " + str(hubs[user]) + "\n") # Auth sorted_auth = sorted(auth.keys(), key=lambda x: auth[x], reverse=True) with open(file_auth, 'w') as f: for user in sorted_auth: f.write(str(user) + " : " + str(auth[user]) + "\n") # Hubs Print graph = read_graph(file) pos = nx.spring_layout(graph) nx.draw(graph, pos, with_labes=True, font_weight='bold', **options) plt.show() lista = sorted_pr nx.draw(graph, pos, with_labes=True, font_weight='bold', **options) nx.draw_networkx_nodes(graph, pos, nodelist=lista[33:35], node_color='b', node_size=10, alpha=0.8) plt.show() plt.show()
""" Plotar Grafo Direcionado e Não Direcionado """ import networkx as nx import matplotlib.pyplot as plt from helper import read_graph, read_digraph # print options file = "graphs\clean_graph.txt" options = { 'node_color': 'red', 'node_size': 5, 'width': 0.5 } # read graph graph = read_graph() # plot pos = nx.spring_layout(graph) nx.draw(graph, pos, with_labes=True, font_weight='bold', **options) plt.show()