mckinsey / causalnex

A Python library that helps data scientists to infer causation rather than observing correlation.
http://causalnex.readthedocs.io/
Other
2.24k stars 258 forks source link

Exporting graph structure #129

Closed qvhaelen closed 3 years ago

qvhaelen commented 3 years ago

Hello,

I would like to know if once the graph has been generated using DAGClassifier , is there a built-in mehod to export the structure of the graph, (edges, weight, nodes) in a column format so it can be visaulized using another custom tools?

Thank you

oentaryorj commented 3 years ago

Hi @qvhaelen,

We currently don't have a built-in export method. However, since StructureModel extends networkx.DiGraph (see here), you can use networkx's export method. For example, you can export to a .dot file using write_dot function:

import networkx as nx

from causalnex.structure import StructureModel

# Create a model
sm = StructureModel()
sm.add_edges_from([
    ('A', 'C'),
    ('B', 'C'),
])
# Save the model into pygraphviz's dot format
nx.drawing.nx_pydot.write_dot(sm, 'graph.dot')

To export to other formats, you can find out more from networkx's documentation. Hope this helps :)

qvhaelen commented 3 years ago

Dear @oentaryorj thank you for the information. Yes I am already using the networkx functionalities so I guess it should be ok to export graph using networkx exprot function without relying on pygraphiz