The Story That Explains Standard Deviationवह कहानी जो Standard Deviation समझाती है一个讲清标准差的故事
You are a quality control manager at a biscuit factory. Every biscuit should weigh exactly 20 grams. At the end of the day, two machines have both made biscuits with a mean weight of 20 g. Your boss is happy. But you check the individual weights.
आप एक biscuit factory में quality control manager हैं। हर biscuit का वज़न ठीक 20 grams होना चाहिए। दिन के अंत में दोनों machines के biscuits का mean वज़न 20 g है। आपके boss ख़ुश हैं। पर आप एक-एक biscuit का वज़न जाँचते हैं।
你是一家饼干厂的质检经理。每块饼干都应该正好重 20 克。一天结束时,两台机器生产的饼干平均重量都是 20 g。 老板很满意。但你去查看了每块饼干的重量。
| BiscuitBiscuit饼干 | Machine A (g)Machine A (g)机器 A(g) | Machine B (g)Machine B (g)机器 B(g) |
|---|---|---|
| 1 | 19.8 | 14.0 |
| 2 | 20.1 | 26.0 |
| 3 | 20.0 | 18.0 |
| 4 | 19.9 | 22.0 |
| 5 | 20.2 | 20.0 |
Machine A: mean = 20 g, standard deviation = 0.16 g — nearly perfect every time.
Machine B: mean = 20 g, standard deviation = 4.47 g — all over the place.
Machine A: mean = 20 g, standard deviation = 0.16 g — हर बार लगभग perfect.
Machine B: mean = 20 g, standard deviation = 4.47 g — पूरी तरह बिखरा हुआ।
机器 A:均值 = 20 g,标准差 = 0.16 g —— 几乎每次都完美。
机器 B:均值 = 20 g,标准差 = 4.47 g —— 忽大忽小。
A 14 g biscuit is underweight — customers complain. A 26 g biscuit breaks the packet and wastes ingredients. The mean looks fine, but the standard deviation shows that Machine B is broken. This is why standard deviation is at the heart of quality-control methods such as Six Sigma, used by many large manufacturers.
14 g का biscuit कम वज़न का है — customers शिकायत करते हैं। 26 g का biscuit packet तोड़ देता है और सामग्री बर्बाद करता है। Mean ठीक दिखता है, पर standard deviation बताता है कि Machine B ख़राब है। इसीलिए standard deviation Six Sigma जैसे quality-control तरीकों का केंद्र है, जिन्हें कई बड़े manufacturers इस्तेमाल करते हैं।
14 g 的饼干分量不足 —— 顾客会投诉;26 g 的饼干会撑破包装、浪费原料。均值看起来没问题,但标准差揭示了机器 B 坏了。 这就是为什么标准差是 六西格玛(Six Sigma)等质量控制方法的核心,许多大型制造企业都在使用。
Each machine makes biscuits around 20 g. Anything outside 19–21 g is rejected (red). Change Machine B's standard deviation and press Play.
हर machine 20 g के आसपास biscuits बनाती है। 19–21 g से बाहर का हर biscuit reject होता है (लाल)। Machine B का standard deviation बदलें और Play दबाएँ।
每台机器生产约 20 g 的饼干,超出 19–21 g 的都算不合格(红色)。调整机器 B 的标准差,然后点击播放。
What Standard Deviation Actually MeansStandard Deviation का असली मतलब标准差到底是什么意思
Standard deviation answers one simple question: "How far are the values from the mean, typically?" Small SD = values bunch together. Large SD = values spread out.
Standard deviation एक आसान सवाल का जवाब देता है: "Values आमतौर पर mean से कितनी दूर हैं?" छोटा SD = values पास-पास। बड़ा SD = values फैली हुई।
标准差回答一个简单的问题:“数值通常离均值有多远?”标准差小 = 数值挤在一起;标准差大 = 数值很分散。
Standard deviation is the square root of variance. That one step brings the unit back to the unit of your data. Machine A's variance is 0.025 g² — hard to picture. Its standard deviation is 0.16 g, so you can say "the biscuits typically differ from 20 g by about 0.16 g". (Strictly, SD is the root-mean-square distance from the mean, so it is a little larger than the plain average distance — the next simulator shows both.)
Standard deviation variance का square root है। यह एक कदम unit को आपके data की unit में वापस ले आता है। Machine A का variance 0.025 g² है — समझना मुश्किल। इसका standard deviation 0.16 g है, तो आप कह सकते हैं "biscuits आमतौर पर 20 g से लगभग 0.16 g अलग होते हैं"। (सटीक रूप से, SD mean से root-mean-square दूरी है, इसलिए यह सीधी औसत दूरी से थोड़ा बड़ा होता है — अगला simulator दोनों दिखाता है।)
标准差就是方差的平方根。这一步把单位变回了数据本身的单位。机器 A 的方差是 0.025 g² —— 很难想象;它的标准差是 0.16 g,于是你可以说“饼干通常与 20 g 相差约 0.16 g”。 (严格地说,标准差是到均值距离的均方根,所以比普通的平均距离略大 —— 下一个模拟器会同时显示两者。)
The 8 exam scores from the next section. Blue dots are inside mean ± 1 SD, red dots outside. Drag a score far away, or add a 20, and see how the SD reacts.
अगले section के 8 exam scores. नीले dots mean ± 1 SD के अंदर हैं, लाल बाहर। किसी score को दूर खींचें, या 20 जोड़ें, और देखें SD कैसे बदलता है।
下一节的 8 个考试分数。蓝点在均值 ± 1 个标准差以内,红点在外面。把某个分数拖远一点,或加一个 20 分,看看标准差如何变化。
Step-by-Step CalculationStep-by-Step गणना分步计算
Dataset — exam scores of 8 students: [52, 74, 68, 90, 61, 85, 72, 78]
Dataset — 8 students के exam scores: [52, 74, 68, 90, 61, 85, 72, 78]
数据集 —— 8 名学生的考试分数:[52, 74, 68, 90, 61, 85, 72, 78]
(52 + 74 + 68 + 90 + 61 + 85 + 72 + 78) / 8 = 580 / 8 = 72.5
(52 + 74 + 68 + 90 + 61 + 85 + 72 + 78) / 8 = 580 / 8 = 72.5
(52 + 74 + 68 + 90 + 61 + 85 + 72 + 78) / 8 = 580 / 8 = 72.5
(52−72.5)² = 420.25 (74−72.5)² = 2.25 (68−72.5)² = 20.25 (90−72.5)² = 306.25
(61−72.5)² = 132.25 (85−72.5)² = 156.25 (72−72.5)² = 0.25 (78−72.5)² = 30.25
(52−72.5)² = 420.25 (74−72.5)² = 2.25 (68−72.5)² = 20.25 (90−72.5)² = 306.25
(61−72.5)² = 132.25 (85−72.5)² = 156.25 (72−72.5)² = 0.25 (78−72.5)² = 30.25
(52−72.5)² = 420.25 (74−72.5)² = 2.25 (68−72.5)² = 20.25 (90−72.5)² = 306.25
(61−72.5)² = 132.25 (85−72.5)² = 156.25 (72−72.5)² = 0.25 (78−72.5)² = 30.25
420.25 + 2.25 + 20.25 + 306.25 + 132.25 + 156.25 + 0.25 + 30.25 = 1068
420.25 + 2.25 + 20.25 + 306.25 + 132.25 + 156.25 + 0.25 + 30.25 = 1068
420.25 + 2.25 + 20.25 + 306.25 + 132.25 + 156.25 + 0.25 + 30.25 = 1068
1068 / (8 − 1) = 1068 / 7 = 152.57
1068 / (8 − 1) = 1068 / 7 = 152.57
1068 / (8 − 1) = 1068 / 7 = 152.57
√152.57 = 12.35
√152.57 = 12.35
√152.57 = 12.35
The mean score is 72.5 and the standard deviation is 12.35 marks: a typical student is about 12 marks above or below the mean. The band mean ± 1 SD is 60.2 to 84.9, and 5 of the 8 students (61, 68, 72, 74, 78) are inside it.
Mean score 72.5 है और standard deviation 12.35 marks: एक आम student mean से लगभग 12 marks ऊपर या नीचे है। Mean ± 1 SD की पट्टी 60.2 से 84.9 है, और 8 में से 5 students (61, 68, 72, 74, 78) इसके अंदर हैं।
平均分是 72.5,标准差是 12.35 分:一个典型学生大约比均值高或低 12 分。 均值 ± 1 个标准差的范围是 60.2 到 84.9,8 名学生中有 5 名(61、68、72、74、78)落在其中。
Python ImplementationPython ImplementationPython 实现
Manual calculationहाथ से गणना手动计算
scores = [52, 74, 68, 90, 61, 85, 72, 78]
n = len(scores)
mean = sum(scores) / n
squared_diffs = [(x - mean) ** 2 for x in scores]
variance = sum(squared_diffs) / (n - 1)
std_dev = variance ** 0.5
print(f"Mean: {mean}")
print(f"Variance: {variance:.2f}")
print(f"Std Dev: {std_dev:.2f}")
Using the statistics modulestatistics module से使用 statistics 模块
import statistics
scores = [52, 74, 68, 90, 61, 85, 72, 78]
print(statistics.mean(scores)) # mean
print(round(statistics.variance(scores), 2)) # sample variance (n - 1)
print(round(statistics.stdev(scores), 2)) # sample std dev
print(round(statistics.pstdev(scores), 2)) # population std dev (n)
Using NumPyNumPy से使用 NumPy
import numpy as np
scores = [52, 74, 68, 90, 61, 85, 72, 78]
print(np.mean(scores))
print(np.std(scores, ddof=1).round(2)) # sample std dev
print(np.std(scores).round(2)) # population std dev — NumPy's default!
print(np.var(scores, ddof=1).round(2)) # sample variance
np.std() divides by n unless you write ddof=1: 11.55 instead of 12.35 here. pandas .std() uses ddof=1 by default, and scikit-learn's StandardScaler uses ddof=0. Write ddof explicitly so everyone knows which one you mean.
np.std() n से भाग देता है जब तक आप ddof=1 न लिखें: यहाँ 12.35 की जगह 11.55. pandas .std() default में ddof=1 लेता है, और scikit-learn का StandardScaler ddof=0. ddof साफ़ लिखें ताकि सबको पता हो कि आपका मतलब कौन सा है।
除非写 ddof=1,否则 np.std() 除以 n:这里得到 11.55 而不是 12.35。pandas 的 .std() 默认 ddof=1,scikit-learn 的 StandardScaler 用的是 ddof=0。请显式写出 ddof,让大家都知道你用的是哪一个。
Complete comparison — the two machinesपूरी तुलना — दोनों machines完整对比 —— 两台机器
import numpy as np
machine_a = [19.8, 20.1, 20.0, 19.9, 20.2]
machine_b = [14.0, 26.0, 18.0, 22.0, 20.0]
for name, data in [("Machine A", machine_a), ("Machine B", machine_b)]:
mean = np.mean(data)
variance = np.var(data, ddof=1)
std_dev = np.std(data, ddof=1)
print(f"{name}: mean={mean:.1f} g variance={variance:.3f} g² std_dev={std_dev:.2f} g")
The 68 – 95 – 99.7 Rule68 – 95 – 99.7 नियम68 – 95 – 99.7 法则
When data follows a normal distribution (bell curve), the standard deviation tells you what share of values falls in any range. This is the Empirical Rule.
जब data normal distribution (bell curve) पर चलता है, तो standard deviation बताता है कि किसी भी range में कितनी values आती हैं। इसे Empirical Rule कहते हैं।
当数据服从正态分布(钟形曲线)时,标准差能告诉你任意区间内有多少比例的数值。这就是经验法则(Empirical Rule)。
- About 68% of valuesलगभग 68% values约 68% 的数值
- The "normal" range"आम" range“正常”范围
- Mean ± 1 SDMean ± 1 SD均值 ± 1 个标准差
- About 95% of valuesलगभग 95% values约 95% 的数值
- Covers almost everyoneलगभग सबको शामिल करता है几乎涵盖所有人
- Mean ± 2 SDMean ± 2 SD均值 ± 2 个标准差
- About 99.7% of valuesलगभग 99.7% values约 99.7% 的数值
- Beyond = very unusualइससे बाहर = बहुत असामान्य超出 = 非常罕见
- Mean ± 3 SDMean ± 3 SD均值 ± 3 个标准差
Real Example — Adult Heightsअसली उदाहरण — वयस्कों की ऊँचाई真实例子 — 成年人身高
Take adult heights that follow a normal distribution with mean = 175 cm and standard deviation = 7 cm (a common textbook approximation for adult men).
वयस्कों की ऊँचाई लें जो mean = 175 cm और standard deviation = 7 cm वाले normal distribution पर चलती है (वयस्क पुरुषों के लिए एक आम textbook अनुमान)।
假设成年人身高服从均值 = 175 cm、标准差 = 7 cm 的正态分布(这是教科书中对成年男性常用的近似)。
| RangeRange范围 | Calculationगणना计算 | Heightsऊँचाई身高 | % of men% पुरुष男性占比 |
|---|---|---|---|
| ±1σ | 175 ± 7 | 168 – 182 cm | 68.3% |
| ±2σ | 175 ± 14 | 161 – 189 cm | 95.4% |
| ±3σ | 175 ± 21 | 154 – 196 cm | 99.7% |
| Beyond ±3σ±3σ से बाहर超出 ±3σ | — | <154 cm or >196 cm<154 cm या >196 cm<154 cm 或 >196 cm | 0.3% |
from scipy.stats import norm
mean, std_dev = 175, 7 # cm
for k in (1, 2, 3):
lo, hi = mean - k * std_dev, mean + k * std_dev
share = norm.cdf(hi, mean, std_dev) - norm.cdf(lo, mean, std_dev)
print(f"±{k}σ: {lo} – {hi} cm → {share:.2%} of men")
# Any other range works too, e.g. taller than 190 cm:
print(f"Taller than 190 cm: {norm.sf(190, mean, std_dev):.2%}")
Pick ±1σ, ±2σ or ±3σ and change the mean and SD. "Draw 1,000 people" checks the rule on random data. Then switch to skewed data with the same mean and SD — the rule breaks.
±1σ, ±2σ या ±3σ चुनें और mean व SD बदलें। "1,000 लोग निकालें" random data पर नियम जाँचता है। फिर उसी mean और SD वाले skewed data पर जाएँ — नियम टूट जाता है।
选择 ±1σ、±2σ 或 ±3σ,并调整均值和标准差。“随机抽 1,000 人”会在随机数据上检验这条法则。然后切换到均值和标准差相同的偏斜数据 —— 法则就失效了。
Standard Deviation in Machine LearningMachine Learning में Standard Deviation机器学习中的标准差
Standard deviation is not just a statistics idea — it powers several machine-learning tools you will use every day.
Standard deviation सिर्फ़ statistics का विचार नहीं — यह कई machine-learning औज़ारों को चलाता है जो आप रोज़ इस्तेमाल करेंगे।
标准差不只是统计学概念 —— 它支撑着你每天都会用到的多种机器学习工具。
Z-scores and StandardScalerZ-scores और StandardScalerZ 分数与 StandardScaler
Many algorithms (SVM, KNN, neural networks, PCA) are sensitive to the scale of features. StandardScaler turns each feature into z-scores: mean 0 and standard deviation 1. A z-score says "how many SDs away from the mean" — so values in different units become comparable.
कई algorithms (SVM, KNN, neural networks, PCA) features के scale से प्रभावित होते हैं। StandardScaler हर feature को z-scores में बदलता है: mean 0 और standard deviation 1. Z-score बताता है "mean से कितने SD दूर" — इसलिए अलग units की values की तुलना हो सकती है।
很多算法(SVM、KNN、神经网络、PCA)对特征的尺度很敏感。StandardScaler 把每个特征转换成 z 分数:均值 0、标准差 1。z 分数表示“离均值有几个标准差” —— 于是不同单位的数值也能放在一起比较。
Maths: class mean 70. English: class mean 80. Set the student's scores and each class's SD. Raw marks cannot be compared directly — z-scores can.
Maths: class mean 70. English: class mean 80. Student के scores और हर class का SD set करें। सीधे marks की तुलना नहीं हो सकती — z-scores की हो सकती है।
数学:班级平均 70 分。英语:班级平均 80 分。设置学生的分数和每个班的标准差。原始分数无法直接比较 —— z 分数可以。
import numpy as np
from sklearn.preprocessing import StandardScaler
# Two features on very different scales: height (cm) and weight (kg)
X = np.array([[160, 55], [175, 70], [180, 80], [155, 50], [190, 95]])
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
print("Means used :", scaler.mean_)
print("SDs used :", scaler.scale_.round(2)) # population SD (ddof=0)
print("Scaled data:\n", X_scaled.round(2))
print("New means :", X_scaled.mean(axis=0).round(2) + 0.0)
print("New SDs :", X_scaled.std(axis=0).round(2))
Both columns now have mean 0 and SD 1, so height (cm) and weight (kg) count equally in distance-based models. Note that StandardScaler divides by the population SD (12.88 for height, not the sample SD 14.40).
अब दोनों columns का mean 0 और SD 1 है, इसलिए distance-based models में height (cm) और weight (kg) बराबर गिने जाते हैं। ध्यान दें कि StandardScaler population SD से भाग देता है (height के लिए 12.88, sample SD 14.40 नहीं)।
现在两列的均值都是 0、标准差都是 1,所以在基于距离的模型里,身高(cm)和体重(kg)的分量相同。注意 StandardScaler 除的是总体标准差(身高为 12.88,而不是样本标准差 14.40)。
Anomaly Detection — and a TrapAnomaly Detection — और एक जाल异常检测 —— 以及一个陷阱
A common rule: flag any value more than 3 standard deviations from the mean. Let us test it on server response times with one obvious problem (500 ms).
एक आम नियम: mean से 3 standard deviations से ज़्यादा दूर वाली हर value को flag करें। चलिए इसे server response times पर आज़माएँ जिनमें एक साफ़ समस्या है (500 ms)।
一条常见规则:离均值超过 3 个标准差的值都标记为异常。我们在服务器响应时间上试一试,其中有一个明显的问题(500 ms)。
import numpy as np
# Server response times (ms)
response_times = np.array([120, 118, 122, 119, 121, 120, 118, 500, 123, 119])
mean = response_times.mean()
std_dev = response_times.std(ddof=1)
print(f"Mean: {mean:.1f} ms")
print(f"Std Dev: {std_dev:.1f} ms")
# Naive rule: anything above mean + 3 std devs is an anomaly
threshold = mean + 3 * std_dev
print(f"Threshold: {threshold:.1f} ms")
print("Anomalies detected:", response_times[response_times > threshold].tolist())
The 500 ms value pulls the mean up to 158 ms and inflates the SD to 120 ms, so the threshold becomes 518 ms — and the outlier hides behind its own effect. This is called masking. It is common with small samples: with only 10 points, one value can never be more than about 2.85 SDs from the mean, however extreme it is.
500 ms वाली value mean को 158 ms तक खींच लेती है और SD को 120 ms तक बढ़ा देती है, इसलिए threshold 518 ms हो जाता है — और outlier अपने ही असर के पीछे छिप जाता है। इसे masking कहते हैं। छोटे samples में यह आम है: सिर्फ़ 10 points में कोई भी value mean से लगभग 2.85 SDs से ज़्यादा दूर हो ही नहीं सकती, चाहे वह कितनी भी extreme हो।
500 ms 这个值把均值拉到 158 ms,把标准差撑到 120 ms,于是阈值变成 518 ms —— 离群点被它自己造成的影响掩盖了。这叫作掩蔽效应(masking)。 这在小样本中很常见:只有 10 个点时,无论某个值多极端,它离均值都不可能超过约 2.85 个标准差。
The fix: measure the centre and spread with statistics the outlier cannot move — the median and the MAD (median absolute deviation).
हल: केंद्र और फैलाव ऐसे statistics से मापें जिन्हें outlier हिला न सके — median और MAD (median absolute deviation)।
解决办法:用离群点撼动不了的统计量来衡量中心和离散程度 —— 中位数和 MAD(中位数绝对偏差)。
# Robust fix: use the median and the MAD (median absolute deviation),
# which the outlier cannot inflate.
median = np.median(response_times)
mad = np.median(np.abs(response_times - median))
robust_sd = 1.4826 * mad # MAD scaled to match the SD for normal data
robust_z = (response_times - median) / robust_sd
print(f"Median: {median:.1f} ms robust SD: {robust_sd:.2f} ms")
print("Robust z of 500 ms:", round(robust_z[response_times == 500][0], 1))
print("Anomalies detected:", response_times[np.abs(robust_z) > 3].tolist())
Move the slow response time. Red dashed band = mean ± 3 SD (classic). Green band = median ± 3 robust SD. A red dot is flagged by the robust rule; a thick black ring means the classic rule flags it too.
धीमे response time को खिसकाएँ। लाल dashed पट्टी = mean ± 3 SD (classic)। हरी पट्टी = median ± 3 robust SD. लाल dot को robust नियम पकड़ता है; मोटा काला घेरा मतलब classic नियम भी पकड़ता है।
移动那个慢响应时间。红色虚线带 = 均值 ± 3 个标准差(传统规则);绿色带 = 中位数 ± 3 个稳健标准差。红点表示被稳健规则标记;粗黑圈表示传统规则也标记了它。
Banks flag unusual transactions, hospitals flag abnormal lab results, and DevOps teams flag slow servers using exactly this idea: "how many SDs away from normal is this?" In practice they compute normal behaviour from a clean history (or with robust statistics), so a single incident cannot hide itself.
Banks असामान्य transactions पकड़ते हैं, hospitals असामान्य lab results, और DevOps teams धीमे servers — बिल्कुल इसी विचार से: "यह आम से कितने SD दूर है?" असल में वे आम व्यवहार साफ़ इतिहास से (या robust statistics से) निकालते हैं, ताकि एक अकेली घटना ख़ुद को छिपा न सके।
银行标记可疑交易、医院标记异常化验结果、运维团队标记慢服务器,用的都是这个思路:“它离正常值有几个标准差?”实际操作中,他们用干净的历史数据(或稳健统计量)来计算“正常”,这样单次事故就无法把自己藏起来。
Variance vs Standard Deviation — SummaryVariance vs Standard Deviation — सार方差 vs 标准差 — 总结
| Propertyगुण特性 | Variance | Standard Deviation |
|---|---|---|
| SymbolSymbol符号 | σ² / s² | σ / s |
| FormulaFormula公式 | Average of squared differencesSquared अंतरों का औसत平方差的平均 | Square root of varianceVariance का square root方差的平方根 |
| UnitUnit单位 | Squared (g², min²)Squared (g², min²)平方(g²、分钟²) | Same as the data (g, min)Data जैसी (g, min)与数据相同(g、分钟) |
| Easy to interpret?समझना आसान?容易解释? | Harderमुश्किल较难 | Easyआसान容易 |
| Used inकहाँ इस्तेमाल用于 | PCA, ANOVA, maths and proofsPCA, ANOVA, गणित और proofsPCA、ANOVA、数学推导 | Reporting, scaling, z-scores, quality controlReporting, scaling, z-scores, quality control报告、缩放、z 分数、质量控制 |
| Sensitive to outliers?Outliers का असर?对离群点敏感? | Yes, veryहाँ, बहुत是,非常 | Yesहाँ是 |
Golden RulesGolden Rules黄金法则
ddof=0 gives the population SD, which slightly underestimates the spread of a sample.ddof=0 population SD देता है, जो sample के फैलाव को थोड़ा कम आँकता है।ddof=0 给出总体标准差,会略微低估样本的离散程度。VarianceThreshold).VarianceThreshold)।VarianceThreshold)。