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

plot_structure does not plot anything #27

Closed
ogencoglu opened this issue Mar 28, 2020 · 2 comments
Closed

plot_structure does not plot anything #27

ogencoglu opened this issue Mar 28, 2020 · 2 comments

Comments

@ogencoglu
Copy link

Description

plot_structure does not plot anything since the update. I am just trying to replicate the tutorial in a jupyter notebook.

Steps to Reproduce

from causalnex.structure import StructureModel
sm = StructureModel()
sm.add_edges_from([
    ('health', 'absences'),
    ('health', 'G1')
])
_, _, _ = plot_structure(sm)

Environment

  • CausalNex version used : causalnex==0.5.0
  • Python version used (python -V): 3.7
  • Operating system and version: Ubuntu 16
@ogencoglu
Copy link
Author

And gives error for the other tutorial example (directly copied from tutorial):

data = pd.read_csv('../data/student-por.csv', delimiter=';')
drop_col = ['school','sex','age','Mjob', 'Fjob','reason','guardian']
data = data.drop(columns=drop_col)
struct_data = data.copy()

non_numeric_columns = list(struct_data.select_dtypes(exclude=[np.number]).columns)
print(non_numeric_columns)

le = LabelEncoder()
for col in non_numeric_columns:
    struct_data[col] = le.fit_transform(struct_data[col])
    
sm = from_pandas(struct_data)
_, _, _ = plot_structure(sm)
/usr/local/lib/python3.7/site-packages/pygraphviz/agraph.py:1367: RuntimeWarning: Warning: node 'address', graph '%3' size too small for label
Warning: node 'famsize', graph '%3' size too small for label
Warning: node 'Pstatus', graph '%3' size too small for label
Warning: node 'Medu', graph '%3' size too small for label
Warning: node 'Fedu', graph '%3' size too small for label
Warning: node 'traveltime', graph '%3' size too small for label
Warning: node 'studytime', graph '%3' size too small for label
Warning: node 'failures', graph '%3' size too small for label
Warning: node 'schoolsup', graph '%3' size too small for label
Warning: node 'famsup', graph '%3' size too small for label
Warning: node 'paid', graph '%3' size too small for label
Warning: node 'activities', graph '%3' size too small for label
Warning: node 'nursery', graph '%3' size too small for label
Warning: node 'higher', graph '%3' size too small for label
Warning: node 'internet', graph '%3' size too small for label
Warning: node 'romantic', graph '%3' size too small for label
Warning: node 'famrel', graph '%3' size too small for label
Warning: node 'freetime', graph '%3' size too small for label
Warning: node 'goout', graph '%3' size too small for label
Warning: node 'Dalc', graph '%3' size too small for label
Warning: node 'Walc', graph '%3' size too small for label
Warning: node 'health', graph '%3' size too small for label
Warning: node 'absences', graph '%3' size too small for label
Warning: node 'G1', graph '%3' size too small for label
Warning: node 'G2', graph '%3' size too small for label
Warning: node 'G3', graph '%3' size too small for label

  warnings.warn(b"".join(errors).decode(self.encoding), RuntimeWarning)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-d2da9edb9d84> in <module>
---->  _, _, _ = plot_structure(sm)

ValueError: too many values to unpack (expected 3)

@SteveLerQB
Copy link
Contributor

Hi @ogencoglu,

Just updated the tutorial and documentation. To output the plot, you have to do the following:

from IPython.display import Image
from causalnex.plots import plot_structure, NODE_STYLE, EDGE_STYLE

viz = plot_structure(
    sm,
    graph_attributes={"scale": "0.5"},
    all_node_attributes=NODE_STYLE.WEAK,
    all_edge_attributes=EDGE_STYLE.WEAK)
filename = "./structure_model.png"
viz.draw(filename)
Image(filename)

Hope this helps! 🙂

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