Giter VIP home page Giter VIP logo

Comments (8)

misterblonde avatar misterblonde commented on August 16, 2024

when using .graph_from_networkx()


AttributeError Traceback (most recent call last)
in
----> 1 sp_kernel.fit_transform(new_G)

~/anaconda3/envs/py36/lib/python3.6/site-packages/grakel/graph_kernels.py in fit_transform(self, X, y)
386 K = self.kernel_.transform(X).dot(self.nystroem_normalization_.T)
387 else:
--> 388 K = self.kernel_.fit_transform(X)
389
390 return K

~/anaconda3/envs/py36/lib/python3.6/site-packages/grakel/kernels/shortest_path.py in fit_transform(self, X, y)
379 """
380 self._method_calling = 2
--> 381 self.fit(X)
382
383 # calculate feature matrices.

~/anaconda3/envs/py36/lib/python3.6/site-packages/grakel/kernels/kernel.py in fit(self, X, y)
121 raise ValueError('fit input cannot be None')
122 else:
--> 123 self.X = self.parse_input(X)
124
125 # Return the transformer

~/anaconda3/envs/py36/lib/python3.6/site-packages/grakel/kernels/shortest_path.py in parse_input(self, X)
428 elif self._method_calling == 3:
429 self._Y_enum = dict()
--> 430 for (idx, x) in enumerate(iter(X)):
431 is_iter = isinstance(x, collections.Iterable)
432 if is_iter:

~/anaconda3/envs/py36/lib/python3.6/site-packages/grakel/utils.py in graph_from_networkx(X, node_labels_tag, edge_labels_tag, edge_weight_tag, as_Graph)
325 nl = nodel_init()
326 el = edgel_init()
--> 327 nodes, edges = take_ne(G)
328 print(nodes)
329 print(edges)

~/anaconda3/envs/py36/lib/python3.6/site-packages/grakel/utils.py in take_ne(graph)
316 if v2:
317 def take_ne(graph):
--> 318 return graph.nodes, graph.edges
319 else:
320 def take_ne(graph):

AttributeError: 'int' object has no attribute 'nodes'

from grakel.

ysig avatar ysig commented on August 16, 2024

Hi.
Please provide me with the script lines, where you are calling this function, because something doesn't seem right.
Thanks

from grakel.

misterblonde avatar misterblonde commented on August 16, 2024

Do you have an example anywhere where you don't use a custom dataset such as MUTAG, but your own dataset, so loading in the graphs and using it for ML is a little clearer?

It works fine for the MUTAG default dataset, but not sure how to get my graphs into the minimum required format, ie. I managed to fix the problem I reported earlier by generating node labels for my graphs which initially didn't have any etc. and generating the H2O format by hand.

from grakel.

ysig avatar ysig commented on August 16, 2024

Hi,

the functions graph_from_csv and graph_from_networkx are functions that we added on our last package and will be updated (fixed) on the new one.

In order for us to debug any unexpected behaviour, we would like you to provide as with a small example of what you are trying to do. As I see from the functions definition, the functions should be able to handle csv files with labels (and attributes).

Do you have an example anywhere where you don't use a custom dataset such as MUTAG, but your
own dataset, so loading in the graphs and using it for ML is a little clearer?

No we don't have yet one, but we do exactly as you (for loading the default datasets):

generating the H2O format by hand.
that is we create an Iterable of graphs (a list) where each element is an Iterable (a list) of a Graph like object (adjacency matrix/ edge dictionary) and a optionally a dictionary of node labels/attributes and edge labels and attributes. Kernels that use weights such as random walk should expect them on the on the graph-like object as weights (values on the adjacency matrix or {'a':{'b':2.0, 'c':1.0}} for the dictionary).

Thanks for your time :)

from grakel.

misterblonde avatar misterblonde commented on August 16, 2024

Hi ysig,

I created this little sample repos to show you my workaround:
https://github.com/misterblonde/GraKelTest

Kernel Comparison if its 1 vs. 1 works fine, but returns an array with 1 entry. I just flattened the array for now and wrote it all into a new output DataFrame. However this is not ideal.

I don't know how to improve this. Also none of the selected kernels work without some Dummy atom labels.

I hope this helps understanding the struggle :)

from grakel.

ysig avatar ysig commented on August 16, 2024

Hi misterblond,

after reading your code, seems you don't get something right.
Firstly comparing pair-by-pair node labels with a kernel is not suggested even when using the raw values of a kernel (not even the normalized ones).

Please see my KernelSimilarity function from your file GraphKernels-bak.py:

def KernelSimilarity(new_graphs, node_labels):
    """

    Combines Node Labels and adds them onto graphs which are read in as .csv files
    Builds a similarity matrix which is then saved as a .csv file

    """

    graphs = []
    for ref_index, ref_file in enumerate(new_graphs):

        # Compute Reference Kernel all other Kernels will be compared across the row:
        # Generate graph that all others are compared to in this row:
        df = pd.read_csv(f"{current_path}/{inp_folder}/{ref_file}.csv", header=None)
        G = df.values.tolist()
        # join networkX graph data and fake labels created previously:
        graphs.append([G, node_labels])


    start = time.time()
    out = kernel.fit_transform(graphs)
    end = time.time()
    print("Time needed for Reference Kernel computation (s): ", end - start)

    # Write Matrix to file
    pd.DataFrame(out, index=new_graphs, columns=new_graphs).to_csv(f"{req_kernel}_{inp_folder}_SimilarityKernel.csv", header=True, index=True)

    #####################################################################

Concerning labels, for kernels:

  • "shortest_path"
  • "pyramid_match"
  • "random_walk"
    you are using set the with_labels argument to False, if you don't want to use node-labels.

Now "neighborhood_hash" functions only with node-labels.

All this can be found here:
https://ysig.github.io/GraKeL/dev/graph_kernel.html

I hope this relieves your struggle.

from grakel.

misterblonde avatar misterblonde commented on August 16, 2024

Thanks a lot ysig! That was the easy answer I was looking for. I knew my workaround wasn't great, hence my "report issue" haha. Cheers so much! I hope I can put it to good use now!

from grakel.

ysig avatar ysig commented on August 16, 2024

from grakel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.