Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code to prepare dataset? #1

Open
jzkay12 opened this issue Aug 25, 2020 · 1 comment
Open

Code to prepare dataset? #1

jzkay12 opened this issue Aug 25, 2020 · 1 comment

Comments

@jzkay12
Copy link

jzkay12 commented Aug 25, 2020

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

@aGIToz
Copy link

aGIToz commented Nov 25, 2021

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants