Let’s look at a problem in probability theory related to binomial distributions, which are used to model the probability of a certain number of successes in a series of independent trials.
Problem: Binomial Probability of Flipping a Coin
Suppose you flip a fair coin ($50$% chance of heads and $50$% chance of tails) $20$ times.
We want to know:
- The probability of getting exactly $(k)$ heads for various values of $(k)$ ($0$ to $20$).
- How the probabilities are distributed across different numbers of heads.
Solution Outline
We’ll use the binomial distribution. The probability of getting exactly $(k)$ heads in $(n)$ flips is given by:
$$
P(X = k) = \binom{n}{k} p^k (1 - p)^{n - k}
$$- $(n)$ = number of trials ($20$),
- $(p)$ = probability of success in a single trial ($0.5$ for heads),
- $(k)$ = number of successes (number of heads).
We’ll calculate the probabilities for each value of $(k)$ from $0$ to $20$ and visualize the distribution of these probabilities.
Python Code
Here’s the $Python$ code to calculate and plot the binomial distribution for this problem:
1 | import numpy as np |
Explanation of the Code
- Binomial Probability Calculation:
- We use
binom.pmf(k, n, p)fromscipy.statsto calculate the probability mass function (PMF) of a binomial distribution, which gives the probability of getting exactly $( k )$ heads in $( n )$ trials with probability $( p )$ of heads.
- We use
- Plotting:
- We plot the probabilities for each possible value of $( k )$ (from $0$ to $20$ heads).
- A bar plot is used to visualize how probabilities are distributed across different numbers of heads.
Visualization

The bar chart shows:
- The probability of each possible outcome (number of heads) when flipping a coin $20$ times.
- The distribution is centered around $10$ heads, since we expect about half of the flips to result in heads due to the $50$% probability of success per flip.
Interpretation
- Peak at 10 Heads:
The distribution peaks at $10$, which is the expected number of heads when flipping a coin $20$ times with a $50$% chance for heads each time. - Symmetry:
The binomial distribution here is symmetric around $10$ due to the equal probability of heads and tails. - Applications:
Binomial distributions model scenarios with a fixed number of independent trials and a constant probability of success in each trial, such as quality control testing, marketing response rates, and predicting outcomes in sports or games of chance.







