Graphical causal models

This model was covered in detail in Chapter 8Probabilistic Graphical Models. We will also look into it briefly here, too.

Bayesian networks are directed acyclic graphs (DAGs) where the nodes represent variables of interest (for example, the temperature of a device, the gender of a patient, a feature of an object, the occurrence of an event, and so on). Causal influences among the variables are represented using links. The strength of an influence can be potrayed by conditional probabilities that are linked to each cluster of the parent-child nodes in the network. In the following diagram we can see the causal models, that have a node and an edge:

The node represents the variables and the edges stand for conditional relationship between the variables. What we are looking for is full joint probability distribution. Here, the conditional dependency is being spoken. Rain causes the ground to be wet. However, winning the lottery has nothing to do with other variables. It's got conditional independence, as shown in the following diagram:

Here, the probability for conditional independence is as follows:

P(Lottery,Rain, Wet Ground)= P(Lottery) P(Rain) P(Wet Ground | Rain)

Therefore, we can say that a Bayesian network describes a probability distribution among all variables by putting conditional probability as edges.

Let's look at an example in Python:

  1. First, we need to load the library, CausalGraphicalModel, as follows:
from causalgraphicalmodels import CausalGraphicalModel
  1. Let's set up the model for a condition that if somebody is doing a Job and if it's powered by Smartwork and Hardwork, he/she reaps rewards and eventually, ends up having a promotion:
Model = CausalGraphicalModel(
nodes=["Job", "Smartwork", "Hardwork", "Reward", "Promotion"],
edges=[
("Job", "Smartwork"),
("Job", "Hardwork"),
("Smartwork", "Reward"),
("Hardwork", "Reward"),
("Reward", "Promotion")
]
)
Model.draw()

The following is the output of the preceding code:

  1. Let's obtain the distribution:
print(Model.get_distribution())

Then we will get the following as a output:

  1. Let's extract all of the conditional independence relationships:
Model.get_all_independence_relationships()

Here, we are able to assess the conditional independence among the variables.

  1. Let's mix this in with Reward:
Intervene = Model.do("Reward")
Intervene.draw()

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.76.204