ysig / GraKeL

A scikit-learn compatible library for graph kernels
https://ysig.github.io/GraKeL/
Other
587 stars 96 forks source link

TypeError with Submatching kernel #61

Closed funan-jhc-lee closed 3 years ago

funan-jhc-lee commented 3 years ago

from grakel import Graph adj=[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]] node_label={0: '1', 1: '2', 2: '1', 3: '2'} edge_label={(0, 1): '1', (1, 2): '1', (2, 3): '1'} g1=Graph(initialization_object=adj, node_labels=node_label, edge_labels=edge_label) from grakel.kernels import SubgraphMatching sm_kernel=SubgraphMatching() sm_kernel.fit_transform([g1])

image

Hello! when I use the Submatching kernel, there is an error as showed in the picture above. Is there something wrong with the code I entered? Thanks a lot for your reply!

giannisnik commented 3 years ago

Hi @funan-jhc-lee ,

The problem is in how you initialize the node and edge labels. In fact, the Subgraph Matching kernel expects the input graphs to contain continuous (e.g., vectors) node and edge attributes.

Therefore, in your example, you only need to initialize the node and edge labels to some values in a similar manner as here: node_label={0:[0.0], 1:[1.0], 2:[2.0], 3:[3.0]} edge_label={(0, 1): [1.0], (1, 0): [1.0], (1, 2): [1.0], (2, 1): [1.0], (2, 3): [1.0], (3, 2): [1.0]}

You can see here https://ysig.github.io/GraKeL/0.1a8/graph_kernel.html if and what type of labels/attributes are required to compute a given kernel.

funan-jhc-lee commented 3 years ago

Hi @funan-jhc-lee ,

The problem is in how you initialize the node and edge labels. In fact, the Subgraph Matching kernel expects the input graphs to contain continuous (e.g., vectors) node and edge attributes.

Therefore, in your example, you only need to initialize the node and edge labels to some values in a similar manner as here: node_label={0:[0.0], 1:[1.0], 2:[2.0], 3:[3.0]} edge_label={(0, 1): [1.0], (1, 0): [1.0], (1, 2): [1.0], (2, 1): [1.0], (2, 3): [1.0], (3, 2): [1.0]}

You can see here https://ysig.github.io/GraKeL/0.1a8/graph_kernel.html if and what type of labels/attributes are required to compute a given kernel. Thanks a lot! It' works. Thanks agian!