tNodeEmbed icon indicating copy to clipboard operation
tNodeEmbed copied to clipboard

KeyError: 'label' for Node Classification

Open purohitsumit opened this issue 3 years ago • 3 comments

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

purohitsumit avatar Mar 28 '21 14:03 purohitsumit

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

urielsinger avatar Mar 28 '21 22:03 urielsinger

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'

purohitsumit avatar Mar 28 '21 22:03 purohitsumit

You probably have a bug, I think it is best to debug.

urielsinger avatar Mar 28 '21 23:03 urielsinger