Python Implementation of The Central Limit Theorem

We will generate random numbers from -40 to 40 and and collect their mean in a list. we will itratively perform his operation for different count of numbers and we will plot their sampling distribution. 

python3

import numpy
import matplotlib.pyplot as plt
 
# number of sample
num = [1, 10, 50, 100
# list of sample means
means = [] 
 
# Generating 1, 10, 30, 100 random numbers from -40 to 40
# taking their mean and appending it to list means.
for j in num:
    # Generating seed so that we can get same result
    # every time the loop is run...
    numpy.random.seed(1)
    x = [numpy.mean(
        numpy.random.randint(
            -40, 40, j)) for _i in range(1000)]
    means.append(x)
k = 0
 
# plotting all the means in one figure
fig, ax = plt.subplots(2, 2, figsize =(8, 8))
for i in range(0, 2):
    for j in range(0, 2):
        # Histogram for each x stored in means
        ax[i, j].hist(means[k], 10, density = True)
        ax[i, j].set_title(label = num[k])
        k = k + 1
 plt.show()

                    

Output:  

Central limit theoram for getting normal distribution 

It is evident from the graphs that as we keep on increasing the sample size from 1 to 100 the histogram tends to take the shape of a normal distribution.

Python – Central Limit Theorem

Statistics is an important part of Data science projects. We use statical tools whenever we want to make any inference about the population of the dataset from a sample of the dataset, gather information from the dataset, or make any assumption about the parameter of the dataset. In this article, we will talk about one of the important statical tools central limit theorem.

Similar Reads

What is Central Limit Theorem

The definition:...

Python Implementation of The Central Limit Theorem

We will generate random numbers from -40 to 40 and and collect their mean in a list. we will itratively perform his operation for different count of numbers and we will plot their sampling distribution....

Rule of Thumb For Central Limit Theoram

...

Contact Us