question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError: 'Head nodes supplied to generator contain IDs not found in graph'

See original GitHub issue

I was trying to implement Stellargraph - Directed GraphSAGE, but then following error occurred: KeyError: ‘Head nodes supplied to generator contain IDs not found in graph’. I don’t know how to fix this.

I made the network by using the following code:

G = nx.Graph()
G.add_nodes_from(list(sample.client.values))
G.add_nodes_from(list(sample.merchant.values))                   
G.add_nodes_from(list(sample.transaction.values))
edgelist1 = list((zip(sample.transaction.values, sample.client.values)))
edgelist2 = list((zip(sample.transaction.values, sample.merchant.values)))
G.add_edges_from(edgelist1)
G.add_edges_from(edgelist2)

Then I split the data in train_data and test_data. I then transform all features to numeric features. I used one-hot encoding to transform the categoric variable ‘country’. Furthermore, I dropped some columns in the train and test data. Moreover, I defined a variable node_features that represents the features used as node attributes (minus the target variable).

Then I transformed the graph into a Stellargraph :

stelgr = sg.StellarDiGraph(G, node_features= node_features)
batch_size = 50; in_samples = [5, 2]; out_samples = [5, 2]
generator = DirectedGraphSAGENodeGenerator(stelgr, batch_size, in_samples, out_samples)
train_gen = generator.flow(train_data, train_targets, shuffle=False)

Then this error occurs:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-49-825ab36d20da> in <module>
----> 1 train_gen = generator.flow(train_data, train_targets, shuffle=False)

~\Anaconda3\lib\site-packages\stellargraph\mapper\node_mappers.py in flow(self, node_ids, targets, shuffle)
   1107 
   1108         """
-> 1109         return NodeSequence(self, node_ids, targets, shuffle=shuffle)
   1110 
   1111     def flow_from_dataframe(self, node_targets, shuffle=False):

~\Anaconda3\lib\site-packages\stellargraph\mapper\node_mappers.py in __init__(self, generator, ids, targets, shuffle)
    105         if any(n not in generator.graph for n in ids):
    106             raise KeyError(
--> 107                 "Head nodes supplied to generator contain IDs not found in graph"
    108             )
    109 

KeyError: 'Head nodes supplied to generator contain IDs not found in graph'

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
huonwcommented, Jan 20, 2020

0.8.4 has now been released.

0reactions
huonwcommented, Jan 22, 2020

Hi @ocesp98, have we addressed your problem here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyError on Generator - python - Stack Overflow
I attempted to add edges to the graph and sometime after that the generator portion stopped working, The node object doesn't appear any ......
Read more >
Source code for stellargraph.mapper.sampled_node_generators
The supplied graph should be a StellarGraph object that is ready for machine ... The node IDs are the nodes to train or...
Read more >
NetworkX Reference
The structure of NetworkX can be seen by the organization of its source code. The package provides classes for graph ob- jects, generators...
Read more >
What is KeyError in Python? Dictionary and Handling Them
Here I am trying to access a key called “D” which is not present in the dictionary. Hence, the error is thrown as...
Read more >
schrodinger.application.matsci.amorphous module — Schrödinger ...
Find monomers marked with the polymer builder method of marking head and tail - the Rx atom ... KeyError – If one of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found