Understanding the Binomial Distribution
Key Characteristics
Discrete Distribution:
- Binomial Distribution applies to scenarios with distinct outcomes. For example, flipping a coin yields either heads or tails—there's no in-between.
Binary Outcomes:
- Each trial has exactly two outcomes.
Parameters:
- n → Total number of trials (experiments).
- p → Probability of success in each trial (e.g., 0.5 for a fair coin).
- size → The number of random samples to generate.
Program:
Simulating Coin Tosses
Let’s simulate 10 coin tosses, repeated 10 times:
from numpy import random
x = random.binomial(n=10, p=0.5, size=10)
print(x)
This will generate 10 data points representing the number of successful outcomes (e.g., number of heads) in each set of 10 coin tosses.
Output:
Visualizing the Binomial Distribution
Here’s how you can visualize the distribution using Python:
Program:
from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns
sns.displot(random.binomial(n=10, p=0.5, size=1000))
plt.show()
This plot shows how the outcomes are distributed after repeating the experiment 1,000 times.
Difference Between Normal and Binomial Distribution
The primary difference between the normal and binomial distributions lies in their nature:
Normal distribution is continuous.
Binomial distribution is discrete.
However, with a large enough number of trials, the binomial distribution tends to approximate the normal distribution, given appropriate values for the mean (loc) and standard deviation (scale).
Program:
from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns
# Generate data for normal and binomial distributions
data = {
"Normal": random.normal(loc=50, scale=5, size=1000),
"Binomial": random.binomial(n=100, p=0.5, size=1000)
}
# Plot the distributions
sns.displot(data, kind="kde")
plt.show()
This example demonstrates how a binomial distribution can resemble a normal distribution when the sample size is large.