ysig / GraKeL

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

Error when using EdgeHistogram #97

Closed kkkkk001 closed 8 months ago

kkkkk001 commented 9 months ago

Describe the bug I'm trying to use the EdgeHistogram kernel with the MUTAG dataset. When calling the transform method on the test set, the following error raises: "TypeError: each element of X must be either a graph object or a list with at least a graph like object and node labels dict ". Following the example in the repository about the WeisfeilerLehman kernel, I first call the fit_transform method on the training set, then call the transform method on the test set. The fit_transform method works well, but the transform method reports TypeError.

To Reproduce Steps to reproduce the behavior: from grakel.datasets import fetch_dataset from grakel.kernels import WeisfeilerLehman, EdgeHistogram

MUTAG = fetch_dataset("MUTAG", verbose=False) G, y = MUTAG.data, MUTAG.target

G_train, G_test, y_train, y_test = train_test_split(G, y, test_size=0.1, random_state=42) gk = WeisfeilerLehman(n_iter=4, base_graph_kernel=EdgeHistogram, normalize=True) K_train = gk.fit_transform(G_train) K_test = gk.transform(G_test)

Expected behavior A clear and concise description of what you expected to happen. I'm wondering why transform failed but fit_transform didn't. I'd like to ask how to use the EdgeHistogram kernel.

giannisnik commented 9 months ago

Hi @kkkkk001 ,

First of all, keep in mind that it doesn't make sense to combine the Weisfeiler-Lehman framework with the edge histogram kernel since the latter compares the edge labels of the two graphs with each other and those labels remain unchanged across the different iterations of the Weisfeiler-Lehman (only the node labels are updated). Still, the code you shared is supposed to produce a kernel matrix even if edge labels are compared multiple times to each other. Thanks for letting us know. We will fix this bug in the next version of the package.