citeseer数据集的读取和处理

惊了,论文里面citeseer数据集的节点数是3327,然而找了一圈,节点数都是3312。。。因为节点的缺失,程序还出现了不少错误。

  • CiteSeer for Document Classification
    • CiteSeer数据集包含3312种科学出版物,分为六类之一。引用网络由4732个链接组成。数据集中的每个出版物都用0/1值的词向量描述,该词向量指示字典中是否存在相应的词。该词典包含3703个独特的单词。数据集中的README文件提供了更多详细信息。
    • Download link:
    • 这些论文分为以下六类之一:
      • Agents
      • AI
      • DB
      • IR
      • ML
      • HCI
import numpy as np
import pandas as pd
cs_content = pd.read_csv('./data/citeseer/citeseer.content',sep='\t',header=None)
cs_content.shape
(3312, 3705)
cs_cite = pd.read_csv('./data/citeseer/citeseer.cites',sep='\t',header=None)
cs_cite.shape
(4732, 2)
ct_idx = list(cs_content.index)
paper_id = list(cs_content.iloc[:,0])
paper_id = [str(i) for i in paper_id] #论文id全部转换为string,paper_id不都是整数值,惊了!
mp = dict(zip(paper_id,ct_idx))
mp['zamir99grouper']
1005
label = cs_content.iloc[:,-1]
label = pd.get_dummies(label)
label.shape
(3312, 6)
feature = cs_content.iloc[:,1:-1]
feature.shape
(3312, 3703)
mlen = cs_content.shape[0]
adj = np.zeros((mlen,mlen))

for i,j in zip(cs_cite[0],cs_cite[1]):
    if str(i) in mp.keys() and str(j) in mp.keys(): #数据集有问题!!在cites中有未出现过的paper_id
        x = mp[str(i)]
        y = mp[str(j)]
        adj[x][y] = adj[y][x] = 1
adj
array([[1., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]])
feature = np.array(feature)
label = np.array(label)
adj = np.array(adj)
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐