Foundations of Data Science 📂 Descriptive Statistics · 1 of 11 122 min read

Mean-Median-Mode

Mean, Median, and Mode are the three core measures of central tendency that every Data Scientist must master before diving into advanced analytics. The Mean gives the mathematical average but breaks down in the presence of outliers, while the Median offers a robust alternative for skewed data like salaries and house prices. The Mode identifies the most frequent value and stands as the only valid measure for categorical data such as colours, brands, or survey responses. Understanding how

🌐
SectionSection第 01 节

Overview — What Are Measures of Central Tendency?Overview — Measures of Central Tendency क्या हैं?概览 — 什么是集中趋势的度量?

In statistics, a measure of central tendency is one value that summarises a dataset by showing where its centre lies. The three most common measures are:

Statistics में measure of central tendency एक ऐसी value है जो बताती है कि dataset का केंद्र कहाँ है, और पूरे data का सार देती है। तीन सबसे आम measures ये हैं:

在统计学中,集中趋势的度量是用一个值来概括数据集,指出数据的中心在哪里。最常用的三种度量是:

MeanMean均值(Mean)
x̄ / μ
  • Sum ÷ Countजोड़ ÷ गिनती总和 ÷ 个数
  • Pulled by outliersOutliers से खिंचता है会被离群点拉偏
  • Best for symmetric dataSymmetric data के लिए सबसे अच्छा最适合对称数据
MedianMedian中位数(Median)
M
  • Middle value (sorted)बीच की value (sort के बाद)排序后的中间值
  • Resists outliersOutliers का असर कम抗离群点
  • Best for skewed dataSkewed data के लिए सबसे अच्छा最适合偏斜数据
ModeMode众数(Mode)
Mo
  • Most frequent valueसबसे ज़्यादा बार आने वाली value出现最多的值
  • Works on categoriesCategories पर भी चलता है适用于类别数据
  • Can be 0, 1 or many values0, 1 या कई values हो सकती हैं可以有 0 个、1 个或多个
🖼️ UNDERSTAND IT BEFORE THE MATHS — THREE PICTURESगणित से पहले समझें — तीन तस्वीरें先看懂,再学公式 — 三幅图
Mean, median and mode in pictures MEAN = the balance pointMEAN = संतुलन का बिंदु均值 = 平衡点 3 One heavy kid far out can tip it:दूर बैठा एक भारी बच्चा झुका देता है:远处一个重孩子就能让它倾斜: the mean moves toward outliers.mean outliers की ओर खिसकता है।均值会向离群点移动。 MEDIAN = the middle personMEDIAN = बीच वाला व्यक्ति中位数 = 站在正中间的人 #4 of 7 Line up by height, pick the middle.ऊँचाई के क्रम में खड़ा करें, बीच वाला चुनें।按身高排队,选正中间的那个人。 A giant at the end changes nothing.आख़िर में खड़ा एक लंबा आदमी कुछ नहीं बदलता।队尾来个巨人,结果也不变。 MODE = the most votesMODE = सबसे ज़्यादा votes众数 = 得票最多 🍕 🍔 👑 🍜 🥗 Count each answer, take the winner.हर जवाब गिनें, जीतने वाला चुनें।数一数每个选项,选票数最多的。 Works even for food, colours, brands.खाना, रंग, brands पर भी चलता है।连食物、颜色、品牌都适用。
📌
Why This Mattersयह क्यों ज़रूरी है为什么这很重要

Choosing the wrong measure can completely mislead your analysis. Reporting the average income of a country with large inequality gives a false picture — the median is far more honest.

ग़लत measure चुनने से आपका पूरा analysis गुमराह हो सकता है। बहुत असमानता वाले देश की average income बताना झूठी तस्वीर देता है — median कहीं ज़्यादा ईमानदार है।

选错度量会彻底误导你的分析。在贫富差距很大的国家报告平均收入,会给出虚假的印象 —— 中位数要诚实得多。


SectionSection第 02 节

The Mean (Arithmetic Average)Mean (Arithmetic Average)均值(算术平均数)

The mean is found by adding all values and dividing by how many there are. It uses every single value in the dataset — which makes it powerful, but also easy to pull by extreme values (outliers).

Mean निकालने के लिए सभी values जोड़कर उनकी गिनती से भाग देते हैं। यह dataset की हर एक value इस्तेमाल करता है — इसलिए ताक़तवर है, पर extreme values (outliers) इसे आसानी से खींच लेते हैं।

均值就是把所有值相加,再除以个数。它用到了数据集中的每一个值 —— 这让它很有力,但也很容易被极端值(离群点)拉偏。

FormulaFormula公式

Population MeanPopulation Mean总体均值
μ = (Σ xᵢ) / N
Σ xᵢ = sum of all population values
N = population size
Σ xᵢ = population की सभी values का जोड़
N = population size
Σ xᵢ = 总体所有值之和
N = 总体大小
Sample MeanSample Mean样本均值
x̄ = (Σ xᵢ) / n
Σ xᵢ = sum of the sample values
n = sample size (a subset of the data)
Σ xᵢ = sample values का जोड़
n = sample size (data का एक हिस्सा)
Σ xᵢ = 样本值之和
n = 样本大小(数据的一个子集)
LIVELIVE互动The Mean Is the Balance Point — Balance the SeesawMean संतुलन का बिंदु है — Seesaw को संतुलित करें均值就是平衡点 — 让跷跷板平衡

Click on the beam to add a point, click a point to remove it, and drag the triangle (fulcrum). The beam only balances when the fulcrum is exactly at the mean, because then Σ(x − mean) = 0.

Point जोड़ने के लिए beam पर click करें, हटाने के लिए point पर click करें, और त्रिकोण (fulcrum) को खींचें। Beam तभी संतुलित होता है जब fulcrum ठीक mean पर हो, क्योंकि तब Σ(x − mean) = 0.

点击横梁添加一个点,点击某个点删除它,拖动三角形(支点)。只有支点正好在均值处时横梁才平衡,因为此时 Σ(x − 均值) = 0。

Real Example — Employee Salariesअसली उदाहरण — कर्मचारियों की Salaries真实例子 — 员工工资

A small company has 10 employees with these monthly salaries (₹):

एक छोटी company में 10 कर्मचारी हैं, जिनकी monthly salaries (₹) ये हैं:

一家小公司有 10 名员工,月薪(₹)如下:

Emp #Emp #员工编号12345678910
Salary (₹)Salary (₹)工资(₹)32,00035,00037,00038,00040,00042,00045,00047,00050,00054,000
🧮 Step-by-Step CalculationStep-by-Step गणना分步计算
Step 1
Add all salaries:
32,000 + 35,000 + 37,000 + 38,000 + 40,000 + 42,000 + 45,000 + 47,000 + 50,000 + 54,000 = ₹4,20,000
सभी salaries जोड़ें:
32,000 + 35,000 + 37,000 + 38,000 + 40,000 + 42,000 + 45,000 + 47,000 + 50,000 + 54,000 = ₹4,20,000
把所有工资相加:
32,000 + 35,000 + 37,000 + 38,000 + 40,000 + 42,000 + 45,000 + 47,000 + 50,000 + 54,000 = ₹4,20,000
Step 2
Divide by the count (n = 10):
x̄ = 4,20,000 / 10 = ₹42,000
गिनती (n = 10) से भाग दें:
x̄ = 4,20,000 / 10 = ₹42,000
除以个数(n = 10):
x̄ = 4,20,000 / 10 = ₹42,000
Resultनतीजा结果
The average salary is ₹42,000/month — a fair picture, because all salaries are close to each other. (The median here is ₹41,000, almost the same.)
Average salary ₹42,000/महीना है — सही तस्वीर, क्योंकि सभी salaries एक-दूसरे के पास हैं। (यहाँ median ₹41,000 है, लगभग वही।)
平均工资是 ₹42,000/月 —— 很有代表性,因为所有工资都很接近。(这里的中位数是 ₹41,000,几乎一样。)

The Outlier Problem — When the Mean FailsOutlier की समस्या — जब Mean फ़ेल होता है离群点问题 — 均值失灵的时候

Now the CEO joins with a salary of ₹5,00,000/month:

अब CEO ₹5,00,000/महीना की salary के साथ जुड़ता है:

现在 CEO 加入,月薪 ₹5,00,000:

⚠️
Outlier Effect on the MeanMean पर Outlier का असर离群点对均值的影响

New sum = 4,20,000 + 5,00,000 = ₹9,20,000
New mean = 9,20,000 / 11 = ₹83,636/month

But 10 of the 11 employees earn ₹32,000–₹54,000! ₹83,636 does NOT describe a typical salary. The median only moves from ₹41,000 to ₹42,000. This is why salary surveys usually report the median.

नया जोड़ = 4,20,000 + 5,00,000 = ₹9,20,000
नया mean = 9,20,000 / 11 = ₹83,636/महीना

पर 11 में से 10 कर्मचारी ₹32,000–₹54,000 कमाते हैं! ₹83,636 आम salary नहीं बताता। Median सिर्फ़ ₹41,000 से ₹42,000 होता है। इसीलिए salary surveys आमतौर पर median बताते हैं।

新的总和 = 4,20,000 + 5,00,000 = ₹9,20,000
新的均值 = 9,20,000 / 11 = ₹83,636/月

可 11 人中有 10 人的工资在 ₹32,000–₹54,000 之间!₹83,636 并不代表典型工资。中位数只从 ₹41,000 变成 ₹42,000。这就是工资调查通常报告中位数的原因。

LIVELIVE互动Add the CEO — Watch the Mean Run AwayCEO जोड़ें — Mean को भागते देखें加入 CEO — 看均值“跑掉”

The ten salaries above (grey). Tick the box and move the slider to set the CEO salary. Blue = mean, green = median.

ऊपर की दस salaries (स्लेटी)। Box पर tick करें और CEO की salary set करने के लिए slider खिसकाएँ। नीला = mean, हरा = median.

上面的十个工资(灰色)。勾选复选框并拖动滑块设置 CEO 工资。蓝色 = 均值,绿色 = 中位数。

MeanMean均值
—
MedianMedian中位数
—

Python CodePython CodePython 代码

mean_example.pyPython
import numpy as np

salaries = [32000, 35000, 37000, 38000, 40000,
            42000, 45000, 47000, 50000, 54000]

print("Mean   (no CEO)  :", np.mean(salaries))
print("Median (no CEO)  :", np.median(salaries))

salaries_with_ceo = salaries + [500000]
print("Mean   (with CEO):", round(np.mean(salaries_with_ceo), 2))
print("Median (with CEO):", np.median(salaries_with_ceo))
OUTPUT
Mean (no CEO) : 42000.0 Median (no CEO) : 41000.0 Mean (with CEO): 83636.36 Median (with CEO): 42000.0

Industry Applications of the MeanMean के Industry Applications均值的行业应用

IndustryIndustry行业Applicationइस्तेमाल应用
💰 FinanceFinance金融Average daily stock return, average monthly expensesStock का औसत daily return, औसत monthly ख़र्च股票平均日收益、平均月支出
🏭 ManufacturingManufacturing制造业Average product weight, average defect rate per batchProduct का औसत वज़न, हर batch की औसत defect rate产品平均重量、每批平均次品率
🏥 HealthcareHealthcare医疗Average blood pressure in a trial group, average daily bed occupancyTrial group का औसत blood pressure, रोज़ की औसत bed occupancy试验组平均血压、每日平均床位占用
🎓 EducationEducation教育Average test score across a classClass का औसत test score全班平均分
🛒 E-commerceE-commerce电商Average order value (AOV) — check the median too, because a few big orders pull it upAverage order value (AOV) — median भी देखें, क्योंकि कुछ बड़े orders इसे ऊपर खींचते हैं平均订单金额(AOV)—— 也要看中位数,因为少数大单会把它拉高

When to Use the MeanMean कब इस्तेमाल करें何时使用均值

  • Data is roughly symmetric (for example bell-shaped)Data लगभग symmetric हो (जैसे bell-shaped)数据大致对称(比如钟形)
  • No important outliersकोई बड़े outliers न हों没有明显的离群点
  • Values are numeric (height, weight, temperature, exam scores)Values numeric हों (ऊँचाई, वज़न, तापमान, exam scores)数值型数据(身高、体重、温度、考试分数)
  • You need the value for further calculations (standard deviation, regression)आगे की गणनाओं में value चाहिए (standard deviation, regression)需要用于后续计算(标准差、回归)

SectionSection第 03 节

The Median (Middle Value)Median (बीच की Value)中位数(中间值)

The median is the middle value of the sorted data: half of the values are below it and half are above. Because it depends on position, not size, making the largest value even larger does not change it at all.

Median sort किए data की बीच की value है: आधी values उससे नीचे और आधी ऊपर। क्योंकि यह position पर निर्भर है, आकार पर नहीं, सबसे बड़ी value को और बड़ा करने से यह बिल्कुल नहीं बदलता।

中位数是排序后数据的中间值:一半的值在它下面,一半在上面。因为它取决于位置而不是大小,把最大值变得再大,它也完全不变。

FormulaFormula公式

Odd Number of ValuesOdd संख्या में Values奇数个值
M = value at position (n+1)/2
Sort the data. The median is the single middle value.
e.g. n = 9 → position 5
Data sort करें। Median बीच की एक value है।
जैसे n = 9 → position 5
先排序,中位数就是正中间那一个值。
例:n = 9 → 第 5 个
Even Number of ValuesEven संख्या में Values偶数个值
M = [x₍n/2₎ + x₍n/2+1₎] / 2
Sort the data. Average the two middle values.
e.g. n = 10 → average positions 5 and 6
Data sort करें। बीच की दो values का औसत लें।
जैसे n = 10 → position 5 और 6 का औसत
先排序,再取中间两个值的平均。
例:n = 10 → 第 5 和第 6 个的平均
LIVELIVE互动Sort the Cards and Find the MedianCards को Sort करें और Median खोजें给卡片排序,找出中位数

Make a new odd or even list, add a huge number, then press "Sort & find the median". The huge number changes the mean a lot but the median very little.

नई odd या even list बनाएँ, एक बहुत बड़ा number जोड़ें, फिर "Sort करें और median खोजें" दबाएँ। बड़ा number mean को बहुत बदलता है पर median को बहुत कम।

生成新的奇数或偶数列表,加入一个超大的数,然后点击“排序并找中位数”。超大的数会大幅改变均值,却几乎不影响中位数。

Real Example — House Prices in a Cityअसली उदाहरण — एक शहर में घरों के दाम真实例子 — 某城市的房价

Seven properties recently sold in a neighbourhood (₹ lakh):

एक इलाके में हाल ही में बिकी सात properties (₹ लाख):

某街区最近售出的七套房产(₹ 拉克):

PropertyProperty房产ABCDEFLuxury VillaLuxury Villa豪华别墅
Price (₹L)दाम (₹L)价格(₹L)455247555048420
🧮 Step-by-Step Median CalculationStep-by-Step Median गणना中位数分步计算
Step 1
Sort the values: 45, 47, 48, 50, 52, 55, 420
Values sort करें: 45, 47, 48, 50, 52, 55, 420
排序:45、47、48、50、52、55、420
Step 2
n = 7 (odd) → middle position = (7+1)/2 = 4th value
n = 7 (odd) → बीच की position = (7+1)/2 = चौथी value
n = 7(奇数)→ 中间位置 = (7+1)/2 = 第 4 个
Median
M = ₹50 lakh ✓
M = ₹50 लाख ✓
M = ₹50 拉克 ✓
Compareतुलना对比
Mean = (45+47+48+50+52+55+420) / 7 = 717 / 7 = ₹102.4 lakh — misleading! No typical buyer pays ₹102 lakh when 6 of the 7 homes cost ₹55 lakh or less.
Mean = (45+47+48+50+52+55+420) / 7 = 717 / 7 = ₹102.4 लाख — गुमराह करने वाला! जब 7 में से 6 घर ₹55 लाख या कम के हैं, तो कोई आम ख़रीदार ₹102 लाख नहीं देता।
均值 = (45+47+48+50+52+55+420) / 7 = 717 / 7 = ₹102.4 拉克 —— 严重误导!7 套房里有 6 套不超过 ₹55 拉克,普通买家不会付 ₹102 拉克。
💡
Real-World Insight — Incomeअसली दुनिया की बात — Income现实洞察 — 收入

Income is the classic right-skewed variable. For example, the US Census Bureau reports a median household income of $83,730 for 2024. The mean household income is well above the median, because a small number of very high incomes pull the mean up — which is exactly why official reports lead with the median.

Income सबसे आम right-skewed variable है। उदाहरण के लिए, US Census Bureau ने 2024 की median household income $83,730 बताई है। Mean household income median से काफ़ी ऊपर है, क्योंकि कुछ बहुत ऊँची incomes mean को ऊपर खींचती हैं — इसीलिए official reports median को आगे रखती हैं।

收入是典型的右偏变量。例如,美国人口普查局公布 2024 年家庭收入中位数为 $83,730。家庭收入的均值明显高于中位数,因为少数极高收入把均值拉高了 —— 这正是官方报告首先给出中位数的原因。

Python CodePython CodePython 代码

median_example.pyPython
import numpy as np

house_prices = [45, 52, 47, 55, 50, 48, 420]   # ₹ lakh

print("Sorted:", sorted(house_prices))
print("Mean  :", round(np.mean(house_prices), 2))    # pulled up by the villa
print("Median:", np.median(house_prices))            # the typical home
OUTPUT
Sorted: [45, 47, 48, 50, 52, 55, 420] Mean : 102.43 Median: 50.0

Industry Applications of the MedianMedian के Industry Applications中位数的行业应用

IndustryIndustry行业Applicationइस्तेमाल应用
🏠 Real EstateReal Estate房地产Median home price in a city (the standard measure)शहर में घर का median दाम (standard measure)城市房价中位数(标准指标)
📊 EconomicsEconomics经济学Median household income, median net worthMedian household income, median net worth家庭收入中位数、净资产中位数
🏥 HealthcareHealthcare医疗Median survival time in clinical trialsClinical trials में median survival time临床试验中的中位生存期
💼 HR / RecruitmentHR / Recruitment人力 / 招聘Median salary for a job role — fairer than the meanकिसी job role की median salary — mean से ज़्यादा उचित岗位工资中位数 —— 比均值更公平
🚚 LogisticsLogistics物流Median delivery time — not pulled by rare extreme delaysMedian delivery time — कभी-कभार की बहुत लंबी देरी से नहीं खिंचता配送时间中位数 —— 不受偶发极端延误影响

When to Use the MedianMedian कब इस्तेमाल करें何时使用中位数

  • Data is skewed (income, property prices, wealth)Data skewed हो (income, property prices, दौलत)数据偏斜(收入、房价、财富)
  • Important outliers are presentबड़े outliers मौजूद हों存在明显的离群点
  • Ordinal data — values have an order but unequal gaps (e.g. ratings 1–5)Ordinal data — values का क्रम है पर अंतर बराबर नहीं (जैसे ratings 1–5)有序数据 —— 有先后顺序但间隔不相等(如 1–5 分评分)
  • You want the typical experience, not a mathematical averageआपको गणित वाला average नहीं, आम अनुभव चाहिए你想描述典型情况,而不是数学平均

SectionSection第 04 节

The Mode (Most Frequent Value)Mode (सबसे ज़्यादा बार आने वाली Value)众数(出现最多的值)

The mode is the value that appears most often. Unlike the mean and median, it also works on categorical (non-numeric) data. A dataset can have one mode, two modes (bimodal), several modes, or no mode.

Mode वह value है जो सबसे ज़्यादा बार आती है। Mean और median के उलट, यह categorical (बिना number वाले) data पर भी चलता है। Dataset में एक mode, दो modes (bimodal), कई modes, या कोई mode नहीं भी हो सकता।

众数是出现次数最多的值。与均值和中位数不同,它也适用于类别型(非数值)数据。一个数据集可以有一个众数、两个众数(双峰)、多个众数,或者没有众数。

Mode DefinitionMode की परिभाषा众数定义
Mo = argmax f(x)
The value x with the highest frequency f(x).
Simply: the value that occurs most.
वह value x जिसकी frequency f(x) सबसे ज़्यादा है।
आसान शब्दों में: सबसे ज़्यादा आने वाली value.
频数 f(x) 最大的那个值 x。
简单说:出现最多的值。
LIVELIVE互动Vote for the Mode — Shoe Sizes and ColoursMode के लिए Vote करें — Shoe Sizes और रंग为众数投票 — 鞋码与颜色

These are the two datasets below. Click any bar to add one more customer or vote; the crown moves to the most frequent value. Try "Make it bimodal".

ये नीचे के दोनों datasets हैं। एक और customer या vote जोड़ने के लिए किसी bar पर click करें; crown सबसे ज़्यादा बार आने वाली value पर जाता है। "इसे bimodal बनाएँ" आज़माएँ।

就是下面的两个数据集。点击任意柱子再加一位顾客或一票,皇冠会移到出现最多的值上。试试“变成双峰”。

Real Example — Retail Shoe Storeअसली उदाहरण — जूतों की दुकान真实例子 — 鞋店

A shoe store records the sizes bought by 238 customers to decide which size to order most:

एक जूतों की दुकान 238 customers के ख़रीदे sizes लिखती है, ताकि तय कर सके कि कौन सा size सबसे ज़्यादा मँगाना है:

一家鞋店记录了 238 位顾客购买的尺码,以决定哪个尺码进货最多:

SizeSize尺码66.577.588.5 ★99.51010.511
CustomersCustomers顾客数5815223845403020105
🧮
Finding the ModeMode खोजना找出众数

Mode = size 8.5 — bought by 45 customers, the highest frequency.

The mode is the measure that tells the store most directly: order the most 8.5s! (Here the mean size is 8.6 and the median is 8.5 — close, but a size of "8.6" does not exist on the shelf.)

Mode = size 8.5 — 45 customers ने ख़रीदा, सबसे ज़्यादा frequency.

Mode वह measure है जो दुकान को सीधे बताता है: सबसे ज़्यादा 8.5 मँगाओ! (यहाँ mean size 8.6 और median 8.5 है — पास-पास, पर shelf पर "8.6" size होता ही नहीं।)

众数 = 8.5 码 —— 45 位顾客购买,频数最高。

众数最直接地告诉商店:8.5 码进货最多!(这里均值尺码是 8.6,中位数是 8.5 —— 很接近,但货架上根本没有“8.6 码”。)

Real Example — Favourite Colour Survey (Categorical Data)असली उदाहरण — पसंदीदा रंग Survey (Categorical Data)真实例子 — 最喜欢的颜色调查(类别数据)

A school asks 200 students: "What is your favourite colour?"

एक school 200 students से पूछता है: "आपका पसंदीदा रंग क्या है?"

一所学校问 200 名学生:“你最喜欢什么颜色?”

Blue ★Blue ★蓝色 ★RedRed红色GreenGreen绿色YellowYellow黄色PurplePurple紫色OrangeOrange橙色
72583518125
⚠️
Why Only the Mode Works Hereयहाँ सिर्फ़ Mode क्यों चलता है为什么这里只能用众数

You cannot calculate a mean or median of colours — they are categories, not numbers, and they have no natural order. Mode = Blue is the only valid measure. Always check the data type before choosing a measure.

रंगों का mean या median नहीं निकाला जा सकता — ये categories हैं, numbers नहीं, और इनका कोई स्वाभाविक क्रम नहीं है। Mode = Blue ही अकेला सही measure है। Measure चुनने से पहले हमेशा data type जाँचें।

颜色无法求均值或中位数 —— 它们是类别而不是数字,也没有自然顺序。众数 = 蓝色是唯一有效的度量。选择度量之前,一定先检查数据类型。

Unimodal, Bimodal and MultimodalUnimodal, Bimodal और Multimodal单峰、双峰与多峰

Typeप्रकार类型Definitionपरिभाषा定义Exampleउदाहरण例子
UnimodalOne peak / one modeएक peak / एक mode一个峰 / 一个众数Exam scores clustered around 7070 के आसपास जमा exam scores集中在 70 分左右的考试成绩
BimodalTwo peaks / two modesदो peaks / दो modes两个峰 / 两个众数Customer ages with peaks at 25 and 55; product reviews with many 1★ and many 5★25 और 55 पर peaks वाली customer ages; बहुत सारे 1★ और 5★ वाले product reviews在 25 岁和 55 岁各有一个高峰的顾客年龄;大量 1 星和 5 星并存的商品评价
MultimodalThree or more peaksतीन या ज़्यादा peaks三个或更多峰Restaurant orders by hour: breakfast, lunch and dinner peaksघंटे के हिसाब से restaurant orders: breakfast, lunch और dinner के peaks按小时统计的餐厅订单:早餐、午餐、晚餐三个高峰
No Modeकोई Mode नहीं无众数All values equally frequentसभी values बराबर बार所有值出现次数相同The theoretical outcomes of a fair die (each face has probability 1/6)Fair die के theoretical नतीजे (हर face की probability 1/6)公平骰子的理论结果(每一面的概率都是 1/6)

Python CodePython CodePython 代码

mode_example.pyPython
import numpy as np
from collections import Counter
from scipy import stats

shoe_sizes = [6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10, 10.5, 11]
counts     = [5, 8,  15, 22, 38, 45, 40, 30, 20,  10,   5]

data = np.repeat(shoe_sizes, counts)          # one entry per customer
print("Customers:", len(data))
print("Mode     :", stats.mode(data).mode)    # newer SciPy returns a single value

# Categorical data: SciPy's mode needs numbers, so use Counter (or pandas)
colours = (["Blue"] * 72 + ["Red"] * 58 + ["Green"] * 35 +
           ["Yellow"] * 18 + ["Purple"] * 12 + ["Orange"] * 5)
print("Favourite:", Counter(colours).most_common(1))
OUTPUT
Customers: 238 Mode : 8.5 Favourite: [('Blue', 72)]
🐍
Two Code TrapsCode के दो जाल两个代码陷阱

(1) In SciPy 1.11 and later, stats.mode(...).mode is a single value, so old code with .mode[0] crashes. (2) SciPy's mode only accepts numbers; for text use collections.Counter, statistics.multimode or pandas .mode().

(1) SciPy 1.11 और बाद में stats.mode(...).mode एक ही value है, इसलिए .mode[0] वाला पुराना code crash हो जाता है। (2) SciPy का mode सिर्फ़ numbers लेता है; text के लिए collections.Counter, statistics.multimode या pandas .mode() इस्तेमाल करें।

(1) 在 SciPy 1.11 及以后版本中,stats.mode(...).mode 是单个值,所以带 .mode[0] 的旧代码会报错。(2) SciPy 的 mode 只接受数字;文本数据请用 collections.Counter、statistics.multimode 或 pandas 的 .mode()。

Industry Applications of the ModeMode के Industry Applications众数的行业应用

IndustryIndustry行业Applicationइस्तेमाल应用
🛍️ RetailRetail零售Most popular size, colour or category to stockStock करने के लिए सबसे लोकप्रिय size, रंग या category最该备货的尺码、颜色或品类
📣 MarketingMarketing营销Most common customer age group, most popular channelसबसे आम customer age group, सबसे लोकप्रिय channel最常见的客户年龄段、最受欢迎的渠道
🏥 HealthcareHealthcare医疗Most common diagnosis, most frequently prescribed drugसबसे आम diagnosis, सबसे ज़्यादा लिखी जाने वाली दवा最常见的诊断、开得最多的药
🚗 TransportationTransportation交通Most popular route, most common trip length bandसबसे लोकप्रिय route, सबसे आम trip length band最热门的线路、最常见的行程距离区间
📱 Social MediaSocial Media社交媒体Most liked post type, most used hashtagसबसे ज़्यादा like होने वाला post type, सबसे ज़्यादा इस्तेमाल hashtag获赞最多的帖子类型、使用最多的话题标签

When to Use the ModeMode कब इस्तेमाल करें何时使用众数

  • Data is categorical (colours, brands, yes/no, city names)Data categorical हो (रंग, brands, हाँ/ना, शहरों के नाम)数据是类别型(颜色、品牌、是/否、城市名)
  • You need the most popular item or choiceआपको सबसे लोकप्रिय चीज़ या पसंद चाहिए需要找出最受欢迎的项目或选择
  • Spotting groups in data (two peaks = maybe two different groups)Data में groups पहचानना (दो peaks = शायद दो अलग groups)发现数据中的群体(两个峰 = 可能有两个不同群体)
  • Quality control — finding the most common defect typeQuality control — सबसे आम defect type खोजना质量控制 —— 找出最常见的缺陷类型
  • Filling missing values in categorical ML columnsCategorical ML columns में missing values भरना填补类别型机器学习列中的缺失值

SectionSection第 05 节

Skewness — How the Shape Changes EverythingSkewness — आकार सब कुछ कैसे बदलता है偏度 — 形状如何改变一切

The order of the mean, median and mode tells you the shape of a distribution. Understanding skewness helps you choose the right measure and avoid misleading reports.

Mean, median और mode का क्रम आपको distribution का आकार बताता है। Skewness समझने से सही measure चुनने और गुमराह करने वाली reports से बचने में मदद मिलती है।

均值、中位数和众数的先后顺序能告诉你分布的形状。理解偏度能帮你选对度量,避免做出误导性的报告。

SymmetricSymmetric对称
Bell-shapedBell-shaped钟形
Mean = Median = ModeMean = Median = Mode均值 = 中位数 = 众数
Right Skewed (+)Right Skewed (+)右偏(+)
Long tail on the rightदाईं ओर लंबी पूँछ右侧长尾
Mode < Median < MeanMode < Median < Mean众数 < 中位数 < 均值
Left Skewed (−)Left Skewed (−)左偏(−)
Long tail on the leftबाईं ओर लंबी पूँछ左侧长尾
Mean < Median < ModeMean < Median < Mode均值 < 中位数 < 众数

━ meanmean均值   ━ medianmedian中位数   ━ modemode众数

LIVELIVE互动Bend the Distribution — Watch the Three SeparateDistribution को मोड़ें — तीनों को अलग होते देखें扭动分布 — 看三者如何分开

Move the slider from left-skewed to right-skewed. The page draws 5,000 values with that shape and marks the mean, median and mode (the tallest bar).

Slider को left-skewed से right-skewed तक खिसकाएँ। Page उस आकार के 5,000 values बनाता है और mean, median और mode (सबसे ऊँची bar) दिखाता है।

把滑块从左偏拖到右偏。页面按这种形状生成 5,000 个值,并标出均值、中位数和众数(最高的柱子)。

DistributionDistribution分布Shapeआकार形状Usual orderआम क्रम通常顺序Best measureसबसे अच्छा measure最佳度量
SymmetricSymmetric对称Bell-shapedBell-shaped钟形Mean = Median = ModeAny — all are equalकोई भी — सब बराबर都可以 —— 三者相等
Right-skewed (+)Right-skewed (+)右偏(+)Long tail on the rightदाईं ओर लंबी पूँछ右侧长尾Mode < Median < MeanMedian
Left-skewed (−)Left-skewed (−)左偏(−)Long tail on the leftबाईं ओर लंबी पूँछ左侧长尾Mean < Median < ModeMedian
📐
Pearson's ApproximationPearson's ApproximationPearson 近似式

For moderately skewed, single-peaked data:
Mean − Mode ≈ 3 × (Mean − Median)

This lets you estimate the mode from the mean and median. It is a rule of thumb, not a law: check it in the simulator above — it is close for mild skew and less accurate for strong skew.

मध्यम skewed, एक peak वाले data के लिए:
Mean − Mode ≈ 3 × (Mean − Median)

इससे mean और median से mode का अंदाज़ा लगाया जा सकता है। यह एक आम नियम है, कोई पक्का क़ानून नहीं: ऊपर के simulator में जाँचें — हल्के skew में यह पास रहता है और ज़्यादा skew में कम सटीक।

对中度偏斜、单峰的数据:
均值 − 众数 ≈ 3 × (均值 − 中位数)

可以用均值和中位数来估计众数。这是经验法则而不是定律:在上面的模拟器里验证一下 —— 轻度偏斜时很接近,偏斜严重时就不那么准了。


SectionSection第 06 节

Complete Real Example — Student Exam Scoresपूरा असली उदाहरण — Students के Exam Scores完整真实例子 — 学生考试成绩

A class of 20 students takes a maths exam (out of 100). Here are their scores:

20 students की एक class maths का exam (100 में से) देती है। उनके scores ये हैं:

一个 20 人的班级参加数学考试(满分 100)。成绩如下:

#ScoreScore分数#ScoreScore分数#ScoreScore分数#ScoreScore分数#ScoreScore分数
14556096513721785
252660106514751880
355762116515781988
458862126816702092
🧮 Calculating All Three Measuresतीनों Measures निकालना计算三种度量
Mean
Sum = 1,357 → x̄ = 1,357 / 20 = 67.85
जोड़ = 1,357 → x̄ = 1,357 / 20 = 67.85
总和 = 1,357 → x̄ = 1,357 / 20 = 67.85
Median
n = 20 (even) → average the 10th and 11th sorted values
…, 62, 65, 65, 65, 68, … → M = (65 + 65) / 2 = 65.0
n = 20 (even) → sort करके 10वीं और 11वीं values का औसत
…, 62, 65, 65, 65, 68, … → M = (65 + 65) / 2 = 65.0
n = 20(偶数)→ 排序后第 10、11 个值的平均
…、62、65、65、65、68、… → M = (65 + 65) / 2 = 65.0
Mode
65 appears 3 times (60 and 62 appear twice) → Mo = 65
65 तीन बार आता है (60 और 62 दो-दो बार) → Mo = 65
65 出现 3 次(60 和 62 各出现 2 次)→ Mo = 65
exam_scores.pyPython
import numpy as np
import statistics as st

scores = [45, 52, 55, 58, 60, 60, 62, 62, 65, 65,
          65, 68, 72, 75, 78, 70, 85, 80, 88, 92]

print("Sum   :", sum(scores))
print("Mean  :", np.mean(scores))
print("Median:", np.median(scores))
print("Modes :", st.multimode(scores))       # all values tied for most frequent
print("Sorted 10th and 11th:", sorted(scores)[9], sorted(scores)[10])
OUTPUT
Sum : 1357 Mean : 67.85 Median: 65.0 Modes : [65] Sorted 10th and 11th: 65 65

What It Tells the TeacherTeacher को यह क्या बताता है这对老师意味着什么

MeasureMeasure度量ValueValue值What it tells the teacherTeacher को क्या बताता है对老师的意义
Mean67.85The average — useful to compare this class with other classes or past years.औसत — इस class की दूसरी classes या पिछले सालों से तुलना के लिए उपयोगी।平均分 —— 适合和其他班级或往年比较。
Median65.0The typical student — half the class scored 65 or less, half 65 or more. Mean > median shows a mild right skew: a few high scores pull the mean up.आम student — आधी class के 65 या कम, आधी के 65 या ज़्यादा। Mean > median हल्का right skew दिखाता है: कुछ ऊँचे scores mean को ऊपर खींचते हैं।典型学生 —— 一半同学 65 分及以下,一半 65 分及以上。均值 > 中位数说明轻度右偏:少数高分把均值拉高了。
Mode65The most common score — several students are bunched here; a natural target for revision support.सबसे आम score — कई students यहीं इकट्ठा हैं; revision support के लिए स्वाभाविक लक्ष्य।最常见的分数 —— 好几名学生集中在这里,是复习辅导的自然目标。

SectionSection第 07 节

Decision Guide — Which Measure to Choose?Decision Guide — कौन सा Measure चुनें?决策指南 — 该选哪种度量?

Situationस्थिति情况Use MeanMean लें用均值Use MedianMedian लें用中位数Use ModeMode लें用众数
Data typeData type数据类型NumericNumeric数值型Numeric or ordinalNumeric या ordinal数值型或有序型Categorical or discreteCategorical या discrete类别型或离散型
DistributionDistribution分布SymmetricSymmetric对称SkewedSkewed偏斜Anyकोई भी任意
Outliers present?Outliers हैं?有离群点?No outliersकोई outlier नहीं无离群点Outliers presentOutliers हैं有离群点Usually does not matterआमतौर पर फ़र्क़ नहीं通常无关紧要
Goalलक्ष्य目的Further calculationsआगे की गणनाएँ后续计算Describe the typical valueआम value बताना描述典型值Find the most popular valueसबसे लोकप्रिय value खोजना找出最受欢迎的值
Real exampleअसली उदाहरण实例Average temperatureऔसत तापमान平均气温Household incomeHousehold income家庭收入Most popular productसबसे लोकप्रिय product最畅销的产品
ML imputationML imputation机器学习缺失值填补Roughly normal featuresलगभग normal features近似正态的特征Skewed featuresSkewed features偏斜特征Categorical columnsCategorical columns类别列

Missing values in ML — the same rule, in codeML में Missing Values — वही नियम, code में机器学习中的缺失值 — 同样的规则,用代码实现

imputation_example.pyPython
import numpy as np
import pandas as pd
from sklearn.impute import SimpleImputer

df = pd.DataFrame({
    'age':    [25, 32, np.nan, 41, 29, 35],               # roughly symmetric
    'income': [30, 35, 32, np.nan, 38, 400],              # ₹ thousand, skewed
    'city':   ['Delhi', 'Pune', 'Delhi', None, 'Delhi', 'Pune'],
})

print("Mean income  :", df['income'].mean())    # pulled up by the 400
print("Median income:", df['income'].median())

df['age']    = SimpleImputer(strategy='mean').fit_transform(df[['age']]).ravel()
df['income'] = SimpleImputer(strategy='median').fit_transform(df[['income']]).ravel()
df['city']   = SimpleImputer(strategy='most_frequent').fit_transform(df[['city']]).ravel()
print(df)
OUTPUT
Mean income : 107.0 Median income: 35.0 age income city 0 25.0 30.0 Delhi 1 32.0 35.0 Pune 2 32.4 32.0 Delhi 3 41.0 35.0 Delhi 4 29.0 38.0 Delhi 5 35.0 400.0 Pune

The income column shows why the rule matters: one income of 400 lifts the mean to 107, so mean imputation would invent a high earner. The median (35) gives a typical value.

Income column दिखाता है कि नियम क्यों ज़रूरी है: 400 की एक income mean को 107 तक ले जाती है, इसलिए mean imputation एक नक़ली ऊँची कमाई वाला बना देता। Median (35) आम value देता है।

收入列说明了这条规则为什么重要:一个 400 的收入把均值拉到 107,用均值填补就等于凭空造出一个高收入者。中位数(35)给出的才是典型值。

LIVELIVE互动Quick Practice — Mean, Median or Mode?जल्दी अभ्यास — Mean, Median या Mode?快速练习 — 均值、中位数还是众数?

Read each situation, pick a measure, and read why. Your score is shown at the top.

हर स्थिति पढ़ें, एक measure चुनें, और वजह पढ़ें। आपका score ऊपर दिखता है।

阅读每个场景,选择一种度量,再看解释。得分显示在上方。

🎯 Golden Rules for Data ScientistsData Scientists के लिए Golden Rules数据科学家的黄金法则
1
Always look at your data before choosing a measure — check for skew and outliers with a histogram or box plot.
Measure चुनने से पहले हमेशा data देखें — histogram या box plot से skew और outliers जाँचें।
选择度量之前一定先看数据 —— 用直方图或箱线图检查偏斜和离群点。
2
Report both mean and median when in doubt — the gap between them reveals skew at once.
शक हो तो mean और median दोनों बताएँ — उनके बीच का gap तुरंत skew दिखा देता है।
拿不准时均值和中位数都报告 —— 两者的差距立刻暴露偏斜。
3
Never use the mean for categorical data — it means nothing.
Categorical data के लिए mean कभी इस्तेमाल न करें — इसका कोई मतलब नहीं।
永远不要对类别数据用均值 —— 毫无意义。
4
For ML missing values: mean for roughly normal features, median for skewed features, mode for categorical columns.
ML missing values के लिए: लगभग normal features में mean, skewed में median, categorical columns में mode.
机器学习缺失值:近似正态的特征用均值,偏斜特征用中位数,类别列用众数。
5
A large gap between mean and median is a red flag — look for outliers, skew or data-entry errors before you continue.
Mean और median के बीच बड़ा gap चेतावनी है — आगे बढ़ने से पहले outliers, skew या data-entry की ग़लतियाँ देखें।
均值与中位数差距大是危险信号 —— 继续之前先查离群点、偏斜或录入错误。

SectionSection第 08 节

Quick Reference CardQuick Reference Card速查卡

Propertyगुण特性MeanMedianMode
SymbolSymbol符号x̄ / μMMo
FormulaFormula公式Σxᵢ / nMiddle value (sorted)बीच की value (sort के बाद)排序后的中间值Most frequent valueसबसे ज़्यादा बार आने वाली value出现最多的值
Data typeData type数据类型Numeric onlyसिर्फ़ numeric仅数值型Numeric or ordinalNumeric या ordinal数值型或有序型Any (incl. categorical)कोई भी (categorical समेत)任意(含类别型)
Outlier effect?Outlier का असर?受离群点影响?Yes — stronglyहाँ — बहुत是 —— 很大Little — robustकम — मज़बूत很小 —— 稳健Usually noneआमतौर पर नहीं通常没有
Always one value?हमेशा एक value?总是唯一?Always 1 valueहमेशा 1 value总是 1 个值Always 1 valueहमेशा 1 value总是 1 个值0, 1 or many0, 1 या कई0 个、1 个或多个
Skewed dataSkewed data偏斜数据Misleadingगुमराह करता है会误导Reliableभरोसेमंद可靠Dependsनिर्भर करता है视情况而定
Used in standard deviation?Standard deviation में इस्तेमाल?用于计算标准差?Yesहाँ是Noनहीं否Noनहीं否
Real estateReal estate房地产Avoidबचें避免Standard useStandard इस्तेमाल标准用法Rareकम ही少用
Income reportingIncome reporting收入报告Report with care (alongside the median)सावधानी से (median के साथ)谨慎使用(与中位数一起报告)Preferredपसंदीदा首选Income bandsIncome bands收入区间
ML imputationML imputation机器学习填补Roughly normal featuresलगभग normal features近似正态特征Skewed featuresSkewed features偏斜特征Categorical featuresCategorical features类别特征