<jupyter_start><jupyter_text>Different ways to load an input graphWe recommend using the GML graph format to load a graph. You can also use the DOT format, which requires additional dependencies (either pydot or pygraphviz). DoWhy supports both loading a graph as a string, or as a file (with the extensions 'gml' or 'dot').Below is an example showing the different ways of loading the same graph.<jupyter_code>import os, sys
import random
sys.path.append(os.path.abspath("../../"))
import numpy as np
import pandas as pd

import dowhy
from dowhy.do_why import CausalModel
from IPython.display import Image, display<jupyter_output><empty_output><jupyter_text>I. Generating dummy dataWe generate some dummy data for three variables: X, Y and Z.<jupyter_code>z=[i for i in range(10)]
random.shuffle(z)
df = pd.DataFrame(data = {'Z': z, 'X': range(0,10), 'Y': range(0,100,10)})
df<jupyter_output><empty_output><jupyter_text>II. Loading GML or DOT graphs GML format<jupyter_code># With GML string
model=CausalModel(
        data = df,
        treatment='X',
        outcome='Y',
        graph="""graph[directed 1 node[id "Z" label "Z"]  
                    node[id "X" label "X"]
                    node[id "Y" label "Y"]      
                    edge[source "Z" target "X"]    
                    edge[source "Z" target "Y"]     
                    edge[source "X" target "Y"]]"""
                    
        )
model.view_model()


display(Image(filename="causal_model.png"))
# With GML file
model=CausalModel(
        data = df,
        treatment='X',
        outcome='Y',
        graph="example_graphs/simple_graph_example.gml"
        )
model.view_model()


display(Image(filename="causal_model.png"))<jupyter_output>Model to find the causal effect of treatment X on outcome Y<jupyter_text>DOT format<jupyter_code># With DOT string
model=CausalModel(
        data = df,
        treatment='X',
        outcome='Y',
        graph="digraph {Z -> X;Z -> Y;X -> Y;}"
        )
model.view_model()

from IPython.display import Image, display
display(Image(filename="causal_model.png"))
# With DOT file
model=CausalModel(
        data = df,
        treatment='X',
        outcome='Y',
        graph="example_graphs/simple_graph_example.dot"
        )
model.view_model()


display(Image(filename="causal_model.png"))<jupyter_output>Model to find the causal effect of treatment X on outcome Y
StarcoderdataJupyterStructuredCleanDedup