Mean Median Mode in Machine Learning
In Machine Learning (and in mathematics) there are often three values that important
Mean - The standard value
Median - The middle value
Mode - The the most common value
Example: We have registered the roll number of 12 students:
Number= [99, 82 87, 81, 82, 102 87, 94, 78, 71, 85, 82 ]
What is the standard, the middle, or the most common roll number?
Mean
The mean value is the average and standard value.
Calculate the Mean
Find the sum of all values, and divided the sum by the number of values:
(99, 82 87, 81, 82, 102 87, 94, 78, 71, 85, 82 ) /12 =85.833
The NumPy module has a method for this:
Use the NumPy mean() method to find the average number:
import numpy
number = [99, 82 87, 81, 82, 102 87, 94, 78, 71, 85, 82]
x = numpy.mean(number)
print(x)
Calculate the Median
The median value is the value in the middle after you have arranged all the values:
71, 78, 81, 82, 82, 82,85, 87, 87, 94, 99, 102
It is essential that the numbers are arranged before you can find the median.
The NumPy module has a method for this:
Example
Use the NumPy median() method to find the middle value:
import numpy
Number = [99, 82 87, 81, 82, 102 87, 94, 78, 71, 85, 82]
x = numpy.median(Number)
print(x)
If there are two numbers in the middle, divide the sum of those numbers by two.
71, 78, 81, 82, 82, 82, 85, 87, 87, 94, 99, 102
(82 + 85) / 2 = 83.5
Example
Using the NumPy module:
import numpy
number = [99, 82 87, 81, 82, 102 87, 94, 78, 71, 85, 82 ]
x = numpy.median(number)
print(x)
Mode
Calculate the Mode
The Mode value is the value that is mostly present the number of times:
99, 82 87, 81, 82, 102 87, 94, 78, 71, 85, 82 = 82
The SciPy module has a method for this:
Example
Use the SciPy mode() method to find the number that appears the most:
from scipy import stats
number = [99, 82 87, 81, 82, 102 87, 94, 78, 71, 85, 82 ]
x = stats.mode(number)
print(x)