Lesson 3 — Probability Foundations in Context
1.0 Probability as a Language for Uncertainty¶
Probability helps us reason about uncertainty.
Examples:
Will a customer make a purchase?
How many users will visit a website?
How variable are human heights?
How likely is an unusually high or low outcome?
One useful interpretation is the frequentist interpretation:
If we repeat a process many times, probability is the long-run proportion of outcomes. Simulation allows us to approximate these long-run proportions computationally.
2.0 Human Heights and the Normal Distribution¶
Suppose human heights are approximately Normally distributed with:
where:
is the mean,
is the standard deviation.
This means:
most observations should cluster near the mean,
while extremely high or low values should be relatively rare.
2.1 AI Prompt for Python Code¶
Suppose we want to simulate human heights using Python.
One possible prompt is:
Write Python code to:
- simulate 400 human heights,
- assuming heights follow a normal distribution with:
mean = 170 cm
standard deviation = 5 cm
Then:
1. print a few simulated heights,
2. plot a histogram using relative frequencies,
3. compute the proportion of heights between 170 and 175 cm.2.2 AI-Generated Python Code¶
import numpy as np
import matplotlib.pyplot as plt
# Set seed for reproducibility
np.random.seed(1001)
# Simulate heights
heights = np.random.normal(
loc=170,
scale=5,
size=400
)
# Show first 20 heights
print(heights[:20])
print("...")
# Show last 20 heights
print(heights[-20:])2.3 Histogram of Simulated Heights¶
plt.hist(
heights,
bins=20,
density=True,
edgecolor='black'
)
plt.xlabel("Height (cm)")
plt.ylabel("Relative Frequency")
plt.title("Simulated Human Heights")
plt.show()2.4 Estimating a Probability from Simulation¶
We can estimate probabilities using simulated data.
For example:
What proportion of individuals have heights between 170 and 175 cm?
prop = np.mean(
(heights >= 170) &
(heights <= 175)
)
print("Proportion between 170 and 175 cm:", prop)Does the probability makes sense? Think about the empirical rule.
3.0 Reflection¶
Think about the following questions:
Why are most observations close to the mean?
Why are extremely high or low heights relatively rare?
What is the proportion between 165 and 175 cm for the above heights example? Verify this with Python code.
What happens if the standard deviation increases?
What happens if the sample size increases?
What did simulation help you understand about probability?
Hint: Try changing
scale=10, size=1000The distribution above is an example of a Normal distribution.
4.0 The Normal Distribution¶
The Normal distribution is one of the most important probability distributions in statistics and data science.
It is:
symmetric,
bell-shaped,
and centered around a mean value.
Many real-world quantities are approximately Normally distributed, including:
human heights,
exam scores,
measurement errors,
and some economic variables.
The probability density function is:
where:
is the mean (center of the distribution),
is the standard deviation (spread of the distribution).
4.1 The Standard Normal Distribution¶
The standard normal distribution is a special case with:
The Normal distribution appears frequently in:
economics,
finance,
machine learning,
and scientific measurement.
The standard normal distribution is useful because many probability calculations can be converted into this standardized form.
5.0 Coin Tossing and Bernoulli Trials¶
Suppose:
Heads = 1
Tails = 0
Each coin toss has:
two possible outcomes,
equal probability,
and independent trials.
This type of process is called a Bernoulli trial.
5.1 AI Prompt for Python Code¶
Write Python code to:
- simulate 100 fair coin tosses,
- display the number of heads and tails,
- and plot a histogram using relative frequencies.5.2 AI-Generated Python Code¶
# Simulate 100 fair coin tosses
tosses = np.random.choice([0,1], size=100)
# Count outcomes
print("Heads:", sum(tosses))
print("Tails:", 100 - sum(tosses))5.3 Histogram of Coin Tosses¶
plt.hist(
tosses,
bins=[-0.5,0.5,1.5],
density=True,
edgecolor='black'
)
plt.xticks([0,1], ['Tails','Heads'])
plt.xlabel("Outcome")
plt.ylabel("Relative Frequency")
plt.title("Histogram of Coin Tosses")
plt.show()5.4 AI Prompt¶
Explain the Binomial distribution in simple language suitable for beginner students.
Then provide:
1. a short intuitive explanation,
2. the Binomial probability mass function in LaTeX,
3. explanations of:
- n
- k
- p
4. one real-world example.5.5 The Binomial Distribution¶
The Binomial distribution models the number of successes obtained from repeated independent trials.
Examples include:
number of customers who make a purchase,
number of students who pass an exam,
number of defective products,
or number of heads in repeated coin tosses.
Suppose:
each trial has only two outcomes,
success or failure,
the probability of success remains constant,
and trials are independent.
The Binomial distribution tells us:
“What is the probability of getting exactly successes out of trials?”
The probability mass function is:
where:
= number of trials,
= number of successes,
= probability of success on each trial.
5.6 Example: Marketing Conversion¶
Suppose:
a company emails 200 customers,
each customer has a 5% probability of purchasing.
The Binomial distribution can model:
the probability of exactly 10 purchases,
or the probability of unusually low conversions.
6.0 Other Useful Probability Distributions¶
6.1 Exponential Distribution¶
The Exponential distribution models waiting times between random events.
Examples include:
time until the next customer arrives,
waiting time between website visits,
time until machine failure,
or time between phone calls.
The probability density function is:
where:
is the rate parameter,
larger means events occur more frequently.
Example prompt:
Write Python code to generate and plot an Exponential distribution with different parameters.6.2 The Poisson Distribution¶
The Poisson distribution models the number of events occurring within a fixed interval.
Examples include:
number of customer arrivals,
number of website visits per minute,
number of accidents per day,
or number of emails received in an hour.
The probability mass function is:
where:
is the average number of events,
is the number of observed events.
Example prompt:
Write Python code to simulate a Poisson distribution with different values of lambda and plot histograms.7.0 Reflection on AI Workflow¶
AI can help us:
generate code,
explain concepts,
and accelerate experimentation.
However, humans remain responsible for:
interpretation,
verification,
and reasoning.
8.0 Homework¶
Go through the Lesson again, running the code in Goolge Colab.
Make sure you fully understand the empirical rule.
Explore the Exponential distribution.
Explore the Poisson distribution.
Save useful prompts into:
prompts/useful_prompts.mdWrite a short reflection in:
personal_log.md9.0 Resources¶
Optional¶
Ch8 Binomial and Poisson Distribution Ch9 Uniform and Exponential Probability Distribution