Table of Contents

    Mean, Median, Mode

    Statistics Fundamentals

    Mean, Median, Mode

    Learn the three most important measures of central tendency used in statistics, data analysis, and Machine Learning.

    Introduction

    In statistics and Machine Learning, we often work with large datasets. A dataset may contain hundreds, thousands, or even millions of values. To understand such data quickly, we need a single representative value that can describe the center or typical behavior of the data.

    Mean, Median, and Mode are three important statistical measures used to describe the central tendency of a dataset. Central tendency means the central or typical value around which most data values are located.

    Simple Meaning: Mean, Median, and Mode help us answer one important question: “What is the typical value in this dataset?”

    Prerequisites

    Before learning Mean, Median, and Mode, students should have basic understanding of the following topics:

    Required Knowledge

    • Basic Arithmetic: Addition, division, comparison, and ordering of numbers.
    • Data Values: Understanding how numbers are stored in a dataset.
    • Sorting: Arranging numbers in ascending or descending order.
    • Frequency: Counting how many times a value appears.
    • Basic Statistics: Idea of dataset, observation, and central tendency.

    What is Central Tendency?

    Central tendency is a statistical concept that describes the center point or representative value of a dataset. It helps summarize an entire dataset using one meaningful value.

    For example, if we have marks of 50 students, instead of looking at all 50 marks separately, we can calculate the mean, median, or mode to understand the general performance of the class.

    Central Tendency
    Central Tendency = A single value that represents the center of a dataset

    Classroom Example

    If a teacher wants to understand the overall performance of a class, the teacher may calculate the average marks, middle marks, or most common marks. These are examples of mean, median, and mode.

    Quick Overview

    Measure Simple Meaning Best Use
    Mean Average value When data is balanced and has no extreme outliers
    Median Middle value When data contains outliers or is skewed
    Mode Most frequent value When we want to find the most common value or category

    1. Mean

    Mean is the arithmetic average of all values in a dataset. It is calculated by adding all values and dividing the sum by the total number of values.

    Definition
    Mean is the sum of all observations divided by the number of observations.
    MEAN FORMULA
    \( \bar{x} = \frac{x_1 + x_2 + x_3 + ... + x_n}{n} \)

    Here:
    \( \bar{x} \) = Mean
    \( x_1, x_2, x_3, ... x_n \) = Data values
    \( n \) = Total number of values

    Example of Mean

    Suppose the marks of five students are:

    
    80, 70, 90, 60, 100
    

    To find the mean:

    STEP-BY-STEP CALCULATION
    \( Mean = \frac{80 + 70 + 90 + 60 + 100}{5} \)
    \( Mean = \frac{400}{5} = 80 \)

    So, the mean marks are 80.

    When to Use Mean Use mean when the data is numerical, balanced, and does not contain very large or very small extreme values.
    Limitation of Mean Mean is affected by outliers. A very large or very small value can pull the mean away from the typical value.

    Mean and Outlier Problem

    Consider the following salary data:

    
    30000, 32000, 35000, 38000, 1000000
    

    Here, 1000000 is an extreme value. If we calculate the mean, it becomes very high and may not represent the typical salary correctly.

    In such cases, median is usually more useful than mean.

    2. Median

    Median is the middle value of a dataset when the values are arranged in ascending or descending order. It divides the dataset into two equal halves.

    Definition
    Median is the middle value of a sorted dataset.
    MEDIAN RULE
    If \( n \) is odd: Median = Middle value
    If \( n \) is even: Median = Average of two middle values

    Steps to Find Median

    Median Calculation Steps

    • Arrange the data in ascending order.
    • Count the total number of values.
    • If the count is odd, select the middle value.
    • If the count is even, take the average of the two middle values.

    Example 1: Median for Odd Number of Values

    Dataset:

    
    30, 10, 50, 20, 40
    

    First, arrange in ascending order:

    
    10, 20, 30, 40, 50
    

    There are 5 values, so the middle value is:

    MEDIAN
    Median = 30

    Example 2: Median for Even Number of Values

    Dataset:

    
    10, 20, 30, 40
    

    There are 4 values, so there are two middle values: 20 and 30.

    MEDIAN
    \( Median = \frac{20 + 30}{2} = 25 \)

    So, the median is 25.

    When to Use Median Use median when the data contains outliers or is skewed. Median gives a better idea of the typical value in such cases.
    Limitation of Median Median does not use every value in the calculation. It only focuses on the middle position after sorting.

    3. Mode

    Mode is the value that appears most frequently in a dataset. It is useful when we want to identify the most common value or most popular category.

    Definition
    Mode is the value that occurs most often in a dataset.

    Example of Mode

    Dataset:

    
    2, 3, 3, 5, 6, 3, 8
    

    Here, 3 appears three times, more than any other value.

    MODE
    Mode = 3

    Types of Mode

    A dataset can have one mode, more than one mode, or no mode depending on frequency.

    Type Meaning Example
    Unimodal Dataset has one mode 2, 3, 3, 4, 5 → Mode = 3
    Bimodal Dataset has two modes 2, 2, 3, 4, 4 → Modes = 2 and 4
    Multimodal Dataset has more than two modes 1, 1, 2, 2, 3, 3 → Modes = 1, 2, 3
    No Mode No value repeats 1, 2, 3, 4, 5 → No mode
    When to Use Mode Use mode when you want to find the most common value or category, especially in categorical data.
    Limitation of Mode Some datasets may have no mode or multiple modes, so mode may not always give a clear central value.

    Mean vs Median vs Mode

    Mean, median, and mode all describe the center of data, but they work differently. Choosing the correct measure depends on the type and shape of the data.

    Basis Mean Median Mode
    Meaning Average value Middle value Most frequent value
    Calculation Sum of values divided by count Sort data and find middle Count frequency of values
    Affected by Outliers? Yes No, mostly resistant Usually not strongly affected
    Best For Balanced numerical data Skewed data or data with outliers Categorical or repeated data
    Example Use Average marks Typical salary Most popular product

    When Should We Use Mean, Median, or Mode?

    Use Mean When

    • Data is numerical
    • Data is fairly balanced
    • There are no extreme outliers
    • You want the arithmetic average

    Use Median When

    • Data has outliers
    • Data is skewed
    • You want the middle value
    • You are analyzing income, salary, or property price

    Use Mode When

    • You need the most common value
    • Data is categorical
    • You are analyzing customer choices
    • You want to find popularity or frequency

    Mean, Median, Mode and Data Distribution

    The relationship between mean, median, and mode can also help us understand the shape of data distribution.

    Distribution Type Relationship Meaning
    Normal Distribution Mean = Median = Mode Data is symmetric and balanced
    Positive Skew Mode < Median < Mean Long tail is on the right side
    Negative Skew Mean < Median < Mode Long tail is on the left side
    Machine Learning Tip: If mean and median are very different, the dataset may be skewed or may contain outliers.

    Importance in Machine Learning

    Mean, median, and mode are not only mathematical concepts. They are used practically in Machine Learning projects during data exploration, data cleaning, feature engineering, and preprocessing.

    Uses in Machine Learning

    • Data Understanding: Helps summarize dataset behavior.
    • Missing Value Handling: Mean, median, or mode can be used to fill missing values.
    • Outlier Detection: Difference between mean and median can indicate outliers.
    • Feature Engineering: Helps create meaningful summary features.
    • Data Distribution Analysis: Helps understand whether data is balanced or skewed.
    • Categorical Data Analysis: Mode helps identify the most frequent category.

    Real-World Examples

    Student Marks

    • Mean shows average class performance
    • Median shows middle student performance
    • Mode shows most common marks

    Salary Analysis

    • Mean may be affected by very high salaries
    • Median gives typical salary more accurately
    • Mode shows most common salary range

    E-Commerce

    • Mean order value shows average spending
    • Median order value shows typical spending
    • Mode shows most purchased product category

    House Prices

    • Mean can be affected by luxury houses
    • Median is often better for typical house price
    • Mode can show most common price range

    Python Example

    The following example shows how to calculate mean, median, and mode using Python.

    
    import pandas as pd
    
    # Sample marks dataset
    marks = [80, 70, 90, 60, 100, 70, 85]
    
    # Convert list into pandas Series
    data = pd.Series(marks)
    
    # Calculate mean, median, and mode
    mean_value = data.mean()
    median_value = data.median()
    mode_value = data.mode()[0]
    
    print("Mean:", mean_value)
    print("Median:", median_value)
    print("Mode:", mode_value)
    

    Output

    
    Mean: 79.28571428571429
    Median: 80.0
    Mode: 70
    

    In this example:
    Mean gives the average marks.
    Median gives the middle marks after sorting.
    Mode gives the most repeated marks.

    NumPy and SciPy Example

    In Machine Learning, NumPy and SciPy are commonly used for numerical calculations.

    
    import numpy as np
    from scipy import stats
    
    speed = [99, 86, 87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86]
    
    mean_speed = np.mean(speed)
    median_speed = np.median(speed)
    mode_speed = stats.mode(speed, keepdims=True)
    
    print("Mean Speed:", mean_speed)
    print("Median Speed:", median_speed)
    print("Mode Speed:", mode_speed.mode[0])
    

    Complete Hand Calculation Example

    Let us calculate mean, median, and mode for the following dataset:

    
    10, 20, 20, 30, 40
    

    Mean

    MEAN
    \( Mean = \frac{10 + 20 + 20 + 30 + 40}{5} = \frac{120}{5} = 24 \)

    Median

    Data is already sorted:

    
    10, 20, 20, 30, 40
    
    MEDIAN
    Middle value = 20

    Mode

    The value 20 appears two times, more than any other value.

    MODE
    Mode = 20

    Advantages

    Benefits of Mean, Median, and Mode

    • They summarize large datasets using simple values.
    • They help understand the central behavior of data.
    • They are easy to calculate and interpret.
    • They are useful in data analysis and Machine Learning preprocessing.
    • They help compare different datasets.
    • They support decision-making in business, education, healthcare, and finance.

    Limitations

    Important Limitations

    • Mean can be misleading when outliers are present.
    • Median does not consider every value directly.
    • Mode may not exist if no value repeats.
    • Mode may have multiple values in multimodal datasets.
    • Central tendency alone does not explain data spread.
    • Two datasets may have the same mean but different variability.

    Common Mistakes Students Make

    Avoid These Mistakes

    • Forgetting to sort data before finding median.
    • Using mean blindly when outliers are present.
    • Thinking mode always exists in every dataset.
    • Confusing median with mean.
    • Ignoring multiple modes in a dataset.
    • Using mode for continuous data without grouping.
    • Assuming central tendency explains the complete dataset.

    Quick Revision

    Concept Meaning Formula / Rule
    Mean Average value \( \bar{x} = \frac{\sum x_i}{n} \)
    Median Middle value Sort data and find the middle
    Mode Most frequent value Value with highest frequency
    Best for Outliers Median Not strongly affected by extreme values
    Best for Categories Mode Find most frequent category

    Interview Questions

    1

    What is mean?

    Mean is the average value of a dataset. It is calculated by adding all values and dividing by the number of values.

    2

    What is median?

    Median is the middle value of a dataset after arranging the values in order. If the number of values is even, the median is the average of the two middle values.

    3

    What is mode?

    Mode is the value that appears most frequently in a dataset.

    4

    Which measure is affected most by outliers?

    Mean is affected most by outliers because it uses every value in the calculation.

    5

    Which measure is best for skewed data?

    Median is usually better for skewed data because it is more resistant to extreme values.

    6

    Can a dataset have more than one mode?

    Yes. A dataset can have more than one mode. If it has two modes, it is called bimodal. If it has more than two modes, it is called multimodal.

    Conclusion

    Mean, Median, and Mode are the three most important measures of central tendency. They help summarize data and identify the typical or central value of a dataset. Mean gives the average, median gives the middle value, and mode gives the most frequent value.

    In Machine Learning, these concepts are useful for data understanding, missing value treatment, outlier analysis, feature engineering, and exploratory data analysis. A good data analyst or Machine Learning learner should know not only how to calculate them, but also when to use each one correctly.

    Final Takeaway

    Mean tells the average, Median tells the middle, and Mode tells the most common value. Together, they help us understand the center of data in a simple and powerful way.