LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.
Python Data Science Binomial Data Distribution
Binomial Distribution is a Discrete Distribution. It describes the outcome of binary
scenarios, e.g. toss of a coin, it will either be head or tails.
It has following three parameters.
1. n - number of trials.
2. p - probability of occurence of each trial (e.g. for toss of a coin 0.5 each).
3. size - The shape of the returned array.
What is Discrete Distribution?
Discrete Distribution is defined at separate set of events, e.g. a
coin toss's result is discrete as it can be only head or tails whereas height of
people is continuous as it can be 170, 170.1, 170.11 and so on.
Example 1: Given 15 trials for coin toss generate 15 data points.
Code
from numpy import random
x = random.binomial(n=15, p=0.5, size=15)
print(x)
the output will be
[ 8 9 7 6 8 5 8 9 10 6 8 7 6 10 6]
Note: The output may differ everytime the code is run as it is generated at random.
Visualization of Binomial Distribution
Example 2: For the example above with 1000 data points.
Code
from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns
sns.distplot(random.binomial(n=10, p=0.5, size=1000), hist=True, kde=False)
plt.show()
the output will be
What is the Difference Between Normal and Binomial Distribution?
Normal distribution is continous whereas Binomial is discrete, but if there are enough
data points it will be quite similar to normal distribution with certain
loc and scale.
Example 3
Code
from numpy import random
import matplotlib.pyplot as plt
import seaborn as sns
sns.distplot(random.normal(loc=50, scale=5, size=10000), hist=False)
sns.distplot(random.binomial(n=100, p=0.5, size=10000), hist=False)
plt.show()
the output will be
In the example above we draw the plot with 10000 data points and can observe from the fig that both the curve
viz Normal distribution and Binomial distribution are displaying alot of similarities.