python - 如何根据入度值对 Cora 数据集的节点进行聚类?

标签 python pytorch

我想以每个集群只包含具有相同入度值的节点的方式对 Cora 数据集的节点进行集群。我可以编写如下代码:

import torch
from torch_geometric.datasets import Planetoid
from torch_geometric.utils import degree

dataset = Planetoid('./data','CORA')
data = dataset[0]
n = data.num_nodes
indegree = degree(data.edge_index[1], n, dtype=torch.long)
counts = torch.bincount(indegree)

但是由于我没有访问节点的索引值,所以不知道如何将每个节点放在哪个集群中?

最佳答案

您可以使用 return_inversetorch.unique恢复指数。
具有相同值的节点 iindices属于同一个簇,因为它们的度数都等于 indegree_class[i] .

indegree_class, indices = torch.unique(indegree, return_inverse=True)

关于python - 如何根据入度值对 Cora 数据集的节点进行聚类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68275680/

上一篇:AngularJS ng-include

下一篇:html - 对面

相关文章:

machine-learning - 如何在 pytorch 中为权重添加 L1 或 L2 正则化

pytorch - Pytorch 照明的 model.to(device)

gpu - 如何将经过 gpu 训练的模型加载到 cpu 中?

python - "Numpy not Available"安装Pytorch XLA后

python - 从 python 调用 c++ 函数

python - 使用计数器 python 来自 2 个因式分解列表的 gcd

python - 如何每天抓取一次数据并将其写入 csv

python - 编写自定义函数乘以 x,y 的平均值

python - 在 Django 中,什么时候应该使用 doctests 而不是单元测试?

pytorch - pytorch 中 conv 的默认权重初始值设定项是什么?