LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.
Python Data Science Machine Learning Lesson 1: Mean Median Mode
Mean Median and Mode are measures of central tendencies.
What is Mean? How to Find/Calculate Mean?
Mean is most commonly used measure of central tendency. It actually
represents the average of the given collection of data. It is applicable for both
continuous and discrete data.
In order to calculate mean in python programming you have a method available with one of the Python module known as numpy you can make use of it in the following manner. First import numpy as under
import numpy as np
For example you have following list of which you have to find the mean.
[5,8,9,4,6]
Now let the available list be declared as a variable A.
The code for calculating mean is given below.
code:
import numpy as np
A=[5,8,9,4,6]
print(np.mean(A))
Output will be
6.4
What is Median?
Median represents the mid-value of the given set of data when arranged in a particular order.
In order to calculate median in python programming you have a method available with one of the Python module known as numpy you can make use of it in the following manner.
First import numpy as under
import numpy as np
For example you have following list of which you have to find the median.
[5,9,4,6,8,3,2,1]
Now let the available list be declared as a variable A.
The code for calculating median is given below.
code:
import numpy as np
A=[5,9,4,6,8,3,2,1]
print(np.median(A))
Output will be
4.5
What is Mode?
Mode is the most frequently occurring element or number in the data set.
In order to calculate mode in python programming you have a method available with one of the Python module known as scipy you can make use of it in the following manner.
First import scipy as under
from scipy import stats
For example you have following list of which you have to find the mode.
[11,15,18,21,23,31,35,38,39,41,
44,45,47,41,51,55,57,59,60,65]
Now let the available list be declared as a variable A.
The code for calculating median is given below.
code:
from scipy import stats
A=[11,15,18,21,23,31,35,38,39,41,
44,45,47,41,51,55,57,59,60,65]
print(stats.mode(A))
Output will be
ModeResult(mode=array([41]), count=array([2]))
Explanation: the output above states that the mode is 41 and number of time it occured is 2.
Note: if you have python installed on your pc you can install numpy as under.
Open Command Prompt from the start menu.
Inside the command prompt, type
pip install numpy
press enter
This command will install numpy on your computer after which you can run on python.