Advertisement
dredder_gun

network_visualzation_dz9_2

Nov 24th, 2022
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. def xy_embeddings(_graph):
  2.     graph = _graph.copy()
  3.     ### BEGIN SOLUTION
  4.     pbar = tqdm(total=4)
  5.  
  6.     model = LaplacianEigenmaps(dimensions=16)
  7.     model.fit(graph)
  8.     laplacian_emb = model.get_embedding()
  9.     model = PCA(n_components=2)
  10.     model.fit(laplacian_emb)
  11.     laplacian_emb = model.transform(laplacian_emb)
  12.     pbar.update(1)
  13.  
  14.     A = nx.to_numpy_array(graph)
  15.     model = TruncatedSVD(n_components=16)
  16.     model.fit(A)
  17.     svd_emb = model.transform(A)
  18.     model = PCA(n_components=2)
  19.     model.fit(svd_emb)
  20.     svd_emb = model.transform(svd_emb)
  21.     pbar.update(1)
  22.  
  23.     model = DeepWalk(
  24.         walk_number=10, walk_length=30, dimensions=16, window_size=10)
  25.     model.fit(graph)
  26.     deep_walk_emb = model.get_embedding()
  27.     model = PCA(n_components=2)
  28.     model.fit(deep_walk_emb)
  29.     deep_walk_emb = model.transform(deep_walk_emb)
  30.     pbar.update(1)
  31.  
  32.     model = MeanWalklets(
  33.         walk_number=10, walk_length=30, dimensions=16, window_size=10)
  34.     model.fit(graph)
  35.     walklets_emb = model.get_embedding()
  36.     model = PCA(n_components=2)
  37.     model.fit(walklets_emb)
  38.     walklets_emb = model.transform(walklets_emb)
  39.     pbar.update(1)
  40.  
  41.     pbar.close()
  42.  
  43.     return laplacian_emb, svd_emb, deep_walk_emb, walklets_emb
  44.     ### END SOLUTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement