Open In App

Understanding Types of Means | Set 1

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



Sequence = {1, 5, 6, 4, 4}

Sum             = 20
n, Total values = 5
Arithmetic Mean = 20/5 = 4




# Arithmetic Mean
 
import statistics
 
# discrete set of numbers
data1 = [1, 5, 6, 4, 4]
 
x = statistics.mean(data1)
 
# Mean
print("Mean is :", x)

Mean is : 4

Sequence = {0, 2, 1, 3}
p        = 0.25

Remaining Sequence  = {2, 1}
n, Total values = 2
Mean = 3/2 = 1.5




# Trimmed Mean
 
from scipy import stats
 
# discrete set of numbers
data = [0, 2, 1, 3]
 
x = stats.trim_mean(data, 0.25)
 
# Mean
print("Trimmed Mean is :", x)

Trimmed Mean is : 1.5



Sequence = [0, 2, 1, 3]
Weight   = [1, 0, 1, 1]

Sum (Weight * sequence)  = 0*1 + 2*0 + 1*1 + 3*1
Sum (Weight) = 3
Weighted Mean = 4 / 3 = 1.3333333333333333




# Weighted Mean
 
import numpy as np
 
# discrete set of numbers
data = [0, 2, 1, 3]
 
x = np.average(data, weights =[1, 0, 1, 1])
 
# Mean
print("Weighted Mean is :", x)

Weighted Mean is : 1.3333333333333333




# Weighted Mean
 
data = [0, 2, 1, 3]
weights = [1, 0, 1, 1]
 
x = sum(data[i] * weights[i]
    for i in range(len(data))) / sum(weights)
 
 
print ("Weighted Mean is :", x)

Weighted Mean is : 1.3333333333333333

Article Tags :