ContinuousGNN icon indicating copy to clipboard operation
ContinuousGNN copied to clipboard

Code to prepare dataset?

Open jzkay12 opened this issue 5 years ago • 1 comments

Hi, thanks for the open source implementation. Could you provide the code to generate the dataset into txt files as listed? I'm trying your code on other datasets such as citeseer and pubmed, while the repo only provides cora. Also I want to try 15-fold cross validation as in the paper, could you explain how to prepare the data? Thanks

jzkay12 avatar Aug 25 '20 01:08 jzkay12

The code to generate the txt files :

import torch
import torch_geometric

graph = torch_geometric.datasets.Planetoid(root='../', name='cora')[0]

f = open("net.txt","w")
for i in range(graph.edge_index.shape[1]):
    f.write(str(graph.edge_index[0,i].item())+"\t"+str(graph.edge_index[1,i].item())+"\t"+"1"+"\n")

f = open("label.txt","w")
for i in range(graph.x.shape[0]):
    f.write(str(i)+"\t"+str(graph.y[i].item())+"\n")

f = open("train.txt", "w")
for i in range(graph.x.shape[0]):
    if graph.train_mask[i].item():
        f.write(str(i)+"\n")

f = open("dev.txt", "w")
for i in range(graph.x.shape[0]):
    if graph.val_mask[i].item():
        f.write(str(i)+"\n")

f = open("test.txt", "w")
for i in range(graph.x.shape[0]):
    if graph.test_mask[i].item():
        f.write(str(i)+"\n")

f = open("feature.txt", "w")
for i in range(graph.x.shape[0]):
    f.write(str(i))
    count = 0
    for j in range(graph.x.shape[1]):
        if graph.x[i,j].item():
            if not count:
                f.write("\t"+str(j)+":"+str(graph.x[i,j].item()))
                count += 1
            else:
                f.write(" "+str(j)+":"+str(graph.x[i,j].item()))
    else:
        f.write("\n")

aGIToz avatar Nov 25 '21 20:11 aGIToz