tNodeEmbed
tNodeEmbed copied to clipboard
KeyError: 'label' for Node Classification
Hi @urielsinger , thanks for the paper and the code. I am trying to run it for a node classification task for a custom graph and get KeyError: 'label'
Looks like while initializing the model, it drops "label" node attribute.
tNodeEmbed(graph_nx2, task="node_classification", dump_folder=".")
Any suggestion to fix this error ? Thanks
In order to use the node_classification
task, you should give the graph (graph_nx2
) a node-attribute called label
which holds the nodes labels.
For further explanation, please refer to: https://networkx.org/documentation/stable/reference/generated/networkx.classes.function.set_node_attributes.html
Thanks Uriel, I have tried that without luck. I will try to follow your example. Thanks for the reply.
g = pd.read_csv("myfile.csv", sep=",",header=None)
g.columns = ['source','etype','target','time']
g = g.sort_values(by=['time'])
graph_nx2 = df2graph(g, 'source', 'target', 'time', create_using=nx.Graph())
nodelable = {}
for n in list(graph_nx2.nodes()):
nodelable[n] = 1
nx.set_node_attributes(graph_nx2, nodelable, "label")
tnodeembed3 = tNodeEmbed(graph_nx2, task="node_classification", dump_folder=".")
X, y = tnodeembed3.get_dataset()
=======
C:/Users/puro755/localcode_ipython/tNodeEmbed/src\loader\task_loader.py in load_node_classification_task(graph_nx, train_skip, test_size)
133
134 for u, attr in list(graph_nx.nodes(data=True))[::train_skip]:
--> 135 X.append(u)
136 y.append(attr['label'])
137
KeyError: 'label'
You probably have a bug, I think it is best to debug.