Skip to content

Part 1: Conditional Probability

▶ Part 1: Conditional Probability

▶ Part 2: Bayes' Theorem

▶ Part 3: Bayes' Theorem in AI

▶ Part 4: Naive Bayes


Probability and Bayes are at the heart of how AI deals with uncertainty, evidence, and prediction.

This series builds the intuition behind conditional probability and Bayes' theorem, without getting lost in unnecessary mathematical machinery.

The reader is expected to be familiar with basic probability concepts, such as events, outcomes, sample spaces, and probability distributions.


1. Conditional Probability: Probability AFTER we learn something

Probabilitye BEFORE we know anything

Suppose we roll a six-sided die.

Before we know anything about the result, the possibilities are:

1  2  3  4  5  6

What is the probability of rolling a 2?

\[ P(2) = \frac{1}{6} \]

Probabilitye AFTER we know anything

Now suppose someone tells us:

"The number is even."

That information changes the situation.

We can immediately eliminate:

1  3  5

We are now left with:

2  4  6

Among these three possibilities, only one is 2.

So the probability of rolling a 2, given that we know the number is even, is:

\[ P(2 \mid \text{Even}) = \frac{1}{3} \]

Notice what happened.

BEFORE receiving the information:

\[ P(2) = \frac{1}{6} \]

AFTER receiving the information:

\[ P(2 \mid \text{Even}) = \frac{1}{3} \]

Nothing about the die changed.

Our information changed. And because our information changed, the probability changed. This is idea behind conditional probaility.

The basic idea of conditional probaility

Conditional probability is simply:

What is the probability of A, now that I know B is true?

We write this as:

\[ P(A \mid B) \]

Read it as:

"The probability of A given B."

The vertical bar | means given that.

So:

\[ P(\text{2} \mid \text{Even}) \]

means:

"What is the probability of getting 2, given that I already know the number is even?"

The important shift

The easiest way to think about conditional probability is not as a new kind of probability.

It is ordinary probability calculated over a restricted set of possibilities.

Initially, we had:

1  2  3  4  5  6

After learning that the number is even:

2  4  6

The information has effectively changed the universe we are considering.

That simple idea is the foundation for everything that follows.

And it leads directly to the question that causes most of the confusion:

How exactly do we calculate the probability once the possibilities have been restricted?

Forget the possibilities that are no longer possible. Work only with the possibilities consistent with what we now know.


2. Worked example of Conditional Probability

The formula is:

\[ P(A \mid B) = \frac{P(A \cap B)}{P(B)} \]

At first glance, this looks like one of those formulas that was designed to make a simple idea look complicated.

It is actually saying something very simple:

Once I know B has happened, I only care about the world where B is true.

The denominator tells us the size of that new world.

Back to the die example

We already saw this example:

1 2 3 4 5 6

Suppose we learn that the number is even.

Our new universe is:

2 4 6

We want the probability that the number is 2.

There is:

1 possibility we want  (i.e. 2)
3 possibilities we are considering (i.e. 2,4,6)

So:

\[ P(2 \mid \text{Even}) = \frac{1}{3} \]

Using the conditional probability formula

Now let's put the actual values into every part of the formula defined above, and we should get the same result as above (i.e 0.33) .

The conditional probability formula is:

\[ P(A \mid B) = \frac{P(A \cap B)}{P(B)} \]

=

\[ P(2 \mid Even) = \frac{P(2 \cap Even)}{P(Even)} \]

Lets find values of each part:

The probability of rolling an even number is:

\[ P(\text{Even}) = \frac{3}{6} = \frac{1}{2} = 0.5 \]

Now consider the intersection:

\[ P(2 \cap \text{Even}) \]

This means:

The set of numbers in 2 AND even (2 AND {2,4,6}) is only one number i.e. 2

\[ P(2 \cap \text{Even}) = P(2) \]

And the probability of rolling a 2 is:

\[ P(2 \cap \text{Even}) = P(2) = \frac{1}{6} \approx 0.1667 \]

Now substitute the actual values into the conditional probability formula:

\[ P(2 \mid \text{Even}) = \frac{P(2 \cap \text{Even})}{P(\text{Even})} = \frac{P(2)}{P(Even)} = \frac{\frac{1}{6}}{\frac{3}{6}} \]
\[ = \frac{1}{3} \]
\[ \approx 0.3333 \]
\[ \approx 33.33\% \]

Therefore:

\[ \boxed{P(2 \mid \text{Even})=\frac{1}{3}\approx33.33\%} \]

That is really all the formula is saying.


3. Independent vs. dependent events

Now we have an important question.

Does knowing one event happened always change the probability of another event?

No.

Sometimes the information changes the probability.

Sometimes it does absolutely nothing.

That gives us the idea of dependence and independence.

Dependent events

Suppose we have a bag containing:

3 red balls
2 blue balls

We pick one ball and do not put it back.

The probability of picking a red ball on the first draw is:

\[ P(\text{Red}) = \frac{3}{5} \]

Suppose we pick a red ball.

Now there are only:

2 red balls
2 blue balls

left.

The probability of getting a red ball on the second draw is now:

\[ P(\text{Red on second draw} \mid \text{Red on first draw}) = \frac{2}{4} = \frac{1}{2} \]

The first draw changed the second probability.

The events are therefore dependent.

Independent events

Now imagine tossing a coin twice.

The first toss is:

Heads

Does that change the probability of Heads on the second toss?

No.

The second toss still has:

\[ P(\text{Heads}) = \frac{1}{2} \]

The first toss gives us no useful information about the second toss.

The events are independent.

The key idea

Two events are independent when knowing that one happened does not change the probability of the other.

In other words:

\[ P(A \mid B) = P(A) \]

If knowing \(B\) happened changes the probability of \(A\), then the events are dependent.

So the simplest way to think about independence is:

Does knowing one thing tell me anything about the other?

If yes, they are dependent.

If no, they are independent.

One important trap

Independence does not mean that two events cannot happen together.

For example, getting Heads on the first coin toss and Heads on the second toss can obviously happen together.

Independence simply means:

The outcome of one does not affect the probability of the other.

This distinction becomes very important later when we start looking at probabilities of multiple events happening together.

Independent vs. Dependent: The formulas

Independent events Dependent events
### Independent vs. Dependent: The formulas
Independent Dependent
\(P(A \mid B) = P(A)\) \(P(A \mid B) = \frac{P(A \cap B)}{P(B)}\)
B does not change the probability of A. B changes the probability of A.

4. The difference between \(P(A \mid B)\) and \(P(B \mid A)\)

This is one of the easiest things to confuse in probability.

Consider this statement:

"If someone is a doctor, they are likely to have studied medicine."

That is:

\[ P(\text{Studied Medicine} \mid \text{Doctor}) \]

Now reverse it:

"If someone studied medicine, they are likely to be a doctor."

That is:

\[ P(\text{Doctor} \mid \text{Studied Medicine}) \]

These are not the same probability.

The information after the | tells us what we already know.

So:

\[ P(A \mid B) \]

means:

"What is the probability of A, given that I know B?"

while:

\[ P(B \mid A) \]

means:

"What is the probability of B, given that I know A?"

The direction matters.

A simple example

Suppose a company has 100 employees.

60 employees are developers
40 employees are not developers

20 developers are managers
5 non-developers are managers

So there are 25 managers in total.

Now ask:

What is the probability that an employee is a manager, given that they are a developer?

We are looking only at the 60 developers.

Among them, 20 are managers.

Therefore:

\[ P(\text{Manager} \mid \text{Developer}) = \frac{20}{60} = \frac{1}{3} \]

Now reverse the question:

What is the probability that an employee is a developer, given that they are a manager?

We are now looking only at the 25 managers.

Among them, 20 are developers.

Therefore:

\[ P(\text{Developer} \mid \text{Manager}) = \frac{20}{25} = 0.8 \]

So:

\[ P(\text{Manager} \mid \text{Developer}) = \frac{1}{3} \]

but

\[ P(\text{Developer} \mid \text{Manager}) = 0.8 \]

Same people. Same data.

Different question, different probability.

The easiest way to remember it

Look at what comes after the bar.

\[ P(A \mid B) \]

means:

Start with B. Among B, how many are A?

And:

\[ P(B \mid A) \]

means:

Start with A. Among A, how many are B?

This distinction is extremely important because Bayes' theorem is largely about moving from one direction to the other.

That is where we go next. ▶ Part 2: Bays' Theorem


AI in Context Main Page