'Graph2Vec fit method by karateclub
I am struggling with running the graph2vec module by karateclub (or any other provider of a similar one) on my networkx Graph G. Graph2Vec was introduced in this paper and promises to build quite successful embeddings.
So far, my Code looks like that:
from karateclub import Graph2Vec
graph2vec_model = Graph2Vec(
dimensions=2
)
graph2vec.fit(**G)
I already tried to apply the fit function to multiple versions of my Graph, with one or two asterisks inside the parentheses.
- Error message with one *: TypeError: fit() takes 2 positional arguments but 8513 were given (as my Graph has 8513 nodes)
- Error message with two **: TypeError: karateclub.graph_embedding.graph2vec.Graph2Vec.fit() argument after ** must be a mapping, not MultiDiGraph
- Error message after trying .fit(*[G]) or .fit(G):
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [75], in <cell line: 1>()
----> 1 graph2vec.fit(*[G])
File /opt/homebrew/lib/python3.9/site-packages/karateclub/graph_embedding/graph2vec.py:66, in Graph2Vec.fit(self, graphs)
59 """
60 Fitting a Graph2Vec model.
61
62 Arg types:
63 * **graphs** *(List of NetworkX graphs)* - The graphs to be embedded.
64 """
65 self._set_seed()
---> 66 graphs = self._check_graphs(graphs)
67 documents = [
68 WeisfeilerLehmanHashing(
69 graph, self.wl_iterations, self.attributed, self.erase_base_features
70 )
71 for graph in graphs
72 ]
73 documents = [
74 TaggedDocument(words=doc.get_graph_features(), tags=[str(i)])
75 for i, doc in enumerate(documents)
76 ]
File /opt/homebrew/lib/python3.9/site-packages/karateclub/estimator.py:64, in Estimator._check_graphs(self, graphs)
62 def _check_graphs(self, graphs: List[nx.classes.graph.Graph]):
63 """Check the Karate Club assumptions for a list of graphs."""
---> 64 graphs = [self._check_graph(graph) for graph in graphs]
66 return graphs
File /opt/homebrew/lib/python3.9/site-packages/karateclub/estimator.py:64, in <listcomp>(.0)
62 def _check_graphs(self, graphs: List[nx.classes.graph.Graph]):
63 """Check the Karate Club assumptions for a list of graphs."""
---> 64 graphs = [self._check_graph(graph) for graph in graphs]
66 return graphs
File /opt/homebrew/lib/python3.9/site-packages/karateclub/estimator.py:57, in Estimator._check_graph(self, graph)
55 def _check_graph(self, graph: nx.classes.graph.Graph) -> nx.classes.graph.Graph:
56 """Check the Karate Club assumptions about the graph."""
---> 57 self._check_indexing(graph)
58 graph = self._ensure_integrity(graph)
60 return graph
File /opt/homebrew/lib/python3.9/site-packages/karateclub/estimator.py:50, in Estimator._check_indexing(graph)
47 @staticmethod
48 def _check_indexing(graph: nx.classes.graph.Graph):
49 """Checking the consecutive numeric indexing."""
---> 50 numeric_indices = [index for index in range(graph.number_of_nodes())]
51 node_indices = sorted([node for node in graph.nodes()])
53 assert numeric_indices == node_indices, "The node indexing is wrong."
AttributeError: 'int' object has no attribute 'number_of_nodes'
Why, and especially where does my Graph get converted to a int object? Using number_of_nodes()
on my normal graph G works just fine.
Sorry for this messy documentation, could anyone help me out here? How do I need to use the fit method or how do I need to transform my graph to fit in?
Thanks a lot
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|