0% found this document useful (0 votes)
19 views8 pages

Data Science-3-Central Tendency

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views8 pages

Data Science-3-Central Tendency

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Introduction to Measures

of Central Tendency

Measures of central tendency are statistical values that represent the central or
typical value in a dataset. Understanding these measures is crucial for data
analysis and decision-making.

by Alekya G
Mean: Definition and Python
Implementation
The mean is the arithmetic average of a set of numbers. It is calculated by summing all the values and
dividing by the total number of values. Here's how to calculate the mean in Python:

Python Code Output

import numpy as np The mean is: 15.0


data = [5, 10, 15, 20, 25]
mean = np.mean(data)
print(f"The mean is: {mean}")
Median: Definition and Python
Implementation
The median is the middle value in a sorted list of numbers. It is the value that separates the higher half from
the lower half of the dataset. Here's how to calculate the median in Python:

Python Code Output

import numpy as np The median is: 15.0


data = [5, 10, 15, 20, 25]
median = np.median(data)
print(f"The median is: {median}")
Mode: Definition and Python
Implementation
The mode is the value that appears most frequently in a dataset. It is the value with the highest frequency.
Here's how to calculate the mode in Python:

Python Code Output

import statistics The mode is: 20


data = [5, 10, 15, 20, 20, 25]
mode = statistics.mode(data)
print(f"The mode is: {mode}")
Weighted Mean: Definition and Python
Implementation
The weighted mean is a type of average where certain values are given more importance or "weight" than
others. It is calculated by multiplying each value by its weight, summing the products, and dividing by the
sum of the weights. Here's how to calculate the weighted mean in Python:

Python Code Output

import numpy as np The weighted mean is: 13.333333333333334


values = [5, 10, 15, 20, 25]
weights = [1, 2, 1, 2, 1]
weighted_mean =
np.average(values,
weights=weights)
print(f"The weighted mean is:
{weighted_mean}")
Geometric Mean: Definition and Python
Implementation
The geometric mean is a type of mean that is calculated by multiplying all the values in a dataset and then
taking the nth root, where n is the number of values. It is useful for data that has a wide range of values or is
skewed. Here's how to calculate the geometric mean in Python:

Python Code Output

import numpy as np The geometric mean is: 12.99


data = [5, 10, 15, 20, 25]
geometric_mean =
np.exp(np.mean(np.log(data)))
print(f"The geometric mean is:
{geometric_mean:.2f}")
Harmonic Mean: Definition and Python
Implementation
The harmonic mean is a type of mean that is the reciprocal of the arithmetic mean of the reciprocals of the
values. It is useful for averaging rates or ratios. Here's how to calculate the harmonic mean in Python:

Python Code Output

import numpy as np The harmonic mean is: 10.00


data = [5, 10, 15, 20, 25]
harmonic_mean = len(data) /
np.sum(1 / np.array(data))
print(f"The harmonic mean is:
{harmonic_mean:.2f}")
Comparison and Use Cases of
Central Tendency Measures

The different measures of central tendency each have their own strengths and
use cases. The mean is useful for general data analysis, the median is robust to
outliers, the mode identifies the most common value, the weighted mean
accounts for importance, the geometric mean is good for skewed data, and the
harmonic mean is useful for averaging rates. Understanding when to use each
measure is crucial for effective data-driven decision making.

You might also like