Spring
此笔记本演示了使用 力导向算法 对图进行 2D 嵌入。
[1]:
from IPython.display import SVG
[2]:
import numpy as np
[3]:
from sknetwork.data import karate_club, painters
from sknetwork.embedding import Spring
from sknetwork.visualization import visualize_graph
图
[4]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
labels = graph.labels
[5]:
spring = Spring(2)
embedding = spring.fit_transform(adjacency)
[6]:
image = visualize_graph(adjacency, position=embedding, labels=labels)
SVG(image)
[6]:
有向图
[7]:
graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
[8]:
spring = Spring(2)
embedding = spring.fit_transform(adjacency)
embedding.shape
[8]:
(14, 2)
[9]:
image = visualize_graph(adjacency, position=embedding, names=names)
SVG(image)
[9]: