Open In App

Understanding Types of Mean | Set 2

It is one of the most important concepts of statistics, a crucial subject to learn Machine Learning.

Example – 



Sequence = {1, 3, 9}

product         = 27
n, Total values = 3
Harmonic Mean   = (27)^(1/3)

Code – 




# Geometric Mean
 
import numpy as np
 
# discrete set of numbers
from scipy.stats.mstats import gmean
x = gmean([1, 3, 9])
 
# Mean
print("Geometric Mean is :", x)

Output : 



Geometric Mean is : 3

 Example – 

Sequence = {1, 3, 9}

sum of reciprocals = 1/1 + 1/3 + 1/9
n, Total values    = 3
Harmonic Mean      = 3 / (sum of reciprocals)

Code – 




# Harmonic Mean
 
import numpy as np
 
# discrete set of numbers
from scipy.stats.mstats import hmean
x = hmean([1, 3, 9])
 
# Mean
print("Harmonic Mean is :", x)

Output : 

Harmonic Mean is : 2.076923076923077

Example – 

Sequence = {1, 3, 9}

sum of reciprocals = 1/1 + 1/3 + 1/9
Sum                = 10
Product            = 27
n, Total values    = 3

Arithmetic Mean = 4.33
Geometric Mean  = 3 
Harmonic Mean   = 3 / (sum of reciprocals) = 2.077
Article Tags :