mckinsey / causalnex

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

Find out the number of cycles #206

Closed geet-8 closed 1 year ago

geet-8 commented 1 year ago

Description

After plotting the graph, it would be great if we can have the number of cycles that the plot has after plotting

Context

It would be important to know the various cycles in the causal graph and also it would be appropriate to know what node is being caused by what other node sm = from_pandas(struct_data) cycles = sm.find_cycles() for cycle in cycles: print(cycle)

GabrielAzevedoFerreiraQB commented 1 year ago

Thanks a lot for the feature request, @geet-8

The CausalNex graph is what we call a DAG - Direct Acyclic Graph, which means it should have no cycles by definition.

If the the from_pandas function doesn't converge before the max iterations is hit OR the user doesnt set a w_threshold, then cycles may appear - and we do throw warnings in that case.

I hope it clarifies, but let me know if you have any questions and please keep feature requests coming :)

Thank you!