AI Lesson 13 – Bayesian Networks | Dataplexa

Bayesian Networks

In the previous lesson, we learned how probability helps AI handle uncertainty. Bayesian Networks take this idea further by representing probabilistic relationships between multiple variables in a structured and visual way.

They allow AI systems to reason about cause, effect, and uncertainty at the same time.

What Is a Bayesian Network?

A Bayesian Network is a graphical model that represents random variables and their probabilistic dependencies.

It consists of:

  • Nodes: Random variables
  • Edges: Probabilistic dependencies
  • Conditional probabilities: How variables influence each other

The structure is a Directed Acyclic Graph (DAG), meaning it has direction and no cycles.

Real-World Connection

Consider medical diagnosis.

  • Rain → Wet ground
  • Wet ground → Slippery roads
  • Slippery roads → Accidents

Each event does not guarantee the next one, but it increases the probability. Bayesian Networks capture this uncertainty naturally.

Why Bayesian Networks Are Useful

Bayesian Networks allow AI systems to:

  • Reason under uncertainty
  • Update beliefs when new evidence appears
  • Model cause-and-effect relationships

They are widely used in healthcare, fraud detection, risk analysis, and expert systems.

Basic Bayesian Network Example

Let’s look at a simplified example with three variables:

  • Rain
  • Sprinkler
  • Wet Grass

Wet grass depends on whether it rained or the sprinkler was on.

Simple Probability Calculation Using Bayes’ Rule

Bayesian Networks rely on Bayes’ Theorem.


def bayes_theorem(p_b_given_a, p_a, p_b):
    return (p_b_given_a * p_a) / p_b

# Example values
p_rain = 0.2
p_wet_given_rain = 0.9
p_wet = 0.5

result = bayes_theorem(p_wet_given_rain, p_rain, p_wet)
print(result)
  
0.36

Code Explanation

This function applies Bayes’ Theorem:

  • p_b_given_a: Probability of evidence given a cause
  • p_a: Probability of the cause
  • p_b: Probability of the evidence

It calculates how likely the cause is after observing evidence.

Output Explanation

The output 0.36 means there is a 36% chance it rained given that the grass is wet.

This shows how Bayesian reasoning updates beliefs based on evidence.

Conditional Probability Tables (CPT)

Each node in a Bayesian Network has a Conditional Probability Table.

A CPT defines the probability of a variable given its parent variables.

This allows the network to compute probabilities efficiently even with many variables.

Where Bayesian Networks Are Used

  • Medical diagnosis systems
  • Spam and fraud detection
  • Risk assessment
  • Decision support systems
  • Fault detection in machines

They are especially powerful when data is incomplete or noisy.

Practice Questions (Logic + Code Thinking)

Practice 1: What probabilistic model represents dependencies using a graph?



Practice 2: What type of graph structure does a Bayesian Network use?



Practice 3: What is the main purpose of Bayesian reasoning?



Quick Quiz (Probability + Reasoning)

Quiz 1: What does Bayes’ Theorem mainly calculate?





Quiz 2: Edges in a Bayesian Network represent?





Quiz 3: Bayesian Networks update probabilities based on?





Coming up next: Markov Models — modeling sequences and state transitions over time.