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

作者: CBlair

简介

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

  Cora、Citeseer、Pubmed

|----------|---------------------------------------------------------------|---|-------|-------|------|-------|
| 数据集      | 来源                                                            | 图 | 节点    | 边     | 特征   | 标签(y) |
| Cora     | "Collective classification in network data," AI magazine,2008 | 1 | 2708  | 5429  | 1433 | 7     |
| Citeseer | "Collective classification in network data," AI magazine,2008 | 1 | 3327  | 4732  | 3703 | 6     |
| Pubmed   | "Collective classification in network data," AI magazine,2008 | 1 | 19717 | 44338 | 500  | 3     |

  ├── 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

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

  ind.dataset_str.x => the feature vectors of the training instances as scipy.sparse.csr.csr_matrix object;
  ind.dataset_str.tx => the feature vectors of the test instances as scipy.sparse.csr.csr_matrix object;
  ind.dataset_str.allx => the feature vectors of both labeled and unlabeled training instances
  (a superset of ind.dataset_str.x) as scipy.sparse.csr.csr_matrix object;
  ind.dataset_str.y => the one-hot labels of the labeled training instances as numpy.ndarray object;
  ind.dataset_str.ty => the one-hot labels of the test instances as numpy.ndarray object;
  ind.dataset_str.ally => the labels for instances in ind.dataset_str.allx as numpy.ndarray object;

  ind.dataset_str.graph => a dict in the format {index: [index_of_neighbor_nodes]} as collections.defaultdict object;
  ind.dataset_str.test.index => the indices of test instances in graph, for the inductive setting as list object.

  以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]的数据集。

  关于特征代码:

data 
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)) <class 'tuple'>
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)) <class 'numpy.ndarray'>
    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)) <class 'collections.defaultdict'>
        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]})

  关于data/ind.cora.test.index代码:

test_idx_reorder = parse_index_file("data/ind.cora.test.index")
print("test index:",test_idx_reorder)
test index: [2692, 2532, 2050, 1715, 2362, 2609, 2622, 1975, 2081, 1767, 2263,..]
print("min_index:",min(test_idx_reorder))

  citeseer数据集中一些孤立点的特殊处理

    处理citeseer中一些孤立的点
    if dataset_str == 'citeseer':
         Fix citeseer dataset (there are some isolated nodes in the graph)
         Find isolated nodes, add them as zero-vecs into the right position

        test_idx_range_full = range(min(test_idx_reorder), max(test_idx_reorder)+1)
         print("test_idx_range_full.length",len(test_idx_range_full))
        test_idx_range_full.length 1015

        转化成LIL格式的稀疏矩阵,tx_extended.shape=(1015,1433)
        tx_extended = sp.lil_matrix((len(test_idx_range_full), x.shape[1]))
         print(tx_extended)
        [2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325
         ....
         3321 3322 3323 3324 3325 3326]

        test_idx_range-min(test_idx_range):列表中每个元素都减去min(test_idx_range),即将test_idx_range列表中的index值变为从0开始编号
        tx_extended[test_idx_range-min(test_idx_range), :] = tx
         print(tx_extended.shape) (1015, 3703)

         print(tx_extended)
         (0, 19) 1.0
         (0, 21) 1.0
         (0, 169) 1.0
         (0, 170) 1.0
         (0, 425) 1.0
          ...
         (1014, 3243) 1.0
         (1014, 3351) 1.0
         (1014, 3472) 1.0

        tx = tx_extended
         print(tx.shape)
         (1015, 3703)
        997,994,993,980,938...等15行全为0


        ty_extended = np.zeros((len(test_idx_range_full), y.shape[1]))
        ty_extended[test_idx_range-min(test_idx_range), :] = ty
        ty = ty_extended
         for i in range(ty.shape[0]):
             print(i," ",ty[i])
              980 [0. 0. 0. 0. 0. 0.]
              994 [0. 0. 0. 0. 0. 0.]
              993 [0. 0. 0. 0. 0. 0.]
  • allx是训练集中的所有训练实例,包含有标签的和无标签的,从0-1707,共1708个
  • ally是allx对应的标签,从1708-2707,共1000个
  • citeseer的测试数据集中有一些孤立的点(test.index中没有对应的索引,15个),可把这些点当作特征全为0的节点加入到测练集tx中,并且对应的标签在ty中
  • 输入是一张整图,因此将 tx 和 allx 拼起来作为 feature
  • 没有标签的数据的 y 值:[0,0,0,0,0,0,0]
  • 数据集中的特征也是稀疏的,用LIL稀疏矩阵存储,格式如下
A=np.array([[1,0,2,0],[0,0,0,0],[3,0,0,0],[1,0,0,4]])
AS=sp.lil_matrix(A)
print(AS)
 (0, 0) 1
 (0, 2) 2
 (2, 0) 3
 (3, 0) 1
 (3, 3) 4

  Tox21 数据集
  此数据集来源于一个PubChem网站的一个2014年的竞赛:https://tripod.nih.gov/tox21/challenge/about.jsp
  PubChem是美国国立卫生研究院(NIH)的开放化学数据库,是世界上最大的免费化学物信息集合。
  PubChem的数据由数百个数据源提供,包括:政府机构,化学品供应商,期刊出版商等。

  21世纪的毒理学(Tox21)计划是NIH,环境保护局和食品药品管理局的联邦合作计划,旨在开发更好的毒性评估方法。目标是快速有效地测试某些化合物是否有可能破坏人体中可能导致不良健康影响的过程。Tox21数据集是其中一个比赛用到的数据集,包含了12个毒理试验测定的化学合成物质的结构信息。

  • 雌激素受体α,LBD(ER,LBD)
  • 雌激素受体α,full(ER,full)
  • 芳香
  • 芳烃受体(AhR)
  • 雄激素受体,full(AR,full)
  • 雄激素受体,LBD(AR,LBD)
  • 过氧化物酶体增殖物激活受体γ(PPAR-γ)
  • 核因子(红细胞衍生的2)样2 /抗氧化反应元件(Nrf2 / ARE)
  • 热休克因子反应元件(HSE)
  • ATAD5
  • 线粒体膜电位(MMP)
  • P53

  每个毒理实验测试的都是PUBCHEM_SID从144203552-144214049共10486个化合物,包括环保化合物、一些上市药物等物质的活性结果。

  略

原文创作:CBlair

原文链接:https://www.cnblogs.com/BlairGrowing/p/15323995.html

更多推荐

更多
  • Azure数据工程指南-二十四、数据治理的权限 创建 azure 预览帐户,探索 azure 预览,探索词汇表,浏览资产,以编程方式使用预览,摘要,管理凭证和访问,创建扫描, 许多组织需要建立数据治理流程、标准和方法,并且已经能够使用内部 SQL Server 工具(如 Master
    Apache CN

  • Azure数据工程指南-二十二、Synapse 分析工作区 创建 Synapse 分析工作区,使用 Spark 探索样本数据,用 SQL 查询数据,用 SQL 创建外部表,摘要, 微软 Azure 数据平台的众多新增功能已经围绕许多类似的产品及其在现代 Azure 数据平台中的用途产生了兴奋和困
    Apache CN

  • Azure数据工程指南-二十三、数据块中的机器学习 创建 MLflow 实验,安装 MLflow 库,创建笔记本,选择性测井,自动记录,摘要, 寻求利用机器学习(ML)和人工智能能力的组织和开发人员花费大量时间构建 ML 模型,并寻求一种方法来简化他们的机器学习开发生命周期,以跟踪实验,
    Apache CN

  • Azure数据工程指南-二十一、将 Apache Spark 的 GraphFrame API 用于图形分析 安装 JAR 库,加载新数据表,将数据加载到数据块笔记本中,用顶点和边构建一个图,查询图表,寻找有图案的图案,用 PageRank 发现重要性,探索入度和出度度量,摘要,进行广度优先搜索,查找连接的组件, 图形技术使用户能够以图形的形式
    Apache CN

  • Azure数据工程指南-20 二十、部署 SQL 数据库先决条件,创建 Visual Studio SQL 数据库项目,安装 Visual Studio GitHub 扩展,导入 AdventureWorks 数据库,连接到 GitHub Repo 源代码控制,将
    Apache CN

  • Azure数据工程指南-十九、部署数据工厂更改 先决条件,创建 DevOps 持续集成构建管道,创建 DevOps 持续部署发布渠道,验证部署的数据工厂资源,摘要,Azure PowerShell 任务停止触发器,ARM 模板部署任务,Azure PowerShell 任务启动触发器
    Apache CN

  • Azure数据工程指南-十八、用于 Cosmos DB 的 Azure Synapse 链接 创建一个 Azure Cosmos DB 帐户,启用 Azure Synapse 链接,创建一个 Cosmos DB 容器和数据库,将数据导入 Azure Cosmos DB,在 Azure Synapse Analytics 中创建
    Apache CN

  • Azure数据工程指南-十六、流分析异常检测 先决条件,创建流分析输入和输出,创建实时电源 BI 仪表板,监控实时电源 BI 流,摘要,创建 Azure 流分析作业,创建物联网中心,创建 Power BI 服务,下载设备模拟器,添加流输入,添加流输出,编写流分析查询,启动流分析作业
    Apache CN

  • Azure数据工程指南-十七、使用 Apache Spark 的实时物联网分析 先决条件,创建物联网中心,创建数据块集群,安装 Maven 库,创建笔记本并运行结构化流查询,摘要,配置笔记本连接,开始结构化流,启动物联网设备模拟器,显示实时流数据,创建 Spark SQL 表,将流写入增量表, 实时物联网分析、高级
    Apache CN

  • Azure数据工程指南-十五、DeltaLake 为什么是酸性 DeltaLake,先决条件,创建并插入 DeltaLake,更新 DeltaLake,从 DeltaLake 删除,浏览增量日志,摘要,插入,更新,删除, 在使用 Azure Data Lake Storage Gen2
    Apache CN

  • 近期文章

    更多
    文章目录

      推荐作者

      更多