Pairplot: 可视化高维数据

本示例展示了如何使用pairplot可视化高维数据。

[1]:
import graspologic

import numpy as np
%matplotlib inline
/home/runner/.cache/pypoetry/virtualenvs/graspologic-pkHfzCJ8-py3.10/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

使用随机块模型模拟二元图

3块模型定义如下:

\begin{align*} n &= [50, 50, 50]\\ P &= \begin{bmatrix}0.5 & 0.1 & 0.05 \\ 0.1 & 0.4 & 0.15 \\ 0.05 & 0.15 & 0.3 \end{bmatrix} \end{align*}

因此,前50个顶点属于块1,接下来的50个顶点属于块2,最后50个顶点属于块3。

[2]:
from graspologic.simulations import sbm

n_communities = [50, 50, 50]
p = [[0.5, 0.1, 0.05],
     [0.1, 0.4, 0.15],
     [0.05, 0.15, 0.3],]

np.random.seed(2)
A = sbm(n_communities, p)

使用邻接谱嵌入来获得图的低维表示

嵌入维度是自动选择的。它应该嵌入到3个维度。

[3]:
from graspologic.embed import AdjacencySpectralEmbed

ase = AdjacencySpectralEmbed()
X = ase.fit_transform(A)

print(X.shape)
(150, 3)

使用pairplot绘制嵌入数据

首先我们生成与块对应的标签。我们将标签与数据一起传递给配对图。

[4]:
from graspologic.plot import pairplot

labels = ['Block 1'] * 50 + ['Block 2'] * 50 + ['Block 3'] * 50

plot = pairplot(X, labels)
../../_images/tutorials_plotting_pairplot_7_0.png
[ ]: