Python program to find the variance

Fluctuation in python: Here, we will figure out how to discover the change of given informational collection utilizing python program?

While managing huge information, what a number of tests do we have to take a gander at before we can have advocated trust in our answer? This relies upon the change of the dataset.

Change enlightens us regarding the uniqueness and the irregularity of the example. So in this python article, we are going to construct a capacity.

Mathematics we characterize it as:

Python program to find the variance

difference in Python

So the accompanying capacity can be utilized while chipping away at a program with enormous information which is exceptionally valuable and help you a ton.

So here is the code:

def variance(X):
    mean = sum(X)/len(X)
    tot = 0.0
    for x in X:
        tot = tot + (x - mean)**2
    return tot/len(X)

# main code
#  a simple data-set 
sample = [1, 2, 3, 4, 5] 
print("variance of the sample is: ", variance(sample))

sample = [1, 2, 3, -4, -5] 
print("variance of the sample is: ", variance(sample))

sample = [10, -20, 30, -40, 50] 
print("variance of the sample is: ", variance(sample))

Output:

ariance of the sample is:  2.0
variance of the sample is:  10.64
variance of the sample is:  1064.0

Leave a Comment

error: Alert: Content is protected!!