Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconArtificial Intelligencebreadcumb forward arrow iconBayesian Network Example [With Graphical Representation]

Bayesian Network Example [With Graphical Representation]

Last updated:
28th Jan, 2021
Read Time
9 Mins
share image icon
In this article
Chevron in toc
View All
Bayesian Network Example [With Graphical Representation]

In statistics, Probabilistic models are used to define a relationship between variables and can be used to calculate the probabilities of each variable. In many problems, there are a large number of variables. In such cases, the fully conditional models require a huge amount of data to cover each and every case of the probability functions which may be intractable to calculate in real-time. There have been several attempts to simplify the conditional probability calculations such as the Naïve Bayes but still, it does not prove to be efficient as it drastically cuts down several variables.

The only way is to develop a model that can preserve the conditional dependencies between random variables and conditional independence in other cases. This leads us to the concept of Bayesian Network and Bayesian Network Example. These Bayesian Networks help us to effectively visualize the probabilistic model for each domain and to study the relationship between random variables in the form of a user-friendly graph.

Learn ML Course from the World’s top Universities. Earn Masters, Executive PGP, or Advanced Certificate Programs to fast-track your career.

Best Machine Learning and AI Courses Online

Ads of upGrad blog

What are Bayesian Networks?

By definition, Bayesian Networks are a type of Probabilistic Graphical Model that uses the Bayesian inferences for probability computations. It represents a set of variables and its conditional probabilities with a Directed Acyclic Graph (DAG). They are primarily suited for considering an event that has occurred and predicting the likelihood that any one of the several possible known causes is the contributing factor.


As mentioned above, by making use of the relationships which are specified by the Bayesian Network, we can obtain the Joint Probability Distribution (JPF) with the conditional probabilities. Each node in the graph represents a random variable and the arc (or directed arrow) represents the relationship between the nodes. They can be either continuous or discrete in nature.

In-demand Machine Learning Skills

In the above diagram A, B, C and D are 4 random variables represented by nodes given in the network of the graph. To node B, A is its parent node and C is its child node. Node C is independent of Node A.

Before we get into the implementation of a Bayesian Network, there are a few probability basics that have to be understood.

Local Markov Property

The Bayesian Networks satisfy the property known as the Local Markov Property. It states that a node is conditionally independent of its non-descendants, given its parents. In the above example, P(D|A, B) is equal to P(D|A) because D is independent of its non-descendent, B. This property aids us in simplifying the Joint Distribution. The Local Markov Property leads us to the concept of a Markov Random Field which is a random field around a variable that is said to follow Markov properties.

FYI: Free Deep Learning Course!

Conditional Probability

In mathematics, the Conditional Probability of event A is the probability that event A will occur given that another event B has already occurred. In simple terms, p(A | B) is the probability of event A occurring, given that event, B occurs. However, there are two types of event possibilities between A and B. They may be either dependent events or independent events. Depending upon their type, there are two different ways to calculate the conditional probability.

  • Given A and B are dependent events, the conditional probability is calculated as P (A| B) = P (A and B) / P (B)
  • If A and B are independent events, then the expression for conditional probability is given by, P(A| B) = P (A)

Joint Probability Distribution

Before we get into an example of Bayesian Networks, let us understand the concept of Joint Probability Distribution. Consider 3 variables a1, a2 and a3. By definition, the probabilities of all different possible combinations of a1, a2, and a3 are called its Joint Probability Distribution.

If P[a1,a2, a3,….., an] is the JPD of the following variables from a1 to an, then there are several ways of calculating the Joint Probability Distribution as a combination of various terms such as,

P[a1,a2, a3,….., an] = P[a1 | a2, a3,….., an] * P[a2, a3,….., an]

= P[a1 | a2, a3,….., an] * P[a2 | a3,….., an]….P[an-1|an] * P[an]


Generalizing the above equation, we can write the Joint Probability Distribution as,

P(Xi|Xi-1,………, Xn) = P(Xi |Parents(Xi ))

Bayesian Network Example

Let us now understand the mechanism of Bayesian Networks and their advantages with the help of a simple example. In this example, let us imagine that we are given the task of modeling a student’s marks (m) for an exam he has just given. From the given Bayesian Network Graph below, we see that the marks depend upon two other variables. They are,

  • Exam Level (e)– This discrete variable denotes the difficulty of the exam and has two values (0 for easy and 1 for difficult)
  • IQ Level (i) – This represents the Intelligence Quotient level of the student and is also discrete in nature having two values (0 for low and 1 for high)

Additionally, the IQ level of the student also leads us to another variable, which is the Aptitude Score of the student (s). Now, with marks the student has scored, he can secure admission to a particular university. The probability distribution for getting admitted (a) to a university is also given below.

In the above graph, we see several tables representing the probability distribution values of the given 5 variables. These tables are called the Conditional Probabilities Table or CPT. There are a few properties of the CPT given below –

  • The sum of the CPT values in each row must be equal to 1 because all the possible cases for a particular variable are exhaustive (representing all possibilities).
  • If a variable that is Boolean in nature has k Boolean parents, then in the CPT it has 2K probability values.

Coming back to our problem, let us first list all the possible events that are occurring in the above-given table.

  1. Exam Level (e)
  2. IQ Level (i)
  3. Aptitude Score (s)
  4. Marks (m)
  5. Admission (a)

These five variables are represented in the form of a Directed Acyclic Graph (DAG) in a Bayesian Network format with their Conditional Probability tables. Now, to calculate the Joint Probability Distribution of the 5 variables the formula is given by,

P[a, m, i, e, s]= P(a | m) . P(m | i, e) . P(i) . P(e) . P(s | i)

From the above formula,

  • P(a | m) denotes the conditional probability of the student getting admission based on the marks he has scored in the examination.
  • P(m | i, e) represents the marks that the student will score given his IQ level and difficulty of the Exam Level.
  • P(i) and P(e) represent the probability of the IQ Level and the Exam Level.
  • P(s | i) is the conditional probability of the student’s Aptitude Score, given his IQ Level.

With the following probabilities calculated, we can find the Joint Probability Distribution of the entire Bayesian Network.

Calculation of Joint Probability Distribution

Let us now calculate the JPD for two cases.

Case 1: Calculate the probability that in spite of the exam level being difficult, the student having a low IQ level and a low Aptitude Score, manages to pass the exam and secure admission to the university.

From the above word problem statement, the Joint Probability Distribution can be written as below,

P[a=1, m=1, i=0, e=1, s=0]

From the above Conditional Probability tables, the values for the given conditions are fed to the formula and is calculated as below.

P[a=1, m=1, i=0, e=0, s=0] = P(a=1 | m=1) . P(m=1 | i=0, e=1) . P(i=0) . P(e=1) . P(s=0 | i=0)

= 0.1 * 0.1 * 0.8 * 0.3 * 0.75

= 0.0018

Case 2: In another case, calculate the probability that the student has a High IQ level and Aptitude Score, the exam being easy yet fails to pass and does not secure admission to the university.

Also Read: Machine Learning Project Ideas & Topics

The formula for the JPD is given by

P[a=0, m=0, i=1, e=0, s=1]


P[a=0, m=0, i=1, e=0, s=1]= P(a=0 | m=0) . P(m=0 | i=1, e=0) . P(i=1) . P(e=0) . P(s=1 | i=1)

= 0.6 * 0.5 * 0.2 * 0.7 * 0.6

= 0.0252

Hence, in this way, we can make use of Bayesian Networks and Probability tables to calculate the probability for various possible events that occur.

Ads of upGrad blog

Popular AI and ML Blogs & Free Courses


Bayesian Networks find extensive utility across various domains like Spam Filtering, Semantic Search, and Information Retrieval. A prime illustration of their effectiveness lies in predicting disease probabilities based on symptoms and other relevant factors. This concept of Bayesian Network is elucidated herein, exemplified through a practical instance known as the Bayesian Network Example.

If you are curious to master Machine learning and AI, boost your career with an Advanced Course on Machine Learning and AI with IIIT-B & Liverpool John Moores University.


Pavan Vadapalli

Blog Author
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology strategy.
Get Free Consultation

Selectcaret down icon
Select Area of interestcaret down icon
Select Work Experiencecaret down icon
By clicking 'Submit' you Agree to  
UpGrad's Terms & Conditions

Our Popular Machine Learning Course

Frequently Asked Questions (FAQs)

1How are Bayesian networks implemented?

A Bayesian network is a graphical model where each of the nodes represent random variables. Each node is connected to other nodes by directed arcs. Each arc represents a conditional probability distribution of the parents given the children. The directed edges represent the influence of a parent on its children. The nodes usually represent some real-world objects and the arcs represent some physical or logical relationship between them. Bayesian networks are used in many applications like automatic speech recognition, document/image classification, medical diagnosis, and robotics.

2Why is the Bayesian network important?

As we know, the Bayesian network is an important part of machine learning and statistics. It is used in data mining and scientific discovery. Bayesian network is a directed acyclic graph (DAG) with nodes representing random variables and arcs representing direct influence. Bayesian network is used in various applications like Text analysis, Fraud detection, Cancer detection, Image recognition etc. In this article, we will discuss Reasoning in Bayesian networks. Bayesian Network is an important tool for analyzing the past, predicting the future and improving the quality of decisions. Bayesian Network has its origins in statistics, but it is now being used by all professionals including Research Scientists, Operations Research Analysts, Industrial Engineers, Marketing Professionals, Business Consultants and even Managers.

3What is a Sparse Bayesian Network?

A Sparse Bayesian Network (SBN) is a special kind of Bayesian network where the conditional probability distribution is a sparse graph. It might be appropriate to use a SBN when the number of variables is large and/or the number of observations is small. In general, Bayesian Networks are most useful when you are interested in explaining an observation or event by conditioning on a number of factors.

Explore Free Courses

Suggested Blogs

45+ Best Machine Learning Project Ideas For Beginners [2024]
Summary: In this Article, you will learn Stock Prices Predictor Sports Predictor Develop A Sentiment Analyzer Enhance Healthcare Prepare ML Algorith
Read More

by Jaideep Khare

21 May 2024

Top 15 IoT Interview Questions & Answers 2024 – For Beginners & Experienced
These days, the minute you indulge in any technology-oriented discussion, interview questions on cloud computing come up in some form or the other. Th
Read More

by Kechit Goyal

19 May 2024

40 Best IoT Project Ideas & Topics For Beginners 2024 [Latest]
In this article, you will learn the 40Exciting IoT Project Ideas & Topics. Take a glimpse at the project ideas listed below. Best Simple IoT Proje
Read More

by Kechit Goyal

19 May 2024

Top 22 Artificial Intelligence Project Ideas & Topics for Beginners [2024]
In this article, you will learn the 22 AI project ideas & Topics. Take a glimpse below. Best AI Project Ideas & Topics Predict Housing Price
Read More

by Pavan Vadapalli

18 May 2024

Image Segmentation Techniques [Step By Step Implementation]
What do you see first when you look at your selfie? Your face, right? You can spot your face because your brain is capable of identifying your face an
Read More

by Pavan Vadapalli

16 May 2024

6 Types of Regression Models in Machine Learning You Should Know About
Introduction Linear regression and logistic regression are two types of regression analysis techniques that are used to solve the regression problem
Read More

by Pavan Vadapalli

16 May 2024

How to Make a Chatbot in Python Step By Step [With Source Code]
Creating a chatbot in Python is an essential skill for modern developers looking to enhance user interaction and automate responses within application
Read More

by Kechit Goyal

13 May 2024

Artificial Intelligence course fees
Artificial intelligence (AI) was one of the most used words in 2023, which emphasizes how important and widespread this technology has become. If you
Read More

by venkatesh Rajanala

29 Feb 2024

Artificial Intelligence in Banking 2024: Examples & Challenges
Introduction Millennials and their changing preferences have led to a wide-scale disruption of daily processes in many industries and a simultaneous g
Read More

by Pavan Vadapalli

27 Feb 2024

Schedule 1:1 free counsellingTalk to Career Expert
footer sticky close icon