The Story That Makes It Clickवह कहानी जिससे बात समझ आती है一个让你秒懂的故事
You are a data scientist at a delivery company. Your boss drops four columns on your desk and says: "Find the average for each of these."
आप एक delivery company में data scientist हैं। आपके boss चार columns देकर कहते हैं: "इन सबका average निकालो।"
你是一家快递公司的数据科学家。老板丢给你四列数据,说:“把每一列的平均值算出来。”
| ColumnColumn列 | What it holdsइसमें क्या है内容 | Sample valuesSample values示例值 |
|---|---|---|
| A | Driver regionDriver region司机所在区域 | North, South, East, West, North |
| B | Customer satisfactionCustomer satisfaction客户满意度 | Very Happy, Happy, Neutral, Unhappy, Very Happy |
| C | Outside temperature at deliveryDelivery के समय बाहर का तापमान送达时的室外温度 | −5 °C, 0 °C, 12 °C, 18 °C, 25 °C |
| D | Package weightPackage weight包裹重量 | 0.5 kg, 1.2 kg, 4.8 kg, 0.3 kg, 12.0 kg |
You try .mean() on every column:
आप हर column पर .mean() चलाते हैं:
你对每一列都试了 .mean():
import pandas as pd
df = pd.DataFrame({
'region': ['North', 'South', 'East', 'West', 'North'],
'satisfaction': ['Very Happy', 'Happy', 'Neutral', 'Unhappy', 'Very Happy'],
'temp_c': [-5, 0, 12, 18, 25],
'weight_kg': [0.5, 1.2, 4.8, 0.3, 12.0],
})
for col in df.columns:
try:
print(f"{col:<13} mean = {df[col].mean():.2f}")
except TypeError as e:
print(f"{col:<13} ERROR: {type(e).__name__}")
Regions and satisfaction labels stop with an error — there is nothing to add up. Temperature gives 10 °C, and that average is perfectly valid. Weight gives 3.76 kg, also valid. So the mean works for C and D — but C and D are still different. You may say "12 kg is 40 times heavier than 0.3 kg". You may not say "20 °C is twice as hot as 10 °C".
Regions और satisfaction labels error देकर रुक जाते हैं — जोड़ने के लिए कुछ है ही नहीं। Temperature 10 °C देता है, और यह average बिल्कुल सही है। Weight 3.76 kg देता है, यह भी सही। तो mean C और D के लिए काम करता है — पर C और D फिर भी अलग हैं। आप कह सकते हैं "12 kg, 0.3 kg से 40 गुना भारी है"। आप यह नहीं कह सकते कि "20 °C, 10 °C से दोगुना गर्म है"।
区域和满意度标签直接报错 —— 根本没东西可加。温度给出 10 °C,这个平均值完全有效。重量给出 3.76 kg,同样有效。所以均值对 C 和 D 都适用 —— 但 C 和 D 仍然不同。你可以说“12 kg 是 0.3 kg 的 40 倍重”,但不能说“20 °C 是 10 °C 的两倍热”。
The "average" of North and South is not East. The middle of "Very Happy" and "Unhappy" is not automatically "Neutral". And 0 °C is not "no temperature", so ratios of °C values mean nothing. Use the wrong statistic for the data type and you get numbers that look precise but mean nothing.
North और South का "average" East नहीं है। "Very Happy" और "Unhappy" का बीच अपने-आप "Neutral" नहीं होता। और 0 °C का मतलब "कोई तापमान नहीं" नहीं है, इसलिए °C values के ratios का कोई मतलब नहीं। Data type के लिए ग़लत statistic लें, तो ऐसी संख्याएँ मिलती हैं जो सटीक दिखती हैं पर बेमतलब होती हैं।
North 和 South 的“平均”不是 East。“Very Happy”和“Unhappy”的中间并不自动等于“Neutral”。0 °C 也不代表“没有温度”,所以 °C 数值之间的比值毫无意义。对数据类型用错统计量,得到的数字看似精确,实则毫无意义。
In 1946, the psychologist S. S. Stevens published "On the Theory of Scales of Measurement" in the journal Science. He described four levels of measurement — nominal, ordinal, interval and ratio — and which operations are allowed on each. Data scientists still use this idea every day.
1946 में psychologist S. S. Stevens ने journal Science में "On the Theory of Scales of Measurement" छापा। उन्होंने चार levels of measurement बताए — nominal, ordinal, interval और ratio — और हर एक पर कौन से operations चलते हैं। Data scientists आज भी रोज़ यह विचार इस्तेमाल करते हैं।
1946 年,心理学家 S. S. Stevens 在《Science》期刊上发表了“On the Theory of Scales of Measurement”。他提出了四种测量尺度 —— 定类、定序、定距、定比 —— 以及每种尺度允许哪些运算。数据科学家至今每天都在用这个思路。
Data Types in Pictures — Understand Before the Mathsतस्वीरों में Data Types — गणित से पहले समझें图解数据类型 — 先理解,再算数
Nominal: shuffle the boxes and nothing is lost. Ordinal: the steps go up, but by different amounts. Interval: the same temperatures sit under different numbers in °C and °F, because each scale puts zero somewhere else. Ratio: bars start at a real zero, so "4 times" is true.
Nominal: boxes को उलट-पलट दें, कुछ नहीं खोता। Ordinal: steps ऊपर जाते हैं, पर अलग-अलग मात्रा से। Interval: वही तापमान °C और °F में अलग संख्याओं के नीचे है, क्योंकि हर scale zero अलग जगह रखता है। Ratio: bars असली zero से शुरू होते हैं, इसलिए "4 गुना" सच है।
定类:把方块打乱,什么都没丢。定序:台阶往上走,但每级高度不同。定距:同样的温度在 °C 和 °F 下对应不同数字,因为两个温标的零点位置不同。定比:柱子从真正的零开始,所以“4 倍”是真的。
Each step keeps everything below it and adds one more property — and one more set of allowed operations.
हर step अपने नीचे की हर चीज़ रखता है और एक नया गुण जोड़ता है — और साथ में allowed operations का एक नया set।
每一级都保留下面所有的性质,再多加一个 —— 也多出一组可用的运算。
The Four Types — Overviewचारों Types — एक नज़र四种类型 — 概览
The four types form a hierarchy. Each level keeps the properties of the levels below it and adds one more. Higher up, the data carries more information and more statistics become valid.
चारों types एक hierarchy बनाते हैं। हर level अपने नीचे के levels के गुण रखता है और एक नया जोड़ता है। ऊपर जाने पर data में ज़्यादा जानकारी होती है और ज़्यादा statistics सही हो जाते हैं।
这四种类型构成一个层级。每一级都保留下面各级的性质,再增加一个。越往上,数据包含的信息越多,可用的统计量也越多。
Property added: Identity — you can tell values apart (= or ≠).
नया गुण: Identity — values को अलग पहचान सकते हैं (= या ≠)।
新增性质:可区分 —— 能分辨值是否相同(= 或 ≠)。
Property added: Order — values can be ranked (< or >).
नया गुण: Order — values को rank कर सकते हैं (< या >)।
新增性质:顺序 —— 可以排序(< 或 >)。
Property added: Equal intervals — a step of 1 means the same everywhere on the scale (+ and −).
नया गुण: Equal intervals — 1 का step scale पर हर जगह एक ही मतलब रखता है (+ और −)।
新增性质:等间隔 —— 刻度上任何地方 1 个单位都代表同样的量(+ 和 −)。
Property added: True zero — all arithmetic is valid (× and ÷).
नया गुण: True zero — सारा arithmetic सही है (× और ÷)।
新增性质:真正的零点 —— 所有算术都有效(× 和 ÷)。
| TypeType类型 | Identity?Identity?可区分? | Order?Order?有顺序? | Equal gaps?बराबर अंतर?等间隔? | True zero?True zero?真正零点? |
|---|---|---|---|---|
| Nominal | Yesहाँ是 | Noनहीं否 | Noनहीं否 | Noनहीं否 |
| Ordinal | Yesहाँ是 | Yesहाँ是 | Noनहीं否 | Noनहीं否 |
| Interval | Yesहाँ是 | Yesहाँ是 | Yesहाँ是 | Noनहीं否 |
| Ratio | Yesहाँ是 | Yesहाँ是 | Yesहाँ是 | Yesहाँ是 |
Categorical (qualitative) = nominal + ordinal. Numerical (quantitative) = interval + ratio. Separately, numerical data can be discrete (counts: 0, 1, 2 items) or continuous (weight: 1.237 kg). "Discrete vs continuous" is a different question from "interval vs ratio" — a count of items is discrete and ratio.
Categorical (qualitative) = nominal + ordinal. Numerical (quantitative) = interval + ratio. अलग से, numerical data discrete (गिनती: 0, 1, 2 items) या continuous (वज़न: 1.237 kg) हो सकता है। "Discrete vs continuous" एक अलग सवाल है, "interval vs ratio" से अलग — items की गिनती discrete और ratio दोनों है।
分类数据(定性) = 定类 + 定序。数值数据(定量) = 定距 + 定比。另外,数值数据还可以分为离散(计数:0、1、2 件)和连续(重量:1.237 kg)。“离散 vs 连续”与“定距 vs 定比”是两个不同的问题 —— 商品件数既是离散的,也是定比的。
Nominal Data — Just NamesNominal Data — सिर्फ़ नाम定类数据 — 只是名字
Nominal data is the simplest type. Values are labels or categories with no natural order. You can count how many fall in each category, but you cannot rank them or do arithmetic.
Nominal data सबसे आसान type है। Values labels या categories हैं, जिनका कोई स्वाभाविक क्रम नहीं। आप गिन सकते हैं कि हर category में कितने हैं, पर उन्हें rank या उन पर arithmetic नहीं कर सकते।
定类数据是最简单的类型。值是没有自然顺序的标签或类别。你可以统计每一类有多少个,但不能排序,也不能做算术。
The story — sorting the post roomकहानी — post room में छँटाई故事 — 邮件室分拣
A post-room worker sorts 200 parcels into four regions: 62 North, 48 South, 55 East and 35 West. The mode is North — the most common destination. Counts, percentages and the mode are the statistics that make sense here. "What is the average region?" is a meaningless question. "Is North bigger than South?" can only mean "does North have more parcels?" — North is not a bigger value, just a different label.
Post room का एक कर्मचारी 200 parcels को चार regions में छाँटता है: 62 North, 48 South, 55 East और 35 West. Mode North है — सबसे आम destination. यहाँ counts, percentages और mode ही मतलब वाले statistics हैं। "Average region क्या है?" एक बेमतलब सवाल है। "क्या North, South से बड़ा है?" का मतलब सिर्फ़ यह हो सकता है कि "क्या North में ज़्यादा parcels हैं?" — North कोई बड़ी value नहीं, बस एक अलग label है।
邮件室的工作人员把 200 个包裹分到四个区域:North 62 个、South 48 个、East 55 个、West 35 个。众数是 North —— 最常见的目的地。这里有意义的统计量就是计数、百分比和众数。 “平均区域是什么?”是个没有意义的问题。“North 比 South 大吗?”只能理解为“North 的包裹更多吗?”—— North 不是更大的值,只是另一个标签。
- Mode (most common)Mode (सबसे आम)众数(最常见)
- Frequency countsFrequency counts频数
- Percentages / proportionsPercentages / proportions百分比 / 比例
- Chi-square testChi-square test卡方检验
- Mean (no average label)Mean (कोई average label नहीं)均值(不存在“平均标签”)
- Median (no order)Median (कोई क्रम नहीं)中位数(没有顺序)
- Standard deviationStandard deviation标准差
- Any arithmeticकोई भी arithmetic任何算术运算
- Blood type: A, B, AB, OBlood type: A, B, AB, O血型:A、B、AB、O
- Eye colourआँखों का रंग眼睛颜色
- Programming languageProgramming language编程语言
- Country, city, PIN codeCountry, city, PIN code国家、城市、邮编
| Situationस्थिति场景 | Nominal columnNominal column定类列 | A good question to askपूछने लायक सही सवाल该问的好问题 |
|---|---|---|
| Customer databaseCustomer database客户数据库 | Preferred languageपसंदीदा भाषा偏好语言 | Which language do most users prefer?ज़्यादातर users कौन सी भाषा पसंद करते हैं?大多数用户偏好哪种语言? |
| Hospital recordsHospital records医院记录 | Blood typeBlood type血型 | What percentage of patients are type O?कितने प्रतिशत मरीज़ type O हैं?有多少比例的病人是 O 型? |
| E-commerce ordersE-commerce orders电商订单 | Payment methodPayment method支付方式 | Is UPI or card used more often?UPI ज़्यादा इस्तेमाल होता है या card?UPI 和银行卡哪个用得更多? |
| Job applicationsJob applications求职申请 | Degree subjectDegree subject学位专业 | What is the most common degree subject?सबसे आम degree subject कौन सा है?最常见的专业是什么? |
| App analyticsApp analytics应用分析 | Device typeDevice type设备类型 | What share of users are on iOS vs Android?कितने users iOS पर हैं और कितने Android पर?iOS 和 Android 用户各占多少? |
Datasets often store categories as integers: 1 = North, 2 = South, 3 = East, 4 = West. These numbers are only shorthand labels. The "average" of North (1) and East (3) is 2, but that does not mean "South". Change the coding and the average changes — even though no parcel moved. Always check what an integer column really means before doing arithmetic on it.
Datasets अक्सर categories को integers में रखते हैं: 1 = North, 2 = South, 3 = East, 4 = West. ये संख्याएँ सिर्फ़ छोटे labels हैं। North (1) और East (3) का "average" 2 है, पर इसका मतलब "South" नहीं। Coding बदलें तो average बदल जाता है — जबकि एक भी parcel नहीं हिला। Integer column पर arithmetic से पहले हमेशा जाँचें कि उसका असली मतलब क्या है।
数据集常把类别存成整数:1 = North,2 = South,3 = East,4 = West。这些数字只是简写标签。North (1) 和 East (3) 的“平均”是 2,但这并不表示“South”。换一种编码,平均值就变了 —— 而一个包裹都没动过。对整数列做算术之前,一定先弄清它的真实含义。
import pandas as pd
regions = pd.Series(['North'] * 62 + ['South'] * 48 + ['East'] * 55 + ['West'] * 35)
print(regions.value_counts())
print("Mode:", regions.mode()[0])
print((regions.value_counts(normalize=True) * 100).round(1).astype(str) + ' %')
# The same data stored as codes: 1=North, 2=South, 3=East, 4=West
codes = regions.map({'North': 1, 'South': 2, 'East': 3, 'West': 4})
print("Mean of the codes:", round(codes.mean(), 2), "<- meaningless")
# Change the coding and the "mean" changes too
codes2 = regions.map({'West': 1, 'East': 2, 'South': 3, 'North': 4})
print("Mean with another coding:", round(codes2.mean(), 2))
Ordinal Data — Order Without Equal GapsOrdinal Data — क्रम, पर बराबर अंतर नहीं定序数据 — 有顺序,但间隔不等
Ordinal data has a meaningful order — you know which value is higher. But the gaps between values are not known to be equal. The step from rank 1 to rank 2 need not be the same size as the step from rank 4 to rank 5.
Ordinal data में मतलब वाला क्रम होता है — पता है कौन सी value ऊँची है। पर values के बीच के अंतर बराबर हैं, यह पता नहीं। Rank 1 से 2 का step, rank 4 से 5 के step जितना बड़ा हो, यह ज़रूरी नहीं।
定序数据有有意义的顺序 —— 你知道哪个值更高。但值与值之间的间隔并不确定相等。从第 1 级到第 2 级的跨度,不一定和第 4 级到第 5 级一样大。
The story — the restaurant tableकहानी — restaurant की table故事 — 餐厅里的一桌人
Four friends rate a restaurant: Alice 5 stars, Bob 4, Carol 2, Dan 5. You know Alice enjoyed it more than Carol, and that 5 stars is better than 4. But is the gap from 4 to 5 the same as the gap from 1 to 2? Not necessarily. Moving from "Terrible" to "Bad" may be a far bigger change in experience than moving from "Good" to "Excellent". The numbers 1–5 suggest a precision that is not really there.
चार दोस्त एक restaurant को rate करते हैं: Alice 5 stars, Bob 4, Carol 2, Dan 5. आप जानते हैं कि Alice को Carol से ज़्यादा मज़ा आया, और 5 stars, 4 से बेहतर है। पर क्या 4 से 5 का अंतर, 1 से 2 के अंतर जितना है? ज़रूरी नहीं। "Terrible" से "Bad" तक जाना, "Good" से "Excellent" तक जाने से कहीं बड़ा बदलाव हो सकता है। 1–5 की संख्याएँ एक ऐसी सटीकता का भ्रम देती हैं जो असल में नहीं है।
四个朋友给一家餐厅打分:Alice 5 星,Bob 4 星,Carol 2 星,Dan 5 星。你知道 Alice 比 Carol 更满意,也知道 5 星比 4 星好。但 4 到 5 的差距和 1 到 2 一样大吗? 不一定。从“Terrible”到“Bad”的体验变化,可能远大于从“Good”到“Excellent”。1–5 这些数字营造了一种并不存在的精确感。
[5, 5, 5, 5, 5, 1, 1, 1, 1, 1]Five love it. Five hate it.
[5, 5, 5, 5, 5, 1, 1, 1, 1, 1]पाँच को बहुत पसंद है। पाँच को बिल्कुल नहीं।
[5, 5, 5, 5, 5, 1, 1, 1, 1, 1]五人非常喜欢,五人非常讨厌。
[1, 1, 1, 1, 1, 5, 5, 5, 5, 5]. The 5th value is 1 and the 6th is 5. Software averages them to 3.0, but averaging two ratings is itself an arithmetic step that ordinal data does not support. The honest answer is: the median lies somewhere between "1" and "5" — it tells you very little here.[1, 1, 1, 1, 1, 5, 5, 5, 5, 5]. 5वीं value 1 है और 6वीं 5. Software इनका औसत 3.0 निकालता है, पर दो ratings का औसत लेना भी एक arithmetic step है जो ordinal data पर नहीं चलता। ईमानदार जवाब: median "1" और "5" के बीच कहीं है — यहाँ यह बहुत कम बताता है।[1, 1, 1, 1, 1, 5, 5, 5, 5, 5]。第 5 个值是 1,第 6 个是 5。软件会取平均得到 3.0,但对两个评分求平均本身就是定序数据不支持的算术运算。诚实的回答是:中位数介于“1”和“5”之间 —— 在这里它几乎说明不了什么。⭐⭐⭐⭐⭐ 50% ⭐⭐⭐⭐ 0% ⭐⭐⭐ 0% ⭐⭐ 0% ⭐ 50%
Two peaks. The product splits opinion completely — that is the real story.
⭐⭐⭐⭐⭐ 50% ⭐⭐⭐⭐ 0% ⭐⭐⭐ 0% ⭐⭐ 0% ⭐ 50%
दो peaks. Product ने राय को पूरी तरह बाँट दिया — यही असली कहानी है।
⭐⭐⭐⭐⭐ 50% ⭐⭐⭐⭐ 0% ⭐⭐⭐ 0% ⭐⭐ 0% ⭐ 50%
两个峰。这个产品让意见彻底两极分化 —— 这才是真正的故事。
- ModeMode众数
- Median (for an odd count, or "between two levels")Median (odd count में, या "दो levels के बीच")中位数(奇数个时,或“介于两级之间”)
- Percentiles (Q1, Q3)Percentiles (Q1, Q3)百分位数(Q1、Q3)
- Spearman rank correlation, Mann–Whitney testSpearman rank correlation, Mann–Whitney testSpearman 秩相关、Mann–Whitney 检验
- Mean (gaps not known to be equal)*Mean (अंतर बराबर होने का पता नहीं)*均值(间隔不确定相等)*
- Standard deviation*Standard deviation*标准差*
- Pearson correlationPearson correlationPearson 相关
- Ratios ("twice as satisfied")Ratios ("दोगुना संतुष्ट")比值(“满意度高一倍”)
- Star ratings 1–5Star ratings 1–51–5 星评分
- Education levelEducation level学历
- Pain scale 1–10Pain scale 1–10疼痛评分 1–10
- Likert survey itemsLikert survey itemsLikert 问卷题
Strictly, the mean needs equal gaps. In practice, averages of ratings are everywhere — app stores, course feedback, many research papers — and averaging many survey items often works reasonably well. Both views are common. A safe habit: if you report a mean for ordinal data, also show the full distribution (or the median), and never call one product "twice as good" as another. The simulator below shows what can go wrong.
सख़्ती से देखें तो mean के लिए बराबर अंतर चाहिए। व्यवहार में ratings के averages हर जगह हैं — app stores, course feedback, बहुत से research papers — और कई survey items का औसत अक्सर ठीक-ठाक काम करता है। दोनों विचार आम हैं। सुरक्षित आदत: ordinal data का mean बताएँ तो पूरा distribution भी दिखाएँ (या median), और किसी product को दूसरे से "दोगुना अच्छा" कभी न कहें। नीचे का simulator दिखाता है कि क्या ग़लत हो सकता है।
严格来说,均值需要等间隔。但实际上,评分的平均值随处可见 —— 应用商店、课程反馈、许多研究论文 —— 对多道问卷题取平均通常也还算可靠。两种观点都很普遍。稳妥的习惯是:如果对定序数据报告均值,同时展示完整分布(或中位数),并且永远不要说一个产品比另一个“好一倍”。下面的模拟器展示了可能出现的问题。
Two products, same 100 ratings each. The labels stay the same — you only change how far apart "Terrible" and "Excellent" really are. Watch the means swap places while the medians never move.
दो products, हर एक की 100 ratings. Labels वही रहते हैं — आप सिर्फ़ यह बदलते हैं कि "Terrible" और "Excellent" असल में कितनी दूर हैं। देखें कि means की जगह बदल जाती है, जबकि medians कभी नहीं हिलते।
两个产品,各有同样的 100 条评分。标签不变 —— 你只改变“Terrible”和“Excellent”实际相隔多远。观察均值如何互换位置,而中位数始终不动。
import pandas as pd
levels = ['Terrible', 'Bad', 'OK', 'Good', 'Excellent']
ratings = pd.Series(pd.Categorical(
['Excellent'] * 5 + ['Terrible'] * 5, categories=levels, ordered=True))
print(ratings.min(), '<', ratings.max()) # order works
print((ratings > 'OK').sum(), 'ratings are better than OK')
codes = ratings.cat.codes + 1 # 1..5 star codes
print("Mean stars:", codes.mean()) # 3.0 -> "OK"? nobody said OK
print("pandas median:", codes.median()) # averages 1 and 5 -> 3.0
s = codes.sort_values().to_list()
n = len(s)
print("Middle two ratings:", levels[s[n//2 - 1] - 1], "and", levels[s[n//2] - 1])
print((ratings.value_counts(normalize=True, sort=False) * 100).astype(int).astype(str) + ' %')
Interval Data — Equal Gaps, No True ZeroInterval Data — बराबर अंतर, true zero नहीं定距数据 — 等间隔,但没有真正的零点
Interval data is numerical with equal gaps: the step from 10 °C to 11 °C is the same amount of warming as the step from 30 °C to 31 °C. But its zero is a choice, not "nothing". 0 °C is just the freezing point of water.
Interval data में बराबर अंतर वाली संख्याएँ होती हैं: 10 °C से 11 °C का step उतनी ही गर्मी है जितनी 30 °C से 31 °C. पर इसका zero एक चुनाव है, "कुछ नहीं" नहीं। 0 °C बस पानी के जमने का बिंदु है।
定距数据是等间隔的数值:从 10 °C 到 11 °C 升温的幅度,和从 30 °C 到 31 °C 一样。但它的零点只是一个约定,而不是“什么都没有”。0 °C 只是水的冰点。
The story — the weather reportकहानी — मौसम की ख़बर故事 — 天气预报
Monday is 10 °C and Tuesday is 20 °C. A news anchor says: "Tuesday will be twice as hot!" In °F the same days are 50 °F and 68 °F — only 1.36 times. In Kelvin they are 283.15 K and 293.15 K — about 3.5% warmer. The "twice" came from where Celsius happens to put zero. But "Tuesday is 10 °C warmer" is true in every scale (10 °C = 18 °F = 10 K of change). With interval data, differences are meaningful and ratios are not.
सोमवार 10 °C है और मंगलवार 20 °C. एक news anchor कहता है: "मंगलवार दोगुना गर्म होगा!" °F में यही दिन 50 °F और 68 °F हैं — सिर्फ़ 1.36 गुना। Kelvin में 283.15 K और 293.15 K — लगभग 3.5% ज़्यादा गर्म। "दोगुना" सिर्फ़ इसलिए आया क्योंकि Celsius zero को एक ख़ास जगह रखता है। पर "मंगलवार 10 °C ज़्यादा गर्म है" हर scale में सच है (10 °C = 18 °F = 10 K का बदलाव)। Interval data में अंतर का मतलब है, ratios का नहीं।
周一 10 °C,周二 20 °C。主播说:“周二会热一倍!”换成 °F,这两天是 50 °F 和 68 °F —— 只有 1.36 倍。换成开尔文是 283.15 K 和 293.15 K —— 只暖了约 3.5%。“一倍”只是因为摄氏度恰好把零点放在那里。 但“周二比周一暖 10 °C”在任何温标下都成立(10 °C = 18 °F = 10 K 的变化)。对定距数据,差值有意义,比值没有。
- Mean and medianMean और median均值和中位数
- Differences ("10 degrees warmer")अंतर ("10 degree ज़्यादा गर्म")差值(“暖 10 度”)
- Standard deviationStandard deviation标准差
- Pearson correlation, t-testPearson correlation, t-testPearson 相关、t 检验
- Ratios ("twice as hot")Ratios ("दोगुना गर्म")比值(“热一倍”)
- Percentage change of the valuesValues का percentage change数值本身的百分比变化
- Coefficient of variationCoefficient of variation变异系数
- Geometric meanGeometric mean几何平均
- Temperature in °C or °F°C या °F में तापमान°C 或 °F 温度
- Calendar years (AD 2024)Calendar years (AD 2024)公历年份(2024 年)
- IQ scores (usually treated as interval)IQ scores (आम तौर पर interval माने जाते हैं)智商分数(通常视为定距)
- Standardised test scores, z-scoresStandardised test scores, z-scores标准化考试分数、z 分数
Set two days. The bars are drawn from each scale's own zero. Ratios depend on where zero sits; differences do not.
दो दिन चुनें। Bars हर scale के अपने zero से बनते हैं। Ratios इस पर निर्भर हैं कि zero कहाँ है; अंतर नहीं।
设置两天的温度。每根柱子都从各自温标的零点画起。比值取决于零点在哪里;差值则不受影响。
import numpy as np
c = np.array([10.0, 20.0]) # two days, °C
f = c * 9 / 5 + 32 # same days, °F
k = c + 273.15 # same days, Kelvin
print("Ratio °C:", round(c[1] / c[0], 2), " °F:", round(f[1] / f[0], 2),
" K:", round(k[1] / k[0], 3))
print("Difference °C:", c[1] - c[0], " °F:", f[1] - f[0], " K:", round(k[1] - k[0], 2))
# Differences of differences ARE comparable on every interval scale
week_c = np.array([12, 15, 21, 18])
week_f = week_c * 9 / 5 + 32
print("Mean °C:", week_c.mean(), "-> in °F:", week_c.mean() * 9 / 5 + 32,
"| mean of °F:", round(week_f.mean(), 2))
print("Rise Mon→Wed vs Mon→Tue °C:", (21 - 12) / (15 - 12),
" °F:", round((week_f[2] - week_f[0]) / (week_f[1] - week_f[0]), 2))
The mean converts correctly between scales (16.5 °C → 61.7 °F), and a ratio of differences (3.0) is the same in both. Only the ratio of the values themselves breaks.
Mean scales के बीच सही बदलता है (16.5 °C → 61.7 °F), और अंतरों का ratio (3.0) दोनों में एक है। सिर्फ़ values का अपना ratio टूटता है।
均值在温标之间换算正确(16.5 °C → 61.7 °F),差值之间的比(3.0)在两种温标下也相同。只有数值本身的比值会出问题。
Ratio Data — Everything Is AllowedRatio Data — सब कुछ allowed定比数据 — 一切运算皆可
Ratio data has equal gaps and a true zero: 0 means "none of it". 0 kg is no weight, 0 minutes is no time, ₹0 is no money. So "12 kg is 40 times 0.3 kg" is a true statement, and every statistic is valid.
Ratio data में बराबर अंतर और true zero दोनों होते हैं: 0 का मतलब "बिल्कुल नहीं"। 0 kg = कोई वज़न नहीं, 0 मिनट = कोई समय नहीं, ₹0 = कोई पैसा नहीं। इसलिए "12 kg, 0.3 kg का 40 गुना है" सच्चा कथन है, और हर statistic सही है।
定比数据既有等间隔,又有真正的零点:0 表示“完全没有”。0 kg 是没有重量,0 分钟是没有时间,₹0 是没有钱。所以“12 kg 是 0.3 kg 的 40 倍”是真命题,所有统计量都有效。
The story — the parcel scaleकहानी — parcel का तराज़ू故事 — 包裹秤
The heaviest parcel today weighs 12 kg and the lightest 0.3 kg. Weigh them in pounds instead (26.5 lb and 0.66 lb) and the heaviest is still 40 times the lightest. Changing the unit of ratio data only multiplies every value by the same number, so ratios survive.
आज का सबसे भारी parcel 12 kg का है और सबसे हल्का 0.3 kg का। इन्हें pounds में तौलें (26.5 lb और 0.66 lb), तब भी सबसे भारी, सबसे हल्के का 40 गुना है। Ratio data का unit बदलने से हर value बस एक ही संख्या से गुणा होती है, इसलिए ratios बचे रहते हैं।
今天最重的包裹 12 kg,最轻的 0.3 kg。换成磅来称(26.5 lb 和 0.66 lb),最重的依然是最轻的 40 倍。改变定比数据的单位只是把每个值乘以同一个数,所以比值保持不变。
- All of the aboveऊपर के सारे以上全部
- Ratios ("twice as heavy")Ratios ("दोगुना भारी")比值(“重一倍”)
- Geometric meanGeometric mean几何平均
- Coefficient of variation (SD ÷ mean)Coefficient of variation (SD ÷ mean)变异系数(标准差 ÷ 均值)
- Nothing is off-limits mathematicallyगणित के हिसाब से कुछ भी मना नहीं数学上没有禁区
- (still check skew and outliers!)(फिर भी skew और outliers देखें!)(仍要检查偏斜和离群点!)
- Weight, height, distanceWeight, height, distance重量、身高、距离
- Income, price, salesIncome, price, sales收入、价格、销量
- Age in years, durationsसाल में age, durations年龄、时长
- Counts, temperature in KelvinCounts, Kelvin में तापमान计数、开尔文温度
import numpy as np
from scipy.stats import gmean
weights = np.array([0.5, 1.2, 4.8, 0.3, 12.0]) # kg - ratio data
print("Mean:", round(weights.mean(), 2), "kg")
print("Heaviest / lightest:", weights.max() / weights.min(), "times")
print("Geometric mean:", round(gmean(weights), 3), "kg")
print("Coefficient of variation:", round(weights.std(ddof=1) / weights.mean(), 2))
# CV on interval data changes with the unit -> meaningless
temps_c = np.array([-5, 0, 12, 18, 25])
temps_f = temps_c * 9 / 5 + 32
cv = lambda x: x.std(ddof=1) / x.mean()
print("CV of temperature in °C:", round(cv(temps_c), 2), "| in °F:", round(cv(temps_f), 2))
CV = SD ÷ mean compares spread to size. On ratio data it is unit-free: the CV of weights is the same in kg or pounds. On interval data it is nonsense: the same five temperatures give CV 1.24 in °C and 0.45 in °F, and if the mean were 0 °C the CV would be infinite.
CV = SD ÷ mean फैलाव को आकार से तुलना करता है। Ratio data पर यह unit-free है: weights का CV kg या pounds में एक ही है। Interval data पर यह बेमतलब है: वही पाँच तापमान °C में CV 1.24 और °F में 0.45 देते हैं, और अगर mean 0 °C होता तो CV अनंत हो जाता।
CV = 标准差 ÷ 均值,用来比较离散程度和数值大小。在定比数据上它与单位无关:重量的 CV 用 kg 还是磅都一样。在定距数据上它毫无意义:同样五个温度,用 °C 算 CV 是 1.24,用 °F 算是 0.45;如果均值恰好是 0 °C,CV 会变成无穷大。
Test Yourselfख़ुद को परखें自我测验
Pick a data type. Python will happily compute every number — the table shows which ones actually mean something.
एक data type चुनें। Python हर संख्या ख़ुशी से निकाल देगा — table दिखाती है कि असल में किनका मतलब है।
选择一种数据类型。Python 会乐呵呵地算出每个数字 —— 表格告诉你哪些真正有意义。
Read the column name and sample values, then pick its level of measurement. Some are tricky on purpose.
Column का नाम और sample values पढ़ें, फिर उसका level of measurement चुनें। कुछ जानबूझकर मुश्किल हैं।
阅读列名和示例值,然后选出它的测量尺度。有几道题故意设了陷阱。
Numbers that are names (PIN codes, IDs, jersey numbers) are nominal. Grouped numbers (age groups 18–25, 26–35…) become ordinal. Ranks (1st, 2nd, 3rd) are ordinal even though they look like counts. Counts (items, visits) are ratio. And the same quantity can change level with its unit: temperature in °C is interval, in Kelvin it is ratio.
नाम वाली संख्याएँ (PIN codes, IDs, jersey numbers) nominal हैं। Group की गई संख्याएँ (age groups 18–25, 26–35…) ordinal बन जाती हैं। Ranks (1st, 2nd, 3rd) ordinal हैं, भले ही गिनती जैसे दिखें। Counts (items, visits) ratio हैं। और एक ही मात्रा का level unit के साथ बदल सकता है: °C में तापमान interval है, Kelvin में ratio.
作为名称的数字(邮编、编号、球衣号码)是定类。分组后的数字(年龄段 18–25、26–35…)变成定序。名次(第 1、2、3 名)看起来像计数,但属于定序。计数(件数、访问次数)是定比。同一个量还可能随单位改变尺度:°C 温度是定距,开尔文温度是定比。
Data Types in Python and Machine LearningPython और Machine Learning में Data TypesPython 与机器学习中的数据类型
pandas dtypes do not tell you the levelpandas dtypes level नहीं बतातेpandas 的 dtype 不会告诉你尺度
import pandas as pd
orders = pd.DataFrame({
'customer_id': [10231, 10232, 10233, 10234],
'pin_code': [110001, 400001, 560001, 700001],
'stars': [5, 3, 4, 1],
'weight_kg': [0.5, 1.2, 4.8, 0.3],
})
print(orders.dtypes)
print(orders.describe().loc[['mean', 'std']].round(1))
pandas sees four numeric columns and happily reports a mean customer ID and a mean PIN code. The dtype (int64) describes how the value is stored, not what it means. Only you can decide that a PIN code is nominal and stars are ordinal.
pandas चार numeric columns देखता है और ख़ुशी से mean customer ID और mean PIN code बता देता है। Dtype (int64) बताता है कि value कैसे रखी गई है, यह नहीं कि उसका मतलब क्या है। PIN code nominal है और stars ordinal — यह सिर्फ़ आप तय कर सकते हैं।
pandas 看到四个数值列,就乐呵呵地报告了平均客户编号和平均邮编。dtype(int64)描述的是值如何存储,而不是它代表什么。只有你能判断邮编是定类、星级是定序。
Encoding categories for a modelModel के लिए categories को encode करना为模型编码类别
import pandas as pd
from sklearn.preprocessing import OrdinalEncoder
df = pd.DataFrame({
'region': ['North', 'South', 'East', 'West'],
'size': ['S', 'L', 'M', 'XL'],
})
# Nominal -> one-hot (no fake order)
print(pd.get_dummies(df['region'], dtype=int))
# Ordinal -> ordered integer codes (YOU give the order)
enc = OrdinalEncoder(categories=[['S', 'M', 'L', 'XL']])
df['size_code'] = enc.fit_transform(df[['size']]).astype(int)
print(df[['size', 'size_code']])
# Without categories=, the order is alphabetical - wrong for sizes
print(OrdinalEncoder().fit(df[['size']]).categories_[0])
Without categories=, OrdinalEncoder sorts the labels alphabetically: L, M, S, XL — so "L" gets code 0 and "S" gets code 2. Always pass the true order for ordinal data. For nominal data, use one-hot encoding (or let tree models handle categories natively), so the model does not invent an order.
categories= के बिना OrdinalEncoder labels को alphabetical क्रम में रखता है: L, M, S, XL — यानी "L" को code 0 और "S" को code 2 मिलता है। Ordinal data के लिए हमेशा असली क्रम दें। Nominal data के लिए one-hot encoding इस्तेमाल करें (या tree models को categories सीधे संभालने दें), ताकि model कोई क्रम न गढ़े।
不传 categories= 时,OrdinalEncoder 会按字母排序:L、M、S、XL —— 于是“L”编码为 0,“S”编码为 2。对定序数据,一定要传入真实顺序。对定类数据,使用独热编码(或让树模型直接处理类别),这样模型就不会凭空编造顺序。
Regions have no order. See how codes 1–4 make some regions look "closer" than others, and how shuffling the codes changes those distances. Then switch to one-hot.
Regions का कोई क्रम नहीं। देखें कि codes 1–4 कुछ regions को दूसरों से "पास" कैसे दिखाते हैं, और codes shuffle करने से ये दूरियाँ कैसे बदलती हैं। फिर one-hot पर जाएँ।
地区没有顺序。看看 1–4 的编码如何让某些地区显得比别的“更近”,以及打乱编码后这些距离如何改变。然后切换到独热编码。
Cheat sheet — what to use for each typeCheat sheet — हर type के लिए क्या इस्तेमाल करें速查表 — 每种类型该用什么
| TypeType类型 | CentreCentre集中趋势 | SpreadSpread离散程度 | ChartChart图表 | ML encodingML encoding机器学习编码 |
|---|---|---|---|---|
| Nominal | ModeMode众数 | Counts / % per categoryहर category के counts / %各类计数 / 占比 | Bar chartBar chart条形图 | One-hotOne-hot独热编码 |
| Ordinal | Median, modeMedian, mode中位数、众数 | Percentiles, full distributionPercentiles, पूरा distribution百分位数、完整分布 | Ordered bar chart, stacked barOrdered bar chart, stacked bar有序条形图、堆积条形图 | Ordinal codes in the true orderअसली क्रम में ordinal codes按真实顺序的序号编码 |
| Interval | Mean, medianMean, median均值、中位数 | SD, IQRSD, IQR标准差、IQR | Histogram, box plot, lineHistogram, box plot, line直方图、箱线图、折线图 | Use as a number (scale if needed)संख्या के रूप में (ज़रूरत हो तो scale करें)直接作为数值(必要时缩放) |
| Ratio | Mean, median, geometric meanMean, median, geometric mean均值、中位数、几何平均 | SD, IQR, CVSD, IQR, CV标准差、IQR、变异系数 | Histogram, box plot (log scale if skewed)Histogram, box plot (skewed हो तो log scale)直方图、箱线图(偏斜时用对数轴) | Use as a number (log if skewed)संख्या के रूप में (skewed हो तो log)直接作为数值(偏斜时取对数) |
Golden RulesGolden Rules黄金法则
int64 proves nothing.int64 dtype कुछ साबित नहीं करता।int64 dtype 什么也证明不了。