GCN数据集Cora、Citeseer、Pubmed文件分析


1 简介

  本文将对Cora、Citeseer、Pubmed 数据集进行详细介绍

数据集 节点 特征 标签(y)
Cora 1 2708 5429 1433 7
Citeseer 1 3327 4732 3703 6
Pubmed 1 19717 44338 500 3

  GCN 文件内容:

  ├── gcn

  │ ├── data //图数据
  │ │ ├── ind.citeseer.allx
  │ │ ├── ind.citeseer.ally
  │ │ ├── ind.citeseer.graph
  │ │ ├── ind.citeseer.test.index
  │ │ ├── ind.citeseer.tx
  │ │ ├── ind.citeseer.ty
  │ │ ├── ind.citeseer.x
  │ │ ├── ind.citeseer.y
  │ │ ├── ind.cora.allx
  │ │ ├── ind.cora.ally
  │ │ ├── ind.cora.graph
  │ │ ├── ind.cora.test.index
  │ │ ├── ind.cora.tx
  │ │ ├── ind.cora.ty
  │ │ ├── ind.cora.x
  │ │ ├── ind.cora.y
  │ │ ├── ind.pubmed.allx
  │ │ ├── ind.pubmed.ally
  │ │ ├── ind.pubmed.graph
  │ │ ├── ind.pubmed.test.index
  │ │ ├── ind.pubmed.tx
  │ │ ├── ind.pubmed.ty
  │ │ ├── ind.pubmed.x
  │ │ └── ind.pubmed.y
  │ ├── __init__.py
  │ ├── inits.py //初始化的公用函数
  │ ├── layers.py //GCN层定义
  │ ├── metrics.py //评测指标的计算
  │ ├── models.py //模型结构定义
  │ ├── train.py //训练
  │ └── utils.py //工具函数的定义
  ├── LICENCE
  ├── README.md
  ├── requirements.txt
  └── setup.py

  三种数据都由以下八个文件组成,存储格式类似,以cora为例:

ind.dataset_str.x => 训练实例的特征向量,是scipy.sparse.csr.csr_matrix类对象,shape:(140, 1433)
ind.dataset_str.tx => 测试实例的特征向量,shape:(1000, 1433)
ind.dataset_str.allx => 有标签的+无无标签训练实例的特征向量,是ind.dataset_str.x的超集,shape:(1708, 1433)
ind.dataset_str.y => 训练实例的标签,独热编码,numpy.ndarray类的实例,是numpy.ndarray对象,shape:(140, 7)
ind.dataset_str.ty => 测试实例的标签,独热编码,numpy.ndarray类的实例,shape:(1000, 7)
ind.dataset_str.ally => 对应于ind.dataset_str.allx的标签,独热编码,shape:(1708, 7)
ind.dataset_str.graph => 图数据,collections.defaultdict类的实例,格式为 {index:[index_of_neighbor_nodes]}
ind.dataset_str.test.index => 测试实例的id,2157行

  Cora为例

   Cora 数据集由机器学习论文组成,是近年来图深度学习很喜欢使用的数据集。在数据集中,论文分为以下七类之一:

  • 基于案例
  • 遗传算法
  • 神经网络
  • 概率方法
  • 强化学习
  • 规则学习
  • 理论

  论文的选择方式是,在最终语料库中,每篇论文引用或被至少一篇其他论文引用。整个语料库中有2708篇论文。

  在词干堵塞和去除词尾后,只剩下 1433 个独特的单词。文档频率小于 10 的所有单词都被删除。cora数据集包含 1433 个独特单词,所以特征是 1433 维。0 和 1 描述的是每个单词在 paper 中是否存在。

  文件组成(cora):

  三种数据都由以下八个文件(3类)组成,存储格式类似:

  x,tx,allx 是特征(转换成array后是独热编码)

    • x (维度 (140,1433)) 是140 篇论文训练实例的特征向量 ,ty (维度 (1000,1433))是 1000 篇论文测试实例的特征向量,allx  (维度 (1708,1433))是1708 篇论文中有标签的+无无标签训练实例的特征向量,从0-1707,共1708个。  
    • 节点数 = 1000 + 1708 = 2708 (tx 中的1000 和 allx 中的 1708)。  

  y,ty,ally是 上面对应标签(独热编码)

    • y  (维度 (140,7)) 是140 篇论文训练实例的标签,ty (维度 (1000,7))是 1000 篇论文测试实例的标签,allx  (维度 (1708,7))对应于ind.dataset_str.allx的标签,包含有标签的和无标签的,从0-1707,共1708个  

  graph,test.index

    • 总共2708个节点,训练数据仅用了140个,范围是(0, 140),验证集用了500个,范围是(140, 640],测试集用了1000个,范围是[1708,2707],其余范围从[641,1707]的数据集。  

  关于特征代码:

import pickle as pkl

with open("data/ind.cora.x", 'rb') as f:
    data = pkl.load(f, encoding='latin1')
print(type(data)) # 变量data是个scipy.sparse.csr.csr_matrix,类似稀疏矩阵,输出得到的是矩阵中非0的行列坐标及值
print(data.shape) #(140, 1433)-ind.cora.x是140行,1433列的
print(data.shape[0]) #row:140
print(data.shape[1]) #column:1433
nonzero=data.nonzero()
print(nonzero) #输出非零元素对应的行坐标和列坐标
print(type(nonzero)) #
print(nonzero[0]) #行:[ 0 0 0 ... 139 139 139]
print(nonzero[1]) #列:[ 19 81 146 ... 1263 1274 1393]
print(data.toarray())
print(data)

  变量 data 是个scipy.sparse.csr.csr_matrix,类似稀疏矩阵,输出得到的是矩阵中非 0 的行列坐标及值。也就是说如果该文献如果出现这个单词则其设置为 1 ,类似于one-hot 编码。

  关于标签代码:

with open("data/ind.cora.y", 'rb') as f:
    print(f)  #<_io.BufferedReader name='data/ind.cora.y'>
    data = pkl.load(f, encoding='latin1')
    print(type(data)) #
    print(data.shape)   #(140, 7)
    print(data.shape[0]) #row:140
    print(data.shape[1]) #column:7
    print(data[1]) #[0 0 0 0 1 0 0]

  关于边关系代码:

with open("data/ind.cora.graph", 'rb') as f:
        data = pkl.load(f, encoding='latin1')
        print(type(data)) #
        print(data) 
  defaultdict(, {0: [633, 1862, 2582], 1: [2, 652, 654], 2: [1986, 332, 1666, 1, 1454],
   , ... ,
  2706: [165, 2707, 1473, 169], 2707: [598, 165, 1473, 2706]})

相关