GraKeL icon indicating copy to clipboard operation
GraKeL copied to clipboard

I don't know how to use my own data for input

Open JXn-XMU opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. This is my first time using grakel and I created my data by mimicking the publicly available dataset. My data have graph_A 、indicator、node_labels、graph_label but I don't know what code to use for input to read my data.

Describe the solution you'd like I hope someone can teach me how I should enter my own data, code or screenshots, and I would sincerely appreciate it.

JXn-XMU avatar Sep 21 '22 11:09 JXn-XMU

Please have a look here:

https://ysig.github.io/GraKeL/0.1a8/documentation/introduction.html

or here:

https://ysig.github.io/GraKeL/0.1a8/auto_examples/erdos_renyi.html#sphx-glr-auto-examples-erdos-renyi-py

On Wed, Sep 21, 2022 at 2:58 PM JXn-XMU @.***> wrote:

Is your feature request related to a problem? Please describe. This is my first time using grakel and I created my data by mimicking the publicly available dataset. My data have graph_A 、indicator、node_labels、graph_label but I don't know what code to use for input to read my data.

Describe the solution you'd like I hope someone can teach me how I should enter my own data, code or screenshots, and I would sincerely appreciate it.

— Reply to this email directly, view it on GitHub https://github.com/ysig/GraKeL/issues/84, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGY7H2NTJK6GNIAV5SID2Z3V7LZ7DANCNFSM6AAAAAAQR73O34 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ysig avatar Sep 22 '22 14:09 ysig

Please have a look here: https://ysig.github.io/GraKeL/0.1a8/documentation/introduction.html or here: https://ysig.github.io/GraKeL/0.1a8/auto_examples/erdos_renyi.html#sphx-glr-auto-examples-erdos-renyi-py On Wed, Sep 21, 2022 at 2:58 PM JXn-XMU @.> wrote: Is your feature request related to a problem? Please describe. This is my first time using grakel and I created my data by mimicking the publicly available dataset. My data have graph_A 、indicator、node_labels、graph_label but I don't know what code to use for input to read my data. Describe the solution you'd like I hope someone can teach me how I should enter my own data, code or screenshots, and I would sincerely appreciate it. — Reply to this email directly, view it on GitHub <#84>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGY7H2NTJK6GNIAV5SID2Z3V7LZ7DANCNFSM6AAAAAAQR73O34 . You are receiving this because you are subscribed to this thread.Message ID: @.>

Yes, I have read https://ysig.github.io/GraKeL/0.1a8/auto_examples/erdos_renyi.html#sphx-glr-auto-examples-erdos-renyi-py . I know graph_label is y. But I'm not sure which file in the database does this Gs refer to, perhaps graph_A ? And how do I add node labels and attributes and edge labels and attributes if I want to add them. I have 495 shapes, by the way

JXn-XMU avatar Sep 23 '22 01:09 JXn-XMU

Hi, I have a similar issue. I have my own set of graphs represented in the form of TUDatasets. I want to do graph classification on this data. But the APIs do not allow me to use them like the MUTAG and ENZYMES datasets.

How can I do the analyses?

saiprasanna06 avatar Nov 20 '22 13:11 saiprasanna06

Hi @saiprasanna06 ,

You can use the following code.

import numpy as np
from scipy.sparse import csr_matrix,lil_matrix
from grakel import Graph

has_node_labels = True

graph_indicator = np.loadtxt("own_dataset_graph_indicator.txt", dtype=np.int64)
_,graph_size = np.unique(graph_indicator, return_counts=True)

edges = np.loadtxt("own_dataset_A.txt", dtype=np.int64, delimiter=",")
edges -= 1
A = csr_matrix((np.ones(edges.shape[0]), (edges[:,0], edges[:,1])), shape=(graph_indicator.size, graph_indicator.size))

if has_node_labels:
    x = np.loadtxt("own_dataset_node_labels.txt", dtype=np.int64).reshape(-1,1)

Gs = []  
idx = 0
for i in range(graph_size.size):
    adj = A[idx:idx+graph_size[i],idx:idx+graph_size[i]]
    node_labels = dict()
    for j in range(graph_size[i]):
        node_labels[j] = x[idx+j,0]
        
    G = Graph(adj, node_labels=node_labels)
    Gs.append(G)
    idx += graph_size[i]

y = np.loadtxt("own_dataset_graph_labels.txt", dtype=np.int64)

giannisnik avatar Nov 21 '22 10:11 giannisnik

Thanks ! But I am getting this error: "ValueError: row index exceeds matrix dimensions"

saiprasanna06 avatar Nov 30 '22 18:11 saiprasanna06