D Dev Duniya
Back to Journal
2 min read

Understanding Mean, Median, and Mode in Machine Learning | DevDuniya

Ashish Yadav

Ashish Yadav

Published on Dev Duniya
Keep exploring
Compare the details before you buy.

In machine learning, understanding central tendencies is fundamental. These statistical measures provide crucial insights into the distribution of data and help in various aspects of model building and analysis. Let's explore three key measures: Mean, Median, and Mode.

Mean

The mean, often referred to as the average, is calculated by summing all values in a dataset and then dividing the sum by the total number of values.

Formula:

Mean = (Sum of all values) / (Number of values)

Example:

import numpy as np

num_list = [54, 3, 12, 65, 34, 23, 16, 9, 3, 8, 12, 3]
mean = np.mean(num_list) 
print("Mean =", mean) 

Output:

Mean = 20.166666666666668

Use Cases of Mean:

  • Widely used in various statistical and machine learning calculations.
  • Useful for understanding the average value of a dataset.
  • Sensitive to outliers, as a single extreme value can significantly influence the mean.

Median

The median is the middle value in a dataset when the data is arranged in ascending or descending order. If the dataset has an even number of values, the median is the average of the two middle values.

Example:

import numpy as np

num_list = [54, 3, 12, 65, 34, 23, 16, 9, 3, 8, 12, 3]
median = np.median(num_list)
print("Median =", median)

Output:

Median = 12.0

Use Cases of Median:

  • Less sensitive to outliers compared to the mean.
  • Provides a more robust measure of central tendency when dealing with skewed distributions or datasets with extreme values.

Mode

The mode is the value that appears most frequently in a dataset. A dataset can have multiple modes (multimodal) or no mode if all values occur with equal frequency.

Example:

from scipy import stats

num_list = [54, 3, 12, 65, 34, 23, 16, 9, 3, 8, 12, 3]
mode = stats.mode(num_list) 
print("Mode =", mode)

Output:

Mode = ModeResult(mode=array([3]), count=array([3])) 

Use Cases of Mode:

  • Identifying the most common value or category in a dataset.
  • Useful in categorical data analysis and understanding the most frequent occurrences.

Choosing the Right Measure

The choice of which central tendency measure to use depends on the characteristics of the dataset and the specific goals of the analysis.

  • Mean: Suitable for symmetric distributions without significant outliers.
  • Median: More robust for skewed distributions or datasets with outliers.
  • Mode: Useful for identifying the most frequent values or categories.

By understanding these key measures and their appropriate use cases, you can gain valuable insights into your data and make more informed decisions in your machine learning projects.

Keep reading

12 latest articles

The newest stories from Dev Duniya, excluding the article you are reading.

All articles →

From the product catalog

Explore device specifications

Specification cards update automatically from published catalog products, grouped by brand.

Apple specifications

Explore Apple devices →
Apple Apple iPhone Duo
Apple Apple iPhone Duo specifications

Apple iPhone Duo is a new-generation iPhone model focused on a sleek design, powerful performance, and everyday usability. Explore iPhone Duo specifications, features, display, cameras, battery, and expected price in the USA. Get the latest information about Apple iPhone Duo and its key features. Compare iPhone Duo with other popular Apple iPhone models.

Size (inches)
Open: 4.64 x 6.48 x 0.21 Closed: 4.64 x 3.31 x 0.44
Weight (ounces)
8.96
Display size (inches)
Inner: 7.6-inch (diagonal) all-screen OLED folding display Outer: 5.4-inch (diagonal) all-screen OLED display
Resolution (pixels)
Inner: 1878-by-2670-pixel resolution at 430 ppi Outer: 1398-by-2034-pixel resolution at 460 ppi
See all specifications →
Apple Apple iPhone 18 Pro Max
Apple Apple iPhone 18 Pro Max specifications

Apple iPhone 18 Pro Max is a high-end flagship smartphone designed for powerful performance and advanced photography. Explore iPhone 18 Pro Max specifications, features, display, cameras, battery, and expected price in the USA. Discover the latest upgrades and key features of Apple’s largest Pro iPhone. Compare iPhone 18 Pro Max with other premium flagship smartphones.

Size (inches)
6.43 x 3.07 x 0.34
Weight (ounces)
8.78
Display size (inches)
6.9-inch (diagonal) all-screen OLED display
Resolution (pixels)
2868-by-1320-pixel resolution at 460 ppi
See all specifications →
Apple Apple iPhone 18 Pro
Apple Apple iPhone 18 Pro specifications

Apple iPhone 18 Pro is a premium flagship smartphone with advanced performance and an upgraded camera system. Explore iPhone 18 Pro specifications, features, display, cameras, battery, and expected price in the USA. Get the latest details about Apple’s new Pro model and its key upgrades. Compare iPhone 18 Pro features with other flagship smartphones.

Size (inches)
5.91 x 2.83 x 0.34
Weight (ounces)
7.44
Display size (inches)
6.3-inch (diagonal) all-screen OLED display
Resolution (pixels)
2622-by-1206-pixel resolution at 460 ppi
See all specifications →

Google specifications

Explore Google devices →

Samsung specifications

Explore Samsung devices →