There
are different formulas used to calculate mean. Following are some.
- Arithmetic mean
- Weighted mean
- Geometric mean
- Harmonic mean
- Quadratic Mean (Root Mean Square)
- Trimmed mean
Arithmetic mean
It is
also called as average of the numbers. Formula to calculate the mean.
Here,
- μ represents the mean.
- xi represents each individual value in the
dataset.
- n is the total number of values in the
dataset.
For
example, I have the values [1, 2, 3, 4, 5] and mean is calculated like below.
Mean
= (Sum of all values)/(total number of values)
= (1 + 2 + 3 + 4 + 5)/5
= 15 / 5
= 3
You
can go for Arithmetic mean when,
- When the data is evenly distributed around
the mean like a symmetric, bell-shaped normal distribution.
- When the data is not skewed, in a skewed
data, the data points are not evenly distributed, and the curve is
distorted in one direction.
- When the data representing values like
height, weight, or temperature you can go with Arithmetic mean.
Examples of Arithmetic mean
- Calculate the student’s average grades
- Average salaries of employee by their
experience
- Average income per each person in India
- Average satisfaction score of the customers
who use X product.
- Player’s average scores
- Average blood pressure of people by their
age
- Average travel time for an employee to reach
office in peak traffic time
- Average temperatures in Bangalore in May
month
- Average height of group of people
- Average running time of animals by category
- Average student scores in a Mathematical
test
- Average fuel efficiency of cars
- Average price of a house in given locality
Weighted mean
Here
we add certain weights to each data point and then calculate the weighted sum.
Formula
|
value
|
1
|
2
|
3
|
4
|
5
|
|
Weight
|
2
|
4
|
2
|
4
|
2
|
Weighted
mean = ((1*2) + (2*4) + (3*2) + (4*4) + (5*2))/(2+4+2+4+2)
= (2 + 8 + 6 + 16 + 10)/14
= 42/14
= 3
Weighted
mean is useful, when some data points are more significant than others. You can
go with weighted mean when not all the data points are equally important.
For
example,
- While taking the survey on a given product,
you might give more weightage to the loyal customers to your company than
the occasional ones.
- While calculating the average grade of a
student, we can give more weightage to some complex or practical courses
than others.
Geometric mean
It is
the nth root of the product of all values.
Geometric
mean is suitable for the data that follows exponential growth.
Geometric
mean is more appropriate for the multiplicative data. In multiplicate data, values
are multiplied together to predict the current data.
For
example, the growth rate of a company’s stock price is multiplicative.
Following
are some other examples, where you can go for Geometric mean.
- While calculating population growth rate
during certain time periods.
- To calculate average compound interest
earned on an investment.
- To calculate average inflation rate over a
period of time.
Harmonic mean
It is
used for data with reciprocals. It is used in the situations where the average
of rates or speeds is needed.
Harmonic
mean is used when the data is inversely proportional. In inversely proportional
data, when one variable increases other variable decrease and vice versa.
For
example, take the formula ‘xy=k’. In this formula, the variable, when x
increases, y will be decreased to make sure that the product of xy is equal to
k.
xy =
20
When
- x is 2, y is 10
- x is 4, y = is 5
- x is 5, y is 4
Other
real time examples
- Time it takes to travel a fixed distance is
inversely proportional to the speed of travel. When the speed of travel is
more, then we reach the destination in less time.
- The brightness of a light bulb and the
distance from the light bulb. When we are near to the light bulb the
brightness is more, when we are far away from the light bulb, the
brightness is less.
Quadratic Mean (Root Mean Square)
It is
also known as root mean square (RMS) or the quadratic average, and calculated
with below formula.
Trimmed mean
Trimmed
mean is calculated after removing a certain percentage of extreme values from
the dataset.
Trimmed
mean is your buddy, when you want to remove specific percentage of extreme
values (outliers) from the data points. For example,
- While calculating the average income of a
population, we might need to ignore a few very wealthy people, who would
skew the distribution of the data.
- While calculating the average test score of
a class, we might need to ignore a few very low or very high scores who
would skew the distribution of the data.
- While analysing customer feedback ratings or
reviews, you may trim the highest and lowest ratings to focus on opinions
of majority of customers.
-
Find
the below working application.
means_comparison.py
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import gmean
from scipy import stats
# Sample dataset
data = np.array([20, 400, 32, 456, 98, 500, 23, 45, 235])
# Sample weights
weights = np.array([2, 4, 2, 4, 2, 4, 3, 4, 3])
# Calculate the mean
arithmetic_mean = np.mean(data)
# Calculate the weighted mean
weighted_mean = np.average(data, weights=weights)
# Calculate the geometric mean
geometric_mean = gmean(data)
# Calculate the harmonic mean manually
harmonic_mean = len(data) / np.sum(1.0 / data)
# Calculate the quadratic mean manually
quadratic_mean = np.sqrt(np.mean(data ** 2))
# Calculate the trimmed mean by trimming 10% from both ends
trimmed_mean = stats.trim_mean(data, proportiontocut=0.20)
# Create a scatter plot of data points
plt.scatter(data, range(len(data)), label='Data Points', color='blue', marker='o')
# Add a vertical line at the mean
plt.axvline(x=arithmetic_mean, color='red', label='Arithmetic Mean')
plt.axvline(x=weighted_mean, color='magenta', label='Weighted Mean')
plt.axvline(x=geometric_mean, color='yellow', label='Geometric Mean')
plt.axvline(x=harmonic_mean, color='black', label='Harmonic Mean')
plt.axvline(x=quadratic_mean, color='cyan', label='Quadratic Mean')
plt.axvline(x=trimmed_mean, color='blue', label='Trimmed Mean')
# Add labels and a title
plt.xlabel('Actual value')
plt.ylabel('Index')
plt.title('Scatter Plot with Mean')
# Add a legend
plt.legend()
# Show the plot
plt.show()
print(f'arithmetic_mean : {arithmetic_mean}')
print(f'weighted_mean : {weighted_mean}')
print(f'geometric_mean : {geometric_mean}')
print(f'harmonic_mean : {harmonic_mean}')
print(f'quadratic_mean : {quadratic_mean}')
print(f'trimmed_mean : {trimmed_mean}')
Output
arithmetic_mean : 201.0
weighted_mean : 238.5
geometric_mean : 103.7371576736313
harmonic_mean : 53.53864688040538
quadratic_mean : 276.23319456172857
trimmed_mean : 184.14285714285714
Previous
Next
Home