Day 2: Basic Stats Required for Any AI Model (Part 2)

By Yash | January 31, 2025
A Little Speech Before We Begin

Alright, you made it to Day 2. That means you're serious about this, and I respect that.

By now, you’re probably seeing that AI isn’t just about slapping some fancy models together—it’s about understanding the foundations. And that’s exactly why we’re still here, grinding through the stats. Because without this, everything else is just guesswork.

Some of this might feel basic, some of it might stretch your brain a little, but trust me—it all matters. Every concept we cover is another building block toward coding Stable Diffusion from scratch. So stay focused, take notes, and push through.

Because the people who truly understand AI? They don’t just copy code. They build it.

Let’s get started.

Understanding Conditional Probability and Bayes' Theorem


Conditional Probability: The Given That Probability

Imagine you have a room with 100 people:
- 40 people wear glasses
- 25 of these glasses-wearers also drink coffee
- 45 people in total drink coffee

If I randomly pick someone who drinks coffee, what's the chance they wear glasses?
This is conditional probability: P(Glasses | Coffee) = Probability of glasses GIVEN THAT they drink coffee

The first term is what we want to find the probability of, the pipe (|), means GIVEN THAT, and Coffee is the conditioned path.

The formula is super simple:

P(A|B) = P(A and B) / P(B)

For our example:
P(Glasses | Coffee) = 25/45 ≈ 0.56 or 56%

Because: 25 people have both traits, divided by 45 total coffee drinkers.

Intuitively, it's pretty easy. As our problem was, glasses GIVEN THAT they drink coffee, so they must be drinking coffee is the first part. Out of those, they then mus be wearing glasses, hence the AND. Then we're just dividing the total number of people that drink coffee to get our probability.

Okay cool, but, why learn it? Will learning it give me 1 million bucks?

Probably not, but here is one intuitive reason,

Because life isn't binary. Life rarely gives you black-and-white choices. Continuous probability helps you navigate those shades of gray with mathematical precision—like calculating the odds of getting rained on during your picnic or how much caffeine is too much before bed.


Bayes' Theorem: Flipping the Condition

Sometimes we know P(B|A) but want P(A|B). Bayes' Theorem helps us flip the condition.

At first glance, Bayes' Theorem might look like one of those intimidating equations that only statisticians care about. But don't be fooled—it's a simple, powerful tool for updating your beliefs when you get new information. It's the math behind how we learn from experience and make better decisions, whether you're a doctor diagnosing a patient or just trying to figure out if you should trust that weather app predicting a sunny day.

P(A|B) = P(B|A) x P(A) / P(B)

In words, this reads: The probability of event A happening, given that B is true, depends on how likely B is when A happens, multiplied by the overall likelihood of A, and divided by how likely B is overall.

Imagine you're trying to figure out if it's worth bringing an umbrella based on the weather report. You know that rain is rare, but when it rains, the forecast is usually accurate. Here's how you can think about the components:

- P(A) = Prior belief: This is your starting assumption—what's the probability it will rain in general? Maybe it's 20% on any given day(0.2).
- P(B|A) = Likelihood: Now, you look at the weather report. Given that it's going to rain, how likely is it that the forecast says rain? Let's say the forecast is right 90% of the time(0.9).
- P(B) = Total probability of B (forecast says rain): This is the overall probability that the forecast says rain, no matter what. It's made up of both the true positive (forecasting rain when it rains) and false positive (forecasting rain when it doesn't). If the forecast predicts rain 20% of the time and it's right 90% of those times, the total probability of B is a mix of these scenarios.

P(False Positive) = 0.8 x 0.1= 0.08

P(B)=P(True Positive)+P(False Positive)=0.18+0.08=0.26

P(A|B) = (0.9 x 0.2)/0.26 = 0.18/0.26 ≈ 0.6923


Why Is Bayes' Theorem So Important?

- It's how we learn from new information. Bayes' Theorem formalizes the process of updating your beliefs as you gather evidence. This is crucial in science, medicine, and even everyday reasoning. For instance, a doctor diagnosing a disease considers both prior probabilities (how common the disease is) and test results (the likelihood of symptoms given the disease).

- It's counterintuitive and eye-opening. Sometimes, our instincts about probability are dead wrong. Bayes' Theorem forces us to confront those biases and shows why certain conclusions (like misinterpreting medical test results) might not be as straightforward as they seem.

A classic example from Thinking, Fast and Slow by Daniel Kahneman illustrates this well.

Imagine a city where 85% of taxis are green and 15% are blue.

A taxi was involved in a hit-and-run accident, and a witness identified it as blue. However, tests show that the witness correctly identifies taxi colors 80% of the time and makes mistakes 20% of the time.

At first glance, we might assume the probability that the taxi was actually blue is 80%, matching the witness’s accuracy.

But Bayes' theorem tells us to also consider the base rate—the fact that blue taxis are much rarer in the city. Applying the formula, we find that the actual probability of the taxi being blue is closer to 41%, not 80%. This is a classic example of how our intuition often neglects base rates, and Bayes' theorem helps us make better judgments.


CONGRATULATIONS!!!

You have just completed Day 2. Now do re-read the whole thing again. Until you can understand every concept. Take a pen and paper; and make notes. Revise. And remember, nothing is tough. You just need to have the hunger for knowledge.


If you found this content helpful and would like to support, feel free to contribute. Your support isn’t just a donation—it’s a step toward building something bigger, together.

Donate via PayPal