Binomial Distribution: Definition and Examples

# Binomial Distribution: Definition and Examples

Vikram Singh
Assistant Manager - Content
Updated on Dec 9, 2022 08:46 IST

## Introduction:

A probability distribution is a function that gives the relationship between the outcome of a random variable in any random experiment and its probable values.

In this article, we will discuss one of the probability distributions which is commonly used in Data Science, Binomial Distribution.

To know more about Random Variable, read the article Introduction to Probability.

To know about other probability distributions, read the article Probability Distribution used in Data Science.

## Binomial Distribution:

A discrete probability distribution that gives the probability of only two possible outcomes in n independent trails is known as Binomial Distribution.

Example:

• Number of Tails in flipping coin n times.
• The number of times getting 1 on throwing a dice.

## Condition of Binomial Distribution:

• Experiment consist of n identical trials
• Each trial are independent
• Each trial results in one of the two possible outcomes i.e. Success or Failure
• The probability of success remains constant throughout the experiment

## Mathematical Definition:

For any random variable X, the probability distribution function for Binomial Distribution is given by:

Example: Binomial Distribution using Python

1.

```# import library

from scipy.stats import binom # binom: binomial distribution function
import seaborn as sns

# generating sample set of size 1000, having 20 trials, and probability of success = 0.5

sample_set = binom.rvs(n = 20, p = 0.5, size = 1000) # binom.rvs: generate the random number

# plotting the binomial distribution

sns.distplot(sample_set, hist = False)```

2. Binomial distribution at different values of p

```# import library

from scipy.stats import binom # binom: binomial distribution function
import seaborn as sns
import matplotlib.pyplot as plt

# plotting the binomial distribution for sample set of size 1000, having 20 trials, and different probability of success

sns.distplot(binom.rvs(n = 20, p = 0.3, size = 1000), hist = False, label = 'p = 0.3')
sns.distplot(binom.rvs(n = 20, p = 0.5, size = 1000), hist = False,  label = 'p = 0.5')
sns.distplot(binom.rvs(n = 20, p = 0.8, size = 1000), hist = False, label = 'p = 0.8')

plt.legend()
plt.show()```

## Properties of Binomial Distribution:

• Mean = np
• Variance = npq
• When we increase the value of n to infinite, we get the Poisson distribution

To know more about Poisson Distribution, read the article Poisson Distribution: Definition and Example.

## Bernoulli Distribution:

Bernoulli distribution is a special case of Binomial Distribution when the random experiment is done just only one time.

Similar to binomial distribution it has only two possible outcomes:

• Success (1)
• Failure (0)

Note: The sum of the probability of success and failure is equal to 1.

Example:

• India will win the cricket world cup or not
• You will pass the exam or not

### Mathematical definition:

For any random variable n, the probability distribution function for Bernoulli Distribution is given by:

Example:

Consider an experiment of shooting the basketball

## Conclusion:

In this article, we have discussed about one of the most important probability distribution Binomial Distribution, with examples in python.