Practical vision on Standard Deviation and Variance

Deepanshu Dashora
3 min readNov 6, 2020

Hi, Great to see you here, As a data science aspirant we need to understand the statistics. Now the very first topic or very basic from where we start our journey is standard deviation and variance. In this case, I am not judging your mathematical skills and memory to recall the formula so as the title suggests, we will see a very practical approach in order to understand these heavy words.

Note I am assuming here you already know the formulas if you don’t just open another tab and search for formula this will do the job.

So grab your protein shake and stay here with me.

So, without wasting any time let’s cover it together, I will take you with few examples so you will never forget this topic again.

Let’s say you are in a marriage function and just for fun(No intuition here), you made two groups of people one group has men and another one has women, you are interested to measure the length of their hair, So you started now you are having one data which separates male and female and has the length of their hair.

Now what?

It is hard to understand the data and relations right?

So as a good statistician you make a plan, you plot as a basic histogram or better say a simple bar plot which holds the count of people who have the length of hair from one range to another and now it is easy for you to tell isn’t it?

But wait, it is a naive approach right what if you need to understand and explain it in one line, now you are finding a different way,

Hold on !!

The mean of men’s hair length shows the average length and the same for women right so to make it interesting and to explain it in a more technical way you take the help of these two words standard deviation and variance.

The standard deviation tells how far all points lie from the mean or indifferent language how far they are from each other, so-called technical people explain it with a bell-shaped curved called normal distribution but we are disturbing our learning mood with this topic we will learn it later.

The variance is a subset of it or you can say when you square root the variance you get the standard deviation. In better words, we can say the average of the square of a particular point’s value minus expected value(so-called mean of data).

So now we can say the standard deviation of men’s hair length is very low because most of the men keep the length short but in the case of women the hairstyles are different the length is different so we can say they have a high standard deviation compared with men.

Now I hope you got this topic but the wait is it actually over?

What about the programming part?

you can have an apple if you have already finished your protein shake.

There are various methods to do this task we will see two here first one very easy and the second actually something which will help you and me to grow.

The very first method (easy one)

you just need to install one python library and done the name is statistics with pip install statistics.

##with library
import statisticslength_of_hair=[2,3,6,3,9,4,9,2,8,5]print("The standard deviation is ",statistics.stdev(length_of_hair))print("The varience is ",statistics.variance(length_of_hair))

The output is :

The standard deviation is  2.766867462592951
The varience is 7.655555555555556

Now let us see the mathematical approach for what we are learning this

length_of_hair=[2,3,6,3,9,4,9,2,8,5]
s=0
for i in length_of_hair:
s+=i
mean_of_hair=s/len(length_of_hair)
print("The mean of hair lengths is ",mean_of_hair)
print("")
squar_diffrence=[]
for i in length_of_hair:
squar_diffrence.append((i-mean_of_hair)*(i-mean_of_hair))
print("calculating the first step of variance ",squar_diffrence)
print("")
adding_squar_diffrence=0
for i in squar_diffrence:
adding_squar_diffrence+=i
varience=adding_squar_diffrence/(len(length_of_hair)-1)
print("The variance is ",varience)
import math
standard_deviation=math.sqrt(varience)
print("The standard deviation is ",standard_deviation)

The output is:

The mean of hair lengths is  5.1calculating the first step of variance  [9.609999999999998, 4.409999999999998, 0.8100000000000006, 4.409999999999998, 15.210000000000003, 1.2099999999999993, 15.210000000000003, 9.609999999999998, 8.410000000000002, 0.009999999999999929]The variance is  7.655555555555556
The standard deviation is 2.766867462592951

Now as we can see both the outputs are the same

so hurray we did it !!!

Thanks for reading this article and learning with me,

see you soon.

--

--