簡介

  本文將對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(<class 'list'>, {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個化合物,包括環保化合物、一些上市藥物等物質的活性結果。

  略