MCPcopy Index your code
hub / github.com/shenweichen/GraphEmbedding / plot_embeddings

Function plot_embeddings

examples/struc2vec_flight.py:31–48  ·  view source on GitHub ↗
(embeddings, label_path, show=True)

Source from the content-addressed store, hash-verified

29
30
31def plot_embeddings(embeddings, label_path, show=True):
32 x_data, y_data = read_node_label(str(label_path), skip_head=True)
33
34 embedding_list = np.array([embeddings[node] for node in x_data])
35 node_pos = TSNE(n_components=2).fit_transform(embedding_list)
36
37 color_idx = {}
38 for index, label in enumerate(y_data):
39 color_idx.setdefault(label[0], [])
40 color_idx[label[0]].append(index)
41
42 for label, indexes in color_idx.items():
43 plt.scatter(node_pos[indexes, 0], node_pos[indexes, 1], label=label)
44 plt.legend()
45 if show:
46 plt.show()
47 else:
48 plt.close()
49
50
51def main(smoke=False, show=True):

Callers 1

mainFunction · 0.70

Calls 1

read_node_labelFunction · 0.90

Tested by

no test coverage detected