Understanding Discrete Random Variables
Understanding Discrete Random Variables
In data analytics, we use random variables to model things we measure but cannot
perfectly predict:
1. Discrete Random Variable (DRV): Outcomes you can count. They are distinct and
separate values. (e.g., 0, 1, 2, 3 cups of coffee).
2. Continuous Random Variable (CRV): Outcomes you can measure. They can take
any value within an interval. (e.g., the exact time spent on a website: 2.35 minutes,
5.17 minutes, etc.).
Notation:
TT -> X = 0
TH -> X = 1
HT -> X = 1
HH -> X = 2
o So, the possible values x for X are {0, 1, 2}.
1. Non-Negativity: The probability for any specific value must be between 0 and 1.
o 0 ≤ P(X = x) ≤ 1 for all possible values x.
2. Sum to One: The sum of the probabilities for all possible values must equal 1. This
makes sense because something must happen.
o Σ P(X = x) = 1 for all x.
This table is the core of the discrete random variable. It lists every possible outcome
and its probability.
Step-by-Step Calculation of Probabilities
From the table above, we can now answer probabilistic questions:
[Link](figsize=(8, 5))
[Link](number_of_items, probabilities, color='skyblue', edgecolor='black', t
ick_label=labels)
[Link]('Probability Distribution: Items Added to Cart')
[Link]('Number of Items')
[Link]('Probability')
[Link](0, 0.5) # Set y-axis limit from 0 to 0.5 for better readability
[Link](axis='y', alpha=0.4)
[Link]()
Applications in Data Analytics
Understanding DRVs is crucial for:
Analysis:
1. The analyst defines X as the number of items in the cart at the time of abandonment
or purchase.
2. They calculate two probability distributions:
o One distribution for abandoned carts.
o One distribution for completed purchases.
3. By comparing these two distributions (e.g., using side-by-side bar charts), they might
discover that carts with only 1 item are abandoned 70% of the time, while carts with
3+ items are only abandoned 20% of the time.
Insight & Action: This suggests the business should create promotions or incentives
(like "add 2 more items for free shipping") to encourage customers with small carts
to add more items, potentially reducing abandonment.
Key Takeaways
A Discrete Random Variable (DRV) counts outcomes and has distinct, separate
values.
Its behavior is defined by its probability distribution—a list of all possible values
and their corresponding probabilities.
The probabilities must be non-negative and sum to 1.
Bar charts are the ideal way to visualize them.
They are the foundation for modeling count-based events in business and analytics.
Assuming Independence: Just because you can model something with a DRV
doesn't mean the events are independent. (e.g., adding one item might make you
more likely to add another).
Ignoring the "Long Tail": In analytics, many events (like purchases) have a few very
high values. Grouping these into a "4+" category is practical, but be aware it hides
detail.
Practice Questions:
1. Define a DRV for the "sum of two dice rolls." List all its possible values.
2. In the cart example, what is P(X ≤ 2)?
3. You survey 10 people on how many smartphones they own. Is this a DRV or CRV?
Why?
4. If P(X=0) = 0.1, P(X=1)=0.3, P(X=2)=0.4, what must P(X=3) be?
For data analysts, the PMF is a crucial tool. It provides a complete description of the
random variable's behavior, allowing us to calculate any probability we need and to
understand the likelihood of different scenarios before they happen.
p(x)=P(X=x)p(x)=P(X=x)
For a function to be a valid PMF, it must satisfy the two fundamental rules of
probability we saw earlier:
2. Normalization: The sum of probabilities over all possible values xx must equal 1.
This ensures that the probability of something happening is 100%.
∑all xp(x)=1all x∑p(x)=1
p(0)=P(X=0)=P(TT)=14p(0)=P(X=0)=P(TT)=41
p(1)=P(X=1)=P(TH, HT)=24=12p(1)=P(X=1)=P(TH, HT)=42=21
p(2)=P(X=2)=P(HH)=14p(2)=P(X=2)=P(HH)=41
We can express this PMF in a table:
xx p(x)p(x)
0 0.25
1 0.50
2 0.25
Sum 1.0
0 0.20
1 0.35
2 0.25
3 0.15
4 0.05
Sum 1.00
A bar chart is also perfectly appropriate and is often used in business contexts for its
clarity.
plt.tight_layout()
[Link]()
(This code would create a side-by-side comparison of a stem plot and a bar chart for
the same PMF.)
Resource Planning: A cloud company uses the PMF of server requests per second to
determine how many servers to have running to handle load without over-
provisioning.
Customer Segmentation: Users can be segmented based on their "number of
purchases" PMF. Marketing campaigns are then tailored to each segment (e.g., re-
engagement campaigns for the x=0 group).
Risk Modeling: In finance, the PMF of "number of defaulting loans" in a portfolio is
used to calculate potential losses.
Analysis:
1. The analyst reviews historical data and builds a PMF for the number of daily support
tickets (XX).
2. The PMF might show:
o p(10)=0.05p(10)=0.05 (a very slow day)
o p(25)=0.20p(25)=0.20 (a typical day)
o p(40)=0.02p(40)=0.02 (a very busy day)
3. The team calculates the expected value (a concept we'll cover later) from this PMF,
which is a weighted average. Let's say E[X]=26E[X]=26 tickets.
4. They also look at the probability of high-volume
events: P(X>35)=p(36)+p(37)+...=0.08P(X>35)=p(36)+p(37)+...=0.08.
Insight & Action: The team decides to schedule enough staff to handle 26 tickets
comfortably. However, because there's an 8% chance of getting more than 35 tickets,
they also create an on-call list for such high-volume scenarios. The PMF allows for
both optimal planning and contingency planning.
Key Takeaways
A Probability Mass Function (PMF) p(x)p(x) is the function that gives the
probability that a discrete random variable XX is exactly equal to xx.
It must satisfy: p(x)≥0p(x)≥0 and ∑all xp(x)=1∑all xp(x)=1.
It is most commonly presented as a table or visualized with a stem plot or bar
chart.
The power of the PMF lies in its ability to answer any probabilistic question about
the random variable through simple addition.
It is a foundational tool for descriptive analytics, forecasting, and risk assessment.
Confusing PMF with PDF: The PMF is for discrete variables (points). The Probability
Density Function (PDF) is for continuous variables (areas under a curve). This is a
critical distinction.
Ignoring the Sample Space: The PMF is only defined for the possible values
of XX. p(x)=0p(x)=0 for any value xx not in that list.
Practice Questions:
(Answers: 1. Calculate sum: 1/10 + 2/10 + 3/10 + 4/10 = 10/10 = 1. And all p(x)
> 0. So, yes, it is valid. 2. P(X<=25) is not just p(10)+p(25). We are missing the
probabilities for all other values between 0 and 25. This highlights the pitfall of
needing a complete PMF. 3. Possible outcomes: {HHH, HHT, HTH, THH, HTT,
THT, TTH, TTT}. X = number of tails: {0, 1, 1, 1, 2, 2, 2, 3}. Therefore: p(0)=1/8,
p(1)=3/8, p(2)=3/8, p(3)=1/8.)
Topic 3: Continuous Random Variables — Basic Concepts
Introduction: The World is Continuous
In the previous topics, we dealt with outcomes you can count (number of items,
logins, heads). But many things we measure in data analytics are not counts; they
are measurements. These measurements can take on any value within an interval.
Consider:
The exact time a customer spends on your website (e.g., 2.357 minutes).
The height of a user (e.g., 175.4 cm).
The annual revenue of a customer (e.g., $243,561.78).
The temperature of a server CPU (e.g., 67.3°C).
These are not whole numbers. They can be infinitely precise. A Continuous Random
Variable (CRV) is used to model these types of outcomes. The key difference from a
Discrete Random Variable (DRV) is that a CRV can take on any value in a continuous
interval.
For a Continuous Random Variable (CRV), the probability of it taking on any single,
exact value is zero.
This doesn't mean the value is impossible; it just means we must think about
probability differently. For CRVs, we only calculate probability for intervals.
PMF (Discrete): The probability p(x) is the mass (the actual probability) assigned to
the point x.
PDF (Continuous): The function f(x) gives the density of the probability at the
point x. It tells us how "packed" or " dense" the probability is around that point. To
find the actual probability, we must find the area under the PDF curve over an
interval.
2. Normalization: The total area under the entire curve of the PDF must be exactly 1.
This represents the fact that the probability of X taking some value is 100%.
∫−∞∞f(x) dx=1∫−∞∞f(x)dx=1
The probability that X falls between two points a and b is the area under the PDF
curve between those points.
P(a≤X≤b)=∫abf(x) dxP(a≤X≤b)=∫abf(x)dx
Real-Life Data Analytics Example: Website Session Duration
Scenario: A web analyst is modeling the time users spend on a website. This is a
continuous random variable T (time in minutes).
They determine that the time follows a distribution with the following PDF (this is a
simplified example):
Question: What is the probability that a randomly selected user spends between 5
and 10 minutes on the site?
Answer: We need to find the area under the f(t) curve from t=5 to t=10.
P(5≤T≤10)=∫510110e−t/10 dtP(5≤T≤10)=∫510101e−t/10dt
We would calculate this integral to find the exact probability. (Spoiler: The result is
approximately e^{-0.5} - e^{-1} ≈ 0.6065 - 0.3679 = 0.2386 or 23.86%).
This code would produce a graph with a decaying curve. The shaded area between 5
and 10 minutes represents the 23.86% probability we calculated. The height of the
curve at any point is the density, not the probability.
Analysis:
1. The engineer defines X as the server response time, a continuous random variable.
2. They collect a massive sample of response times and plot a histogram. They discover
the data is right-skewed—most responses are fast, but there's a long tail of slower
responses.
3. They fit a theoretical PDF (e.g., a log-normal or gamma distribution) to this data. This
PDF model, f(x), describes the pattern of their response times.
4. The question becomes: What is the value c such that the area under the PDF
from 0 to c is 0.99?
P(X≤c)=∫0cf(x) dx=0.99P(X≤c)=∫0cf(x)dx=0.99
Insight & Action: The calculated 99th percentile is 190 ms. This means 99% of
requests are handled in under 190 ms, which safely meets the 200 ms SLA. The
model also shows that improving performance for the slowest 1% of requests would
be very challenging, helping the team set realistic goals.
Key Takeaways
Interpreting PDF height as probability: This is the most common error. The
value f(x) is a density, not a probability. Only an area gives a probability.
Forgetting P(X=x)=0: Asking for the probability of an exact value in a continuous
setting is meaningless.
Practice Questions:
(Answers: 1. Because there are infinitely many possible values, making the
probability of any single one effectively zero. 2. It tells you that values around
x=10 are very dense or likely; a small interval around 10 will have a high
probability. 3. 1. 4. No, P(Spend = $50) = 0. Yes, we can calculate P(50 ≤ Spend
≤ 100) by finding the area under the PDF between 50 and 100.)
Topic 4: Probability Density Functions (PDF)
Introduction: The "Density" in Probability
In the previous topic, we established that for continuous random variables,
probability is measured as the area under a curve. The Probability Density Function
(PDF) is the mathematical function that defines this curve. It is the continuous analog
of the Probability Mass Function (PMF).
For data analysts, the PDF is a powerful model. Once we have a PDF that fits our
data, we can answer any question about the probability of future events within that
continuum.
P(a≤X≤b)=∫abf(x) dxP(a≤X≤b)=∫abf(x)dx
This equation is the heart of the PDF. It states that the probability that XX falls
between aa and bb is the definite integral (the area under the curve) of the PDF
from aa to bb.
Key Insight: A PDF value f(x) can be greater than 1, as long as the total area under
the curve is 1. For example, a very tall and very narrow PDF "spike" can have a height
much greater than 1, but its width is so small that its area is a tiny probability.
Scenario: A call center's data analyst is modeling the duration of customer service
calls. The data is continuous and is well-modeled by a probability distribution with
the following PDF:
where xx is the call length in minutes. This is the PDF of the exponential
distribution, which is commonly used to model time until an event (like the end of a
call).
Question: What is the probability that a randomly selected call lasts between 5 and
10 minutes?
Answer: We find the area under the PDF curve between 5 and 10.
P(5≤X≤10)=∫5100.1e−0.1x dxP(5≤X≤10)=∫5100.1e−0.1xdx
Step-by-Step Calculation (Using Calculus and Python)
Let's solve the integral from the previous page.
1. Calculus Solution:
∫0.1e−0.1x dx=−e−0.1x+C∫0.1e−0.1xdx=−e−0.1x+C
Therefore,
∫5100.1e−0.1x dx=[−e−0.1x]510=(−e−1)−(−e−0.5)=−e−1+e−0.5∫510
0.1e−0.1xdx=[−e−0.1x]510
=(−e−1)−(−e−0.5)=−e−1+e−0.5≈−0.3679+0.6065=0.2386≈−0.3679+0.6065=0.23
86
So, there is approximately a 23.86% chance a call lasts between 5 and 10 minutes.
This code uses the Cumulative Distribution Function (CDF), which we will cover next.
The output will be:
P(5 <= X <= 10) = 0.2387 or 23.87%
import numpy as np
import [Link] as plt
from [Link] import expon
Predict Probabilities: What is the probability a user session will last more than 30
minutes?
Identify Outliers: Values where the PDF is extremely low (e.g., in the tails of a normal
distribution) are rare and might be outliers worth investigating (e.g., fraudulent
transactions).
Simulate Real-World Processes: PDFs are used in Monte Carlo simulations to
model complex systems like stock markets or queue waiting times by generating
random variables that follow the PDF's pattern.
Calculate Expected Values: The mean of a distribution (a crucial concept for
reporting "average" values) is calculated using the
PDF: E[X]=∫xf(x)dxE[X]=∫xf(x)dx.
Analysis:
Insight & Action: The company can confidently set its SLA to 620 ms. This means
they are contractually promising that 99.9% of all API responses will be faster than
620 ms. The PDF model provides a rigorous, data-driven foundation for this critical
business decision.
Key Takeaways
The Probability Density Function (PDF) defines the shape of the distribution for a
continuous random variable.
f(x) is a density, not a probability. Probability is given by the area under the PDF
curve over an interval.
The total area under any PDF is always exactly 1.
PDFs are used to calculate probabilities, identify outliers, simulate processes,
and calculate summary statistics like the mean and variance.
Choosing the right PDF model (e.g., Normal, Exponential, Lognormal) for your data is
a key skill in data analytics.
"f(5) = 0.4, so the probability is 40%." INCORRECT. f(5) is the density. The
probability at a point is zero.
Ignoring the support of the PDF. The PDF is only defined over a specific range
(e.g., x >= 0 for the exponential distribution). Outside this range, f(x) = 0.
Practice Questions:
1. If f(x) is the PDF of rainfall in a day, what does ∫₀¹ f(x)dx represent?
2. Can the value of a PDF be greater than 1? Why or why not?
3. True or False: The probability that a continuous random variable equals 5 is
always f(5).
4. A PDF is defined as f(x) = c * x for 0 <= x <= 4, and 0 otherwise. What must the
value of c be to make this a valid PDF? (Hint: Total area must be 1).
(Answers: 1. The probability that rainfall is between 0 and 1 unit. 2. Yes, as long
as the area under the curve is 1. A very tall, very narrow spike can have a height
>1. 3. False. P(X=5)=0. f(5) is the density. 4. Solve ∫₀⁴ (c*x) dx = 1. ∫₀⁴ c*x dx =
c * [x²/2]₀⁴ = c * (8 - 0) = 8c. Set 8c = 1, so c = 1/8.)
Topic 5: Cumulative Distribution Functions (CDF)
Introduction: The "Running Total" of Probability
The Cumulative Distribution Function (CDF) is a fundamental concept in probability
theory that provides a different perspective on the distribution of a random variable.
While the PMF (for discrete) and PDF (for continuous) give you the probability or
density at a point, the CDF gives you the probability that a random variable takes a
value less than or equal to a specific number. It is, in essence, a "running total" of
probabilities.
F(x)=P(X≤x)F(x)=P(X≤x)
This function has the following properties:
F(x)=P(X≤x)=∑k≤xp(k)F(x)=P(X≤x)=k≤x∑p(k)
where p(k)p(k) is the PMF at kk.
p(0)=0.2,p(1)=0.5,p(2)=0.3p(0)=0.2,p(1)=0.5,p(2)=0.3
Then the CDF is:
F(−0.5)=P(X≤−0.5)=0F(−0.5)=P(X≤−0.5)=0
F(0)=P(X≤0)=p(0)=0.2F(0)=P(X≤0)=p(0)=0.2
F(0.5)=P(X≤0.5)=p(0)=0.2F(0.5)=P(X≤0.5)=p(0)=0.2
F(1)=P(X≤1)=p(0)+p(1)=0.7F(1)=P(X≤1)=p(0)+p(1)=0.7
F(1.5)=P(X≤1.5)=p(0)+p(1)=0.7F(1.5)=P(X≤1.5)=p(0)+p(1)=0.7
F(2)=P(X≤2)=p(0)+p(1)+p(2)=1.0F(2)=P(X≤2)=p(0)+p(1)+p(2)=1.0
F(3)=1.0F(3)=1.0
Notice how the CDF remains constant between integers and jumps at the integer
values.
F(x)=P(X≤x)=∫−∞xf(t) dtF(x)=P(X≤x)=∫−∞xf(t)dt
where f(t)f(t) is the PDF.
F(x)=∫0xλe−λt dt=1−e−λxF(x)=∫0xλe−λtdt=1−e−λx
Real-Life Data Analytics Example: Customer Waiting Times
Scenario: A company models the waiting time (in minutes) for customer service calls
using an exponential distribution with rate parameter λ=0.2λ=0.2 (so mean waiting
time is 5 minutes). The CDF is:
F(x)=1−e−0.2xF(x)=1−e−0.2x
Questions:
P(X≤3)=F(3)=1−e−0.2×3=1−e−0.6≈1−0.5488=0.4512P(X≤3)=F(3)=1−e−0.2×
3=1−e−0.6≈1−0.5488=0.4512
For a discrete variable, the CDF is a step function. For a continuous variable, it is an S-
shaped curve (for the exponential, it is a rising curve that approaches 1).
import numpy as np
import [Link] as plt
from [Link] import expon
[Link](figsize=(10, 6))
[Link](x, cdf, 'b-', label='CDF: F(x) = 1 - e^{-0.2x}')
[Link]('CDF of Customer Waiting Time')
[Link]('Waiting Time (minutes)')
[Link]('Cumulative Probability F(x)')
[Link](True, alpha=0.3)
[Link]()
[Link]()
This code will plot the CDF of the exponential distribution. The dashed lines show
how to find the cumulative probability for x=3 and x=10.
The Inverse CDF (Percentile Function)
The inverse of the CDF, also called the quantile function or percentile function, is
incredibly useful. For a probability pp, the inverse CDF gives the value xx such
that F(x)=pF(x)=p. This is how we find percentiles.
Example: In the waiting time example, what is the 90th percentile of waiting times?
That is, find xx such that F(x)=0.9F(x)=0.9.
p = 0.9
percentile_90 = [Link](p, scale=5) # scale = 1/lambda = 5
print(f"The 90th percentile is {percentile_90:.2f} minutes.")
Analysis:
The CDF provides a complete picture of the income distribution, allowing the analyst
to make statements like: "The bottom 20% of households have incomes below
$30,000" and "The top 10% have incomes above $150,000".
Common Pitfalls:
Confusing the CDF with the PDF/PMF. Remember: the CDF accumulates probability.
For discrete variables, the CDF is right-continuous, but note that it has jumps.
Practice Questions:
(Answers: 1. P(X>10)=1−F(10)=0.25P(X>10)=1−F(10)=0.25.
2. F(2.5)=P(X≤2.5)=p(1)+p(2)=0.8F(2.5)=P(X≤2.5)=p(1)+p(2)=0.8. 3. True.
4. The PDF is the derivative: f(x)=2xf(x)=2x for 0≤x≤10≤x≤1.)
Topic 6: Binomial Distribution
Introduction: Modeling Success in Fixed Trials
The Binomial Distribution is one of the most fundamental discrete probability
distributions in statistics and data analytics. It models scenarios where we perform a
fixed number of independent experiments, each with the same probability of success,
and count the number of successes.
Real-world examples:
P(X=k)=(nk)pk(1−p)n−kP(X=k)=(kn)pk(1−p)n−k
Where:
Questions:
Analysis:
This is a binomial scenario with:
P(X=50)=(100050)(0.05)50(0.95)950P(X=50)=(501000)(0.05)50(0.95)950
While this calculation is complex manually, we can use Python:
python
from [Link] import binom
n = 1000
p = 0.05
k = 50
prob_exact = [Link](k, n, p)
print(f"P(X = 50) = {prob_exact:.6f}")
P(X≥60)=1−P(X≤59)P(X≥60)=1−P(X≤59)
In Python:
prob_at_least_60 = 1 - [Link](59, n, p)
print(f"P(X ≥ 60) = {prob_at_least_60:.6f}")
Visualization: Understanding Distribution Shape
The shape of the binomial distribution changes based on n and p. Let's visualize
different scenarios:
plt.tight_layout()
[Link]()
In each case, the binomial model helps make data-driven decisions by quantifying
uncertainty.
Analysis:
Using the binomial model with n = 10,000, p = 0.15:
# Normal approximation
mu = n * p
sigma = [Link](n * p * (1-p))
# Using continuity correction: P(X > 1600) ≈ P(Z > (1600.5 - μ)/σ)
z = (1600.5 - mu) / sigma
prob_approx = 1 - [Link](z)
print(f"Normal approximation: {prob_approx:.4f}")
Probability of more than 1600 opens: 0.0026
Normal approximation: 0.0024
np ≥ 10
n(1-p) ≥ 10
P(X≤k)≈P(Z≤k+0.5−npnp(1−p))P(X≤k)≈P(Z≤np(1−p)k+0.5−np)
This approximation simplifies calculations for large n where exact binomial
computation becomes difficult.
Common Pitfalls:
Practice Questions:
1. Events are independent: The occurrence of one event does not affect the
probability of another event
2. Constant average rate: The average rate (events per unit time/space) is constant
3. No simultaneous events: Two events cannot occur at exactly the same instant
Real-world examples:
The Probability Mass Function (PMF) of a Poisson random variable X with parameter
λ (lambda), representing the average rate of events, is:
P(X=k)=e−λλkk!P(X=k)=k!e−λλk
Where:
Mean: E[X]=λE[X]=λ
Variance: Var(X)=λVar(X)=λ
Standard Deviation: σ=λσ=λ
The Poisson distribution can be derived as a limiting case of the Binomial distribution
when:
Scenario: A call center receives an average of 15 calls per hour. The management
wants to understand:
Analysis:
This is a classic Poisson scenario with:
We can use the Poisson PMF and CDF to answer these operational questions.
P(X=20)=e−15⋅152020!P(X=20)=20!e−15⋅1520
Using Python for calculation:
The shape of the Poisson distribution changes based on the value of λ. Let's visualize
different scenarios:
plt.tight_layout()
[Link]()
1. Operations Management:
o Modeling customer arrivals in queues
o Inventory management for perishable goods
o Service capacity planning
2. Quality Control:
o Counting defects in manufacturing processes
o Monitoring rare events in production lines
3. Telecommunications:
o Modeling call arrivals in networks
o Predicting message traffic
4. Healthcare:
o Modeling patient arrivals in emergency rooms
o Counting rare disease occurrences
5. Finance:
o Modeling rare market events
o Counting transactions in high-frequency trading
Business Problem: An e-commerce website averages 500 visitors per hour during
peak times. The infrastructure team needs to:
Analysis:
Using the Poisson model with λ = 500:
lambda_val = 500
This analysis helps the team set appropriate capacity limits and scaling policies.
An important related concept is the exponential distribution, which models the time
between events in a Poisson process. If events follow a Poisson process with rate λ,
then the time between events follows an exponential distribution with parameter λ.
Key relationships:
The Poisson distribution models the number of events in fixed intervals of time or
space
It's characterized by a single parameter λ (the average rate)
Mean and variance are both equal to λ
Arises as a limit of the Binomial distribution for rare events
Widely applicable in operations, quality control, and service industries
Related to the exponential distribution for modeling time between events
Common Pitfalls:
Practice Questions:
How does the distribution of customer spending change when we know their age
group?
What is the probability distribution of website conversion rates for users from
different geographic regions?
How does the failure rate of equipment change based on operating conditions?
P(Y=y∣X=x)=P(X=x,Y=y)P(X=x)P(Y=y∣X=x)=P(X=x)P(X=x,Y=y)
For continuous variables:
f(y∣x)=f(x,y)fX(x)f(y∣x)=fX(x)f(x,y)
Where:
f(x,y)=f(y∣x)⋅fX(x)=f(x∣y)⋅fY(y)f(x,y)=f(y∣x)⋅fX(x)=f(x∣y)⋅fY(y)
Real-World Analytics Example: Customer Segmentation
Analysis:
Let's say the data shows:
Suppose we have data on 1000 customers showing their device type (Mobile or
Desktop) and conversion status (Converted or Not):
This shows desktop users have a 50% higher conversion rate (36% vs 24%),
information that would be masked if we only looked at the overall conversion rate of
30%.
ax.set_xlabel('Device Type')
ax.set_ylabel('Probability')
ax.set_title('Conditional Distribution of Conversion by Device Type')
ax.set_xticks(x)
ax.set_xticklabels(devices)
[Link]()
plt.tight_layout()
[Link]()
This visualization clearly shows how the conversion probability distribution changes
conditional on the device type.
Conditional distributions form the theoretical foundation for many machine learning
algorithms:
In all these applications, we're not just modeling variables in isolation, but how they
relate to each other conditionally.
Analysis:
Instead of using a single overall default probability, the bank develops conditional
default probabilities:
This conditional approach is far superior to using overall average default rates, which
would treat all borrowers as identical.
Common Pitfalls:
Practice Questions:
The Normal Distribution, also known as the Gaussian distribution, is arguably the
most important probability distribution in statistics and data analytics. Its
characteristic bell-shaped curve appears throughout nature, science, and human
phenomena, making it a fundamental tool for understanding and modeling
continuous data.
Central Limit Theorem: The sum of many independent random variables tends
toward a normal distribution, regardless of their original distributions
Natural phenomena: Many biological, physical, and social measurements follow
normal distributions (heights, test scores, measurement errors)
Analytical convenience: Mathematical properties make it tractable for statistical
inference and hypothesis testing
The probability density function (PDF) of the normal distribution with mean μ and
standard deviation σ is:
f(x)=1σ2πe−12(x−μσ)2f(x)=σ2π1e−21(σx−μ)2
Where:
Key properties:
The standard normal distribution is a special case with μ = 0 and σ = 1. Its PDF
simplifies to:
ϕ(z)=12πe−12z2ϕ(z)=2π1e−21z2
Any normal distribution can be transformed to the standard normal distribution
using the z-score transformation:
z=x−μσz=σx−μ
This transformation is crucial because:
The z-score represents how many standard deviations a value is from the mean,
providing a standardized measure of relative position.
Data characteristics:
Business questions:
Analysis:
This is a classic application of the normal distribution where we can use z-scores and
standard normal properties to answer these questions.
Step-by-Step Probability Calculations
Let's calculate the percentage of the population between 168 cm and 182 cm:
1. Convert to z-scores:
z1=168−1757=−1.0z1=7168−175=−1.0z2=182−1757=1.0z2=7182−175=1.0
This reveals that approximately 68% of the population falls within this range, and the
95th percentile height is about 186.5 cm.
The normal distribution's properties are beautifully captured in the empirical rule (68-
95-99.7 rule):
# Create visualization
mu, sigma = 175, 7
x = [Link](mu - 4*sigma, mu + 4*sigma, 1000)
pdf = [Link](x, mu, sigma)
[Link](figsize=(12, 6))
[Link](x, pdf, 'b-', linewidth=2)
[Link]('Normal Distribution of Adult Male Heights')
[Link]('Height (cm)')
[Link]('Probability Density')
[Link]()
[Link](True, alpha=0.3)
[Link]()
This visualization clearly demonstrates the empirical rule and helps understand the
concentration of values around the mean.
1. Hypothesis Testing: Many tests (t-tests, z-tests) assume normality or rely on the
central limit theorem
2. Quality Control: Process capability analysis uses normal distributions to assess
manufacturing processes
3. Risk Management: Value at Risk (VaR) calculations in finance often assume normal
returns
4. Forecasting: Prediction intervals often rely on normal distribution assumptions
5. Machine Learning: Many algorithms assume features are normally distributed or
perform better after normalization
The central limit theorem is particularly important as it justifies the use of normal-
based inference even when the underlying data isn't perfectly normal, provided
sample sizes are sufficiently large.
Related Distributions
1. t-Distribution:
o Similar shape to normal but with heavier tails
o Used when sample sizes are small and population variance is unknown
o Approaches normal distribution as degrees of freedom increase
2. Chi-Square Distribution:
o Distribution of sum of squared standard normal variables
o Used in goodness-of-fit tests and tests of independence
o Right-skewed with shape depending on degrees of freedom
3. F-Distribution:
o Ratio of two chi-square distributed variables
o Used in ANOVA and regression analysis
o Right-skewed with two parameters for degrees of freedom
These distributions form the foundation of many statistical tests and are essential for
advanced analytics.
Analysis:
Using Python:
python
# Find critical values for 99% interval
lower_limit = [Link](0.005, 10, 0.02)
upper_limit = [Link](0.995, 10, 0.02)
The normal distribution is characterized by its bell shape, symmetry, and defined by μ
and σ
The standard normal distribution (μ=0, σ=1) serves as a reference for all normal
distributions
The empirical rule provides quick probability estimates for intervals around the mean
Z-scores allow standardization and comparison across different normal distributions
Related distributions (t, χ², F) extend the utility of the normal distribution to various
statistical applications
Understanding the normal distribution is essential for statistical inference, hypothesis
testing, and many analytical techniques
Common Pitfalls:
Practice Questions:
1. If test scores are N(75, 10²), what percentage of students scored above 90?
2. What z-score corresponds to the 25th percentile?
3. When would you use a t-distribution instead of a normal distribution?
4. How does the chi-square distribution relate to the normal distribution?
Probability Density Functions (PDFs) provide the density of probability per unit and help determine the likelihood of values in a specific interval. In contrast, Cumulative Distribution Functions (CDFs) accumulate the probabilities up to a particular value, thus giving the probability that a random variable is less than or equal to a certain value. CDFs are more efficient in computing probabilities for non-specific intervals, finding percentiles, and assessing probabilities over ranges. PDFs, however, remain essential for understanding distribution characteristics and pinpointing data behavior .
Understanding the properties and applications of a Probability Density Function (PDF) is crucial for data analytics practitioners because it allows for precise modeling of continuous phenomena, informs decisions based on probability estimates, and aids in fitting models to data. This understanding supports critical tasks such as identifying data distribution, assessing risk, predicting future trends, and making evidence-based business strategies. For instance, in risk management and reliability testing, knowing how to manipulate and interpret PDFs enables practitioners to anticipate potential failures and optimize decision-making processes .
For continuous outcomes, the probability of any specific value is zero; thus, probabilities are meaningful only over intervals. The Probability Density Function (PDF) gives the relative likelihood of values rather than the actual probability at each point. Therefore, the area under the PDF over an interval gives the probability that a random variable falls within that interval, demonstrating how the function relates to actual probability .
A Probability Density Function (PDF) differs from a Probability Mass Function (PMF) in that, for continuous random variables (CRVs), probability at an exact point is meaningless (P(X = x) = 0), and probability is instead calculated for intervals by finding the area under the curve of the PDF over that interval. The PDF provides the density of probability at each point, indicating how densely packed probability is near a point, rather than providing the probability at the point itself, which a PMF does for discrete random variables .
The exponential distribution is particularly useful in data analytics for modeling scenarios involving waiting times due to its 'memoryless' property, where the probability of an event occurring in the future is independent of the past. The PDF for the exponential distribution, which decreases exponentially as time increases, captures the idea that high probability is concentrated in the short term. This makes it applicable for modeling time between arrivals in a queue, webpage session durations, or time to failure of machines, where events occur continuously and independently at a constant average rate .
The concept of density in a Probability Density Function (PDF) refers to the relative likelihood of the random variable being near a specific point. High density at a given point indicates that values near this point are more likely to occur. This insight helps in continuous data analysis, as it allows analysts to understand how densely packed the probabilities are around each point, thus providing deeper insights into where most of the observations are likely to occur, which is critical in scenarios like peak traffic periods or optimal pricing .
A valid Probability Density Function (PDF) must satisfy two conditions: 1) Non-Negativity: The function must not return negative values for any input, indicating that the density cannot be negative. 2) Normalization: The total area under the PDF over the entire range of possible values must be equal to 1, representing the certainty that the variable takes on some value within its range .
Considering the support of a Probability Density Function (PDF) is important because it defines the range over which the function is valid and provides meaningful values. Ignoring the support could lead to misinterpretation by assuming functions were applicable outside their valid ranges, potentially resulting in incorrect probability assessments. Understanding where a PDF is defined helps in accurately calculating probabilities and ensures that models reflect realistic constraints of the system being analyzed .
The normalization property of a Probability Density Function (PDF) implies that the total area under the PDF curve must be 1, ensuring that the probability of the random variable taking on any value over the entire range of the variable is 100%. This ensures the model accurately represents a complete probability distribution and maintains the consistency and validity of the probabilistic model .
The shape of a Probability Density Function (PDF) dictates how the probabilities are distributed across different outcomes and influences the interpretation of data by highlighting regions with higher likelihoods. For example, a symmetric bell-shaped PDF like the normal distribution signifies normal variability around a mean, whereas a skewed distribution indicates potential biases or anomalies. Thus, understanding the shape allows interpreting patterns such as likely ranges of outcomes, central tendency, and variability in datasets .