PCA
此笔记本说明了通过邻接矩阵的 主成分分析 对图进行嵌入。
[1]:
from IPython.display import SVG
[2]:
import numpy as np
[3]:
from sknetwork.data import karate_club, painters, movie_actor
from sknetwork.embedding import PCA
from sknetwork.visualization import visualize_graph, visualize_bigraph
图
[4]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
labels = graph.labels
[5]:
pca = PCA(2)
embedding = pca.fit_transform(adjacency)
[6]:
image = visualize_graph(adjacency, embedding, labels=labels)
SVG(image)
[6]:
有向图
[7]:
graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
[8]:
pca = PCA(2)
embedding = pca.fit_transform(adjacency)
[9]:
image = visualize_graph(adjacency, embedding, names=names)
SVG(image)
[9]:
二部图
[10]:
graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col
[11]:
pca = PCA(2)
pca.fit(biadjacency)
[11]:
PCA(n_components=2, normalized=False, solver=LanczosSVD(n_iter=None, tol=0.0))
[12]:
embedding_row = pca.embedding_row_
embedding_col = pca.embedding_col_
[13]:
image = visualize_bigraph(biadjacency, names_row, names_col,
position_row=embedding_row, position_col=embedding_col,
color_row='blue', color_col='red')
SVG(image)
[13]: