Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming or Setting labels on Nodes #141

Open
priamai opened this issue Oct 9, 2023 · 4 comments
Open

Renaming or Setting labels on Nodes #141

priamai opened this issue Oct 9, 2023 · 4 comments

Comments

@priamai
Copy link

priamai commented Oct 9, 2023

Hi there,
I want to able to assign labels to the GeneralGraph similar to what you do with the GraphUtils instead of using the default X1...Xn notation.

This is what I tried:


cg.G.get_node_names()

['X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9']

for i, node in enumerate(cg.G.get_nodes()):
    node_name = labels[i] if labels is not None else node.get_name()
    node.set_name(node_name)

cg.G.get_node_names()
['IMPRESSIONS',
 'CLICKS',
 'CONVERSIONS',
 'AD_SPEND_USD',
 'REVENUE_USD',
 'NUM_ORDERS',
 'AOV_USD',
 'VISITORS',
 'SESSIONS']

Which looks good but I think it destroys the internal lookup table, when I want to see the edges it just complains of a keyerror:

image

Maybe I have to relabel the node_map? Any help will be appreciated.

I know you are working on supporting Pandas DataFrames directly but a short workaround will get me through this problem for the time being.

@kunwuz
Copy link
Collaborator

kunwuz commented Oct 9, 2023

Hi, the recommended way to assign labels to the nodes is 'cg.draw_pydot_graph(labels=[“A”, “B”, “C”])' or 'GraphUtils.to_pydot(cg.G, labels=[“A”, “B”, “C”])', as mentioned in the documentation. Here are some usage examples.

This visualizes the graph with assigned labels. But I'm not sure if you are looking for something else.

@priamai
Copy link
Author

priamai commented Oct 9, 2023

That is only for saving in pydot, I need to rewrite the actual node names for my downstream tasks and avoid confusion when referring to the original dataframe e.g. variable names.

@priamai
Copy link
Author

priamai commented Oct 9, 2023

@kunwuz for example when I add the Background Knowledge I want to do it by referring to the real node names defined in my ground truth NetworkX graph, instead now I have to go back and forward converting between the X{0} notation and the real variable names. Hope it makes better sense.

@kunwuz
Copy link
Collaborator

kunwuz commented Oct 12, 2023

I see, that requires some refactorization of the graph classes in causal-learn. For now, it seems that creating a mapping/look-up table is the easiest way. We have put it on the list. Please also feel free to let me know if you have any suggestions or would like to improve it together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants