<jupyter_start><jupyter_text>Causal Graphical Models in Python In this example, we create a causal graphical model with Python. The causal network depicts the Sprinkler example covered by the lectures.    In this example, we use the causalgraphicalmodels Python library. You can find this library here: https://github.com/ijmbarr/causalgraphicalmodels  Step 1. Create the DAG of the Causal Network Use the CausalGraphicalModel class to create the DAG of the "Sprinkler" Causal Network:provide an array of nodesprovide an array of edges<jupyter_code>from causalgraphicalmodels import CausalGraphicalModel

sprinkler = CausalGraphicalModel(
    nodes=["season", "rain", "sprinkler", "wet", "slippery"],
    edges=[
        ("season", "rain"), 
        ("season", "sprinkler"), 
        ("rain", "wet"),
        ("sprinkler", "wet"), 
        ("wet", "slippery")
    ]
)<jupyter_output><empty_output><jupyter_text>Step 2. Show the DAG of the Causal Network<jupyter_code># draw the graphical model
sprinkler.draw()<jupyter_output><empty_output><jupyter_text>Step 3. Show the Joint Dstribution of the Causal Network<jupyter_code>print(sprinkler.get_distribution())<jupyter_output>P(season)P(rain|season)P(sprinkler|season)P(wet|rain,sprinkler)P(slippery|wet)<jupyter_text>Step 4. Run the intervention do("sprinkler") on the Causal Network<jupyter_code>sprinkler_do = sprinkler.do("sprinkler")<jupyter_output><empty_output><jupyter_text>Step 5. Show the Causal DAG with the intervention "on"<jupyter_code>sprinkler_do.draw()<jupyter_output><empty_output><jupyter_text>Step 6. Show the Joint Distibution of the Causal Network with the intervention "on"<jupyter_code>print(sprinkler_do.get_distribution())<jupyter_output>P(season)P(rain|season)P(wet|rain,do(sprinkler))P(slippery|wet)
{'fraction_non_alphanumeric': 0.10698198198198199, 'fraction_numerical': 0.0033783783783783786, 'mean_word_length': 6.692640692640692, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '83028', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 634, 'n_tokens_neox': 594, 'n_words': 149, 'path': 'Weeks_10-12/Lessons/causal_graphical_model_example.ipynb', 'repo_name': 'evassev/CS6462_SEM2_2021-2', 'size': '1776'}