from karateclub.dataset import GraphReader import networkx as nx import matplotlib.pyplot as plt reader = GraphReader("twitch") engb = nx.read_gml( 'L:\Github Repos\playground\TwitchSocialNetworks\TwitchDataENGB.gml') graph = nx.path_graph(engb) nx.draw(graph) plt.draw() # pyplot draw() # y = reader.get_target() # from karateclub import Diff2Vec # model = Diff2Vec(diffusion_number=2, diffusion_cover=20, dimensions=16) # model.fit(graph) # X = model.get_embedding() # from sklearn.model_selection import train_test_split # X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # from sklearn.metrics import roc_auc_score # from sklearn.linear_model import LogisticRegression # downstream_model = LogisticRegression(random_state=0).fit(X_train, y_train) # y_hat = downstream_model.predict_proba(X_test)[:, 1] # auc = roc_auc_score(y_test, y_hat) # print('AUC: {:.4f}'.format(auc))
"""GraphReader example.""" from karateclub.dataset import GraphReader reader = GraphReader("facebook") graph = reader.get_graph() target = reader.get_target()
import networkx as nx import community import numpy as np from karateclub.community_detection.overlapping import EgoNetSplitter, NNSED, DANMF, MNMF, BigClam from karateclub.node_embedding.neighbourhood import GraRep, DeepWalk, Walklets, NMFADMM, Diff2Vec, BoostNE from karateclub.community_detection.non_overlapping import EdMot, LabelPropagation from karateclub.node_embedding.structural import GraphWave from karateclub.node_embedding.attributed import BANE, TENE from karateclub.graph_embedding import Graph2Vec from karateclub.dataset import GraphReader dataset = "twitch" reader = GraphReader(dataset) graph = reader.get_graph() target = reader.get_target() features = reader.get_features() quit() #----------------------------------- # Graph2Vec example #----------------------------------- graphs = [nx.newman_watts_strogatz_graph(50, 5, 0.3) for _ in range(1000)] model = Graph2Vec() model.fit(graphs) model.get_embedding()
model.get_embedding() #------------------------- # GraphSet reader example #------------------------- reader = GraphSetReader("reddit10k") graphs = reader.get_graphs() y = reader.get_target() #---------------------- # Graph reader example #---------------------- reader = GraphReader("facebook") graph = reader.get_graph() target = reader.get_target() #------------------------------- # Graph2Vec attributed example #------------------------------- graphs = [] for i in range(50): graph = nx.newman_watts_strogatz_graph(50, 5, 0.3) nx.set_node_attributes(graph, {j: str(j) for j in range(50)}, "feature") graphs.append(graph) model = Graph2Vec(attributed=True)
if __name__ == "__main__": import json import matplotlib.pyplot as plt # nodes: 189028 edges: 1046039 # network = json.load(open("./test/Epinions.json")) # 37805 40701 # network = json.load(open("./test/Epinions_20_percent.json")) # 18902 10418 # network = json.load(open("./test/Epinions_10_percent.json")) # 2125 2831 # network = json.load(open("./test/epinions_5_percent.json")) # 1889 109 # network = json.load(open("./test/epinions_1_percent.json")) # network = json.load(open("./test/PolBooks.json")) # g = network_centrality(network) # network_centrality(network) from karateclub.dataset import GraphReader # print(GraphReader().get_features()) g = GraphReader().get_graph() # print(GraphReader().get_target()) # g = nx.newman_watts_strogatz_graph(1000, 20, 0.05) print(nx.info(g)) print(g.nodes()) # splitter = EgoNetSplitter(1.0) # splitter.fit(g) # print(splitter.get_memberships()) # plt.show()