Foundations of Data Science 📂 Probability · 2 of 5 143 min read

Conditional Probability

A deeply comprehensive, story-driven tutorial on conditional probability — covering P(A|B) = P(A∩B)/P(B) with full intuition, five custom inline SVG diagrams (Venn, spam flow, factory tree, confusion matrix), four rich real-world applications (spam filtering with Naive Bayes, Netflix recommendations with lift calculation, medical diagnosis with base rate neglect, job interview hiring analysis), Simpson's Paradox, the Law of Total Probability, the Prosecutor's Fallacy, an 8-row ML applications ta

🌐
SectionSection第 01 节

The World Changes When You Know Something 🌍कुछ पता चलते ही दुनिया बदल जाती है 🌍知道一点信息,世界就变了 🌍

Monday morning. With no other information, you think there is a 10% chance your bus will be late. Then your phone shows a major accident on the main road. Now you think the chance is more like 75%. The bus has not changed. Your knowledge has changed — and the probability should change with it.

सोमवार की सुबह। बिना किसी और जानकारी के आप मानते हैं कि बस के लेट होने का 10% chance है। फिर फ़ोन पर ख़बर आती है कि मुख्य सड़क पर बड़ा हादसा हुआ है। अब आप chance को 75% के आसपास मानते हैं। बस नहीं बदली। आपकी जानकारी बदली है — और probability को भी उसके साथ बदलना चाहिए।

周一早上。没有其他信息时,你觉得公交迟到的概率是 10%。然后手机提示主干道发生了严重车祸,你觉得概率大约变成了 75%。公交车没变,变的是你掌握的信息 —— 概率也应随之改变。

This is conditional probability. It answers: "Given that I know B has happened, how likely is A?" It is written P(A | B) and read "the probability of A given B". The bar "|" means "given that". It powers medical diagnosis, spam filters, recommendations, the weighing of evidence in court, and Bayesian machine learning.

यही conditional probability है। यह बताती है: "जब पता है कि B हो चुका है, तो A कितना संभव है?" इसे P(A | B) लिखते हैं और पढ़ते हैं "B दिया हो तो A की probability"। खड़ी रेखा "|" का मतलब "दिया हो तो"। यह medical diagnosis, spam filters, recommendations, अदालत में सबूत तौलने और Bayesian machine learning को चलाती है।

这就是条件概率。它回答:“已知 B 已经发生,A 发生的可能性有多大?”记作 P(A | B),读作“在 B 条件下 A 的概率”。竖线“|”表示“已知”。医学诊断、垃圾邮件过滤、推荐系统、法庭证据评估和贝叶斯机器学习都依赖它。

💡
The One-Line Intuitionएक लाइन में समझ一句话直觉

Conditional probability shrinks the sample space. Once you learn B happened, outcomes outside B no longer matter. You zoom in on the world where B is true and ask: how much of that world also has A?

Conditional probability sample space को छोटा करती है। जैसे ही पता चलता है कि B हुआ, B के बाहर के नतीजे मायने नहीं रखते। आप उस दुनिया में zoom करते हैं जहाँ B सच है और पूछते हैं: उस दुनिया के कितने हिस्से में A भी है?

条件概率会缩小样本空间。一旦知道 B 发生了,B 之外的结果就不再重要。你把视野聚焦到 B 为真的世界,再问:这个世界中有多大比例也包含 A?


SectionSection第 02 节

The Definition & Formula 📐परिभाषा और Formula 📐定义与公式 📐

Why the Formula Is What It IsFormula ऐसा क्यों है公式为什么是这样

Given that B happened, we want the share of B's outcomes that also include A. That share is the overlap A ∩ B divided by all of B. This ratio is the definition.

B हुआ है, तो हम B के उन नतीजों का हिस्सा चाहते हैं जिनमें A भी है। वह हिस्सा है overlap A ∩ B भाग पूरा B। यही अनुपात परिभाषा है।

已知 B 发生,我们想知道 B 的结果中同时包含 A 的比例。这个比例就是重叠部分 A ∩ B 除以整个 B。这就是定义。

Core formulaमूल formula核心公式
P(A | B) = P(A ∩ B) / P(B)
P(A ∩ B) = chance both happen. P(B) = chance B happens. Defined only when P(B) > 0.
P(A ∩ B) = दोनों होने का chance। P(B) = B होने का chance। सिर्फ़ P(B) > 0 होने पर परिभाषित।
P(A ∩ B) = 两者同时发生的概率。P(B) = B 发生的概率。仅当 P(B) > 0 时有定义。
Rearranged: multiplication ruleपलटकर: multiplication rule变形:乘法法则
P(A ∩ B) = P(A | B) × P(B)
Multiply both sides by P(B). This is the multiplication rule for dependent events.
दोनों तरफ़ P(B) से गुणा करें। यही dependent events का multiplication rule है।
两边同乘 P(B),就是相依事件的乘法法则。
Direction mattersदिशा मायने रखती है方向很重要
P(A | B) ≠ P(B | A) in general
They share the numerator P(A ∩ B) but divide by different things. They are equal only when P(A) = P(B).
दोनों का numerator P(A ∩ B) एक है, पर भाग अलग चीज़ों से होता है। ये सिर्फ़ तब बराबर जब P(A) = P(B)।
二者分子都是 P(A ∩ B),但分母不同。只有当 P(A) = P(B) 时才相等。
Independence checkIndependence जाँच独立性检验
P(A | B) = P(A) ⟺ independent
If learning B does not change the chance of A, B carries no information about A (assuming P(B) > 0).
अगर B जानने से A का chance न बदले, तो B में A के बारे में कोई जानकारी नहीं (मानकर P(B) > 0)।
若得知 B 不改变 A 的概率,则 B 不含关于 A 的信息(假设 P(B) > 0)。

SectionSection第 03 节

Conditional Probability in Pictures — Understand Before the Maths 📊तस्वीरों में Conditional Probability — गणित से पहले समझें 📊图解条件概率 — 先理解,再算数 📊

We use a real table of 200 students (full details in the next section): 90 study Data Science (DS) and 72 of them passed; 110 study Business (BUS) and 66 of them passed. In the picture, area = number of students.

हम 200 छात्रों की असली table लेते हैं (पूरा विवरण अगले section में): 90 Data Science (DS) पढ़ते हैं और उनमें 72 pass हुए; 110 Business (BUS) पढ़ते हैं और उनमें 66 pass हुए। तस्वीर में area = छात्रों की संख्या।

我们用一个 200 名学生的真实表格(详见下一节):90 人学数据科学(DS),其中 72 人通过;110 人学商科(BUS),其中 66 人通过。图中面积 = 学生人数。

🔍 PICTURE 1 — CONDITIONING ZOOMS INतस्वीर 1 — CONDITIONING ZOOM करती है图 1 — 条件化就是放大
Conditioning zooms into one part of the sample space All 200 students (Ω)सभी 200 छात्र (Ω)全部 200 名学生(Ω) pass 72 fail 18 DS (90) pass 66 fail 44 BUS (110) given DSDS दिया हो已知 DS New world: 90 DS studentsनई दुनिया: 90 DS छात्र新世界:90 名 DS 学生 pass 72 / 90 = 80% fail 18 P(Pass | DS) = 0.80 Everything outside the dashed box is thrown away. The fraction is then taken inside it.Dashed box के बाहर सब हटा दिया जाता है। फिर fraction उसके अंदर लिया जाता है।虚线框外的一切都被舍弃,比例只在框内计算。
⇄ PICTURE 2 — SAME OVERLAP, DIFFERENT DENOMINATORतस्वीर 2 — वही OVERLAP, अलग DENOMINATOR图 2 — 同样的重叠,不同的分母
Same overlap, different denominators P(Pass | DS) 72 72 / 90 = 0.80 divide by the 90 DS students90 DS छात्रों से भाग除以 90 名 DS 学生 P(DS | Pass) 72 72 / 138 = 0.52 divide by the 138 students who passedpass हुए 138 छात्रों से भाग除以 138 名通过的学生 Purple = the same 72 students (DS AND passed). Only the denominator changes.बैंगनी = वही 72 छात्र (DS और pass)। सिर्फ़ denominator बदलता है।紫色 = 同样的 72 名学生(DS 且通过)。只有分母变了。
LIVELIVE互动Zoom Into the Condition — 200 Studentsशर्त में Zoom करें — 200 छात्र聚焦条件 — 200 名学生

Each dot is a student. Choose what you are given; everyone else disappears and the rest regroup. Then choose what you ask about. Try "given DS, ask passed" and then "given passed, ask DS".

हर बिंदु एक छात्र है। चुनें कि आपको क्या दिया गया है; बाक़ी सब ग़ायब होते हैं और बचे हुए फिर से जमते हैं। फिर चुनें कि सवाल क्या है। "DS दिया हो, pass पूछें" और फिर "pass दिया हो, DS पूछें" आज़माएँ।

每个点是一名学生。选择“已知”条件,其他人会消失,剩下的人重新排列。再选择要问的事件。试试“已知 DS,问通过”,再试“已知通过,问 DS”。

g
t


SectionSection第 04 节

Building Intuition — The Classroom Story 🎓समझ बनाना — Classroom की कहानी 🎓建立直觉 — 课堂故事 🎓

A college has 200 students. Each studies Data Science (DS) or Business (BUS), and each passed or failed the statistics exam:

एक college में 200 छात्र हैं। हर कोई Data Science (DS) या Business (BUS) पढ़ता है, और हर कोई statistics exam में pass या fail हुआ:

某学院有 200 名学生,每人学数据科学(DS)或商科(BUS),统计学考试要么通过要么未通过:

Passed ✅Pass ✅通过 ✅Failed ❌Fail ❌未通过 ❌Totalकुल合计
Data Science (DS)721890
Business (BUS)6644110
Totalकुल合计13862200
🧮 Six Questions on One Tableएक Table पर छह सवाल一张表上的六个问题
Q1
P(Pass) — no condition. 138/200 = 0.69
P(Pass) — कोई शर्त नहीं। 138/200 = 0.69
P(通过) —— 无条件。138/200 = 0.69
Q2
P(Pass | DS) — keep only the 90 DS students. 72/90 = 0.80
P(Pass | DS) — सिर्फ़ 90 DS छात्र रखें। 72/90 = 0.80
P(通过 | DS) —— 只保留 90 名 DS 学生。72/90 = 0.80
Q3
P(Pass | BUS) — keep only the 110 BUS students. 66/110 = 0.60
P(Pass | BUS) — सिर्फ़ 110 BUS छात्र रखें। 66/110 = 0.60
P(通过 | BUS) —— 只保留 110 名 BUS 学生。66/110 = 0.60
Q4
P(DS | Pass) — keep only the 138 who passed. 72/138 = 0.522. Same 72 on top as Q2, different bottom.
P(DS | Pass) — सिर्फ़ pass हुए 138 रखें। 72/138 = 0.522। ऊपर वही 72 जो Q2 में, नीचे अलग।
P(DS | 通过) —— 只保留 138 名通过者。72/138 = 0.522。分子与 Q2 相同(72),分母不同。
Q5
Check Q2 with the formula. P(Pass ∩ DS) = 72/200 = 0.36, P(DS) = 90/200 = 0.45, so 0.36/0.45 = 0.80 ✓
Formula से Q2 जाँचें। P(Pass ∩ DS) = 72/200 = 0.36, P(DS) = 90/200 = 0.45, तो 0.36/0.45 = 0.80 ✓
用公式验证 Q2。P(通过 ∩ DS) = 72/200 = 0.36,P(DS) = 90/200 = 0.45,所以 0.36/0.45 = 0.80 ✓
Q6
Independent? P(Pass) = 0.69 but P(Pass | DS) = 0.80. Not independent: knowing the major changes the pass chance. (This shows a link, not a cause — DS students may differ in other ways.)
Independent? P(Pass) = 0.69 पर P(Pass | DS) = 0.80। Independent नहीं: विषय जानने से pass का chance बदलता है। (यह संबंध दिखाता है, कारण नहीं — DS छात्र दूसरी बातों में भी अलग हो सकते हैं।)
独立吗?P(通过) = 0.69,而 P(通过 | DS) = 0.80。不独立:知道专业会改变通过的概率。(这只说明关联而非因果 —— DS 学生可能在其他方面也不同。)

SectionSection第 05 节

The Prosecutor's Fallacy — Swapping the Condition ⚖️Prosecutor's Fallacy — शर्त की अदला-बदली ⚖️检察官谬误 — 把条件弄反 ⚖️

A prosecutor says: "If the defendant were innocent, the chance of this DNA match would be 1 in a million. So the chance he is innocent is 1 in a million." This mixes up two different numbers. P(match | innocent) is 1 in a million. P(innocent | match) depends on how many other people could have left the DNA and on all the other evidence.

Prosecutor कहता है: "अगर आरोपी बेगुनाह होता, तो इस DNA match का chance 10 लाख में 1 होता। इसलिए उसके बेगुनाह होने का chance 10 लाख में 1 है।" यह दो अलग संख्याओं को मिला देता है। P(match | बेगुनाह) 10 लाख में 1 है। P(बेगुनाह | match) इस पर निर्भर है कि और कितने लोग DNA छोड़ सकते थे और बाक़ी सबूत क्या कहते हैं।

检察官说:“如果被告无辜,这次 DNA 匹配的概率只有百万分之一,所以他无辜的概率是百万分之一。”这把两个不同的数混为一谈。P(匹配 | 无辜) 是百万分之一;P(无辜 | 匹配) 则取决于还有多少人可能留下 DNA,以及其他所有证据。

In a city of 1 million possible people, about one innocent person is expected to match by chance, as well as the real culprit. With no other evidence, a match alone gives roughly 50/50 — nowhere near "1 in a million".

10 लाख संभावित लोगों के शहर में, असली अपराधी के अलावा लगभग एक बेगुनाह व्यक्ति के संयोग से match होने की उम्मीद है। कोई और सबूत न हो तो सिर्फ़ match से लगभग 50/50 मिलता है — "10 लाख में 1" के आसपास भी नहीं।

在有 100 万可能人选的城市里,除了真正的罪犯,预计还会有约 1 名无辜者偶然匹配。若没有其他证据,仅凭匹配大约是 50/50 —— 远不是“百万分之一”。

LIVELIVE互动The DNA Match — Prosecutor's FallacyDNA Match — Prosecutor's FallacyDNA 匹配 — 检察官谬误

Set how many people could have left the DNA and how rare a chance match is. Each red dot is an innocent person who would also match. Compare the two bars: they answer different questions.

चुनें कि कितने लोग DNA छोड़ सकते थे और संयोगवश match कितना दुर्लभ है। हर लाल बिंदु एक बेगुनाह व्यक्ति है जो match भी करेगा। दोनों bars की तुलना करें: ये अलग सवालों के जवाब हैं।

设置可能留下 DNA 的人数,以及偶然匹配有多罕见。每个红点是一名同样会匹配的无辜者。比较两根条:它们回答的是不同的问题。

⚠️
A Real Case: Sally Clark (UK)असली मामला: Sally Clark (UK)真实案例:萨莉·克拉克(英国)

In 1999 Sally Clark was convicted of murdering her two baby sons. An expert told the jury that two cot deaths in such a family had a chance of 1 in 73 million. That number wrongly assumed the two deaths were independent, and it was easily heard as "1 in 73 million that she is innocent" — the prosecutor's fallacy. The Royal Statistical Society publicly criticised the statistics, and her conviction was overturned in 2003.

1999 में Sally Clark को अपने दो शिशु बेटों की हत्या का दोषी ठहराया गया। एक विशेषज्ञ ने jury से कहा कि ऐसे परिवार में दो cot deaths का chance 7.3 करोड़ में 1 है। इस संख्या ने ग़लत माना कि दोनों मौतें independent थीं, और इसे आसानी से "बेगुनाह होने का chance 7.3 करोड़ में 1" समझा गया — prosecutor's fallacy। Royal Statistical Society ने इन आँकड़ों की खुलकर आलोचना की, और 2003 में उनकी सज़ा रद्द हुई।

1999 年,萨莉·克拉克被判谋杀两个幼子。一位专家告诉陪审团,这种家庭发生两次婴儿猝死的概率是 7,300 万分之一。这个数字错误地假设两次死亡相互独立,而且很容易被理解成“她无辜的概率是 7,300 万分之一”—— 正是检察官谬误。英国皇家统计学会公开批评了这一统计论证,她的定罪于 2003 年被撤销。


SectionSection第 06 节

Application 1 — Spam Filtering 📧उपयोग 1 — Spam Filtering 📧应用 1 — 垃圾邮件过滤 📧

The Story: A Simple Word-Based Filterकहानी: एक सरल शब्द-आधारित Filter故事:一个简单的关键词过滤器

You receive 1,000 emails a month: 200 spam and 800 real. Of the 200 spam emails, 160 contain the word "FREE". Of the 800 real ones, 40 do (sales, free webinars). An email arrives with "FREE". How likely is it to be spam? We need P(spam | FREE) — not P(FREE | spam) = 160/200 = 80%, which is the other direction.

आपको हर महीने 1,000 emails आते हैं: 200 spam और 800 असली। 200 spam में से 160 में "FREE" शब्द है। 800 असली में से 40 में (sales, free webinars)। "FREE" वाला email आता है। इसके spam होने का chance क्या है? हमें P(spam | FREE) चाहिए — P(FREE | spam) = 160/200 = 80% नहीं, जो उल्टी दिशा है।

你每月收到 1,000 封邮件:200 封垃圾、800 封正常。200 封垃圾中有 160 封含“FREE”,800 封正常邮件中有 40 封含它(促销、免费讲座)。一封含“FREE”的邮件到来,它是垃圾邮件的概率是多少?我们要的是 P(垃圾 | FREE),而不是反方向的 P(FREE | 垃圾) = 160/200 = 80%。

🧮 Spam Filter — P(spam | FREE)Spam Filter — P(spam | FREE)垃圾邮件过滤 — P(垃圾 | FREE)
SetupSetup设定
1,000 emails: 200 spam (20%), 800 real. "FREE" appears in 160 spam + 40 real = 200 emails.
1,000 emails: 200 spam (20%), 800 असली। "FREE" 160 spam + 40 असली = 200 emails में।
1,000 封:200 封垃圾(20%),800 封正常。含“FREE”的有 160 + 40 = 200 封。
FormulaFormula公式
P(spam | FREE) = P(spam ∩ FREE) / P(FREE) = 0.16 / 0.20 = 0.80
P(spam | FREE) = P(spam ∩ FREE) / P(FREE) = 0.16 / 0.20 = 0.80
P(垃圾 | FREE) = P(垃圾 ∩ FREE) / P(FREE) = 0.16 / 0.20 = 0.80
Insightसीख启示
Here both directions happen to equal 0.80, because "FREE" emails (200) and spam emails (200) are the same count. Change one number and they split apart — try it in the simulation.
यहाँ दोनों दिशाएँ संयोग से 0.80 हैं, क्योंकि "FREE" वाले emails (200) और spam emails (200) की गिनती बराबर है। एक संख्या बदलें और ये अलग हो जाते हैं — simulation में आज़माएँ।
这里两个方向恰好都等于 0.80,因为含“FREE”的邮件(200)与垃圾邮件(200)数量相同。改动一个数字它们就会分开 —— 在模拟中试试。
Naive Bayes
With several words, compute a score for each class and compare:
spam score = P(spam) × P(FREE | spam) × P(WINNER | spam)
real score = P(real) × P(FREE | real) × P(WINNER | real)
P(spam | both words) = spam score / (spam score + real score). Treating the words as independent within each class is the "naive" part, yet it works well in practice.
कई शब्दों के साथ हर class का score निकालें और तुलना करें:
spam score = P(spam) × P(FREE | spam) × P(WINNER | spam)
real score = P(real) × P(FREE | real) × P(WINNER | real)
P(spam | दोनों शब्द) = spam score / (spam score + real score)। हर class के अंदर शब्दों को independent मानना "naive" हिस्सा है, फिर भी यह व्यवहार में अच्छा काम करता है।
多个词时,为每个类别计算得分并比较:
垃圾得分 = P(垃圾) × P(FREE | 垃圾) × P(WINNER | 垃圾)
正常得分 = P(正常) × P(FREE | 正常) × P(WINNER | 正常)
P(垃圾 | 两个词) = 垃圾得分 / (垃圾得分 + 正常得分)。在每个类别内把词视为独立就是“朴素”之处,但实践中效果很好。
LIVELIVE互动Filter 1,000 Emails1,000 Emails Filter करें筛选 1,000 封邮件

Each square is one email (red = spam, green = real; a white dot means it contains FREE). Apply the filters and watch the world shrink. Then move the sliders: P(spam | FREE) moves away from P(FREE | spam).

हर खाना एक email है (लाल = spam, हरा = असली; सफ़ेद बिंदु = इसमें FREE है)। Filters लगाएँ और दुनिया को सिकुड़ते देखें। फिर sliders खिसकाएँ: P(spam | FREE), P(FREE | spam) से अलग हो जाता है।

每个方块是一封邮件(红 = 垃圾,绿 = 正常;白点表示含 FREE)。应用筛选,看世界缩小。再拖动滑块:P(垃圾 | FREE) 会与 P(FREE | 垃圾) 分开。


SectionSection第 07 节

Application 2 — Recommendation Systems 🎬उपयोग 2 — Recommendation Systems 🎬应用 2 — 推荐系统 🎬

An illustrative streaming platform has 100,000 users. 20,000 watched Movie A (a thriller), 10,000 watched Movie B (another thriller), and 7,000 watched both. Should it recommend B to someone who just finished A?

एक उदाहरण streaming platform पर 100,000 users हैं। 20,000 ने Movie A (thriller) देखी, 10,000 ने Movie B (दूसरी thriller), और 7,000 ने दोनों। क्या A ख़त्म करने वाले को B suggest करनी चाहिए?

假设一个流媒体平台有 100,000 名用户。20,000 人看过电影 A(惊悚片),10,000 人看过电影 B(另一部惊悚片),7,000 人两部都看过。应该向刚看完 A 的人推荐 B 吗?

🧮 Recommendation — Conditional LiftRecommendation — Conditional Lift推荐 — 条件提升度
Base ratesBase rates基础比率
P(A) = 0.20, P(B) = 0.10, P(A ∩ B) = 0.07
P(A) = 0.20, P(B) = 0.10, P(A ∩ B) = 0.07
P(A) = 0.20,P(B) = 0.10,P(A ∩ B) = 0.07
ConditionalConditional条件概率
P(B | A) = 0.07 / 0.20 = 0.35. P(A | B) = 0.07 / 0.10 = 0.70. Again, the two directions differ.
P(B | A) = 0.07 / 0.20 = 0.35। P(A | B) = 0.07 / 0.10 = 0.70। फिर से, दोनों दिशाएँ अलग।
P(B | A) = 0.07 / 0.20 = 0.35。P(A | B) = 0.07 / 0.10 = 0.70。两个方向再次不同。
Lift
Lift = P(B | A) / P(B) = 0.35 / 0.10 = 3.5×. A user who watched A is 3.5 times as likely as a random user to watch B. Lift above 1 means a useful signal.
Lift = P(B | A) / P(B) = 0.35 / 0.10 = 3.5×। A देखने वाले user के B देखने की संभावना random user से 3.5 गुना है। 1 से ऊपर lift मतलब काम का संकेत।
提升度 = P(B | A) / P(B) = 0.35 / 0.10 = 3.5×。看过 A 的用户看 B 的可能性是随机用户的 3.5 倍。提升度大于 1 就是有用的信号。
Independent?Independent?独立吗?
0.35 ≠ 0.10, so not independent. Watching A predicts watching B — that dependence is exactly what "people who watched this also watched…" uses.
0.35 ≠ 0.10, इसलिए independent नहीं। A देखना B देखने का अनुमान देता है — "जिन्होंने यह देखा उन्होंने यह भी देखा…" ठीक इसी dependence का इस्तेमाल करता है।
0.35 ≠ 0.10,所以不独立。看 A 能预测看 B ——“看过这部的人还看了……”正是利用了这种相依。
💡
Conditional Probability Behind "You Might Also Like""आपको यह भी पसंद आ सकता है" के पीछे Conditional Probability“猜你喜欢”背后的条件概率

Product suggestions, music playlists and video autoplay all estimate something like P(user engages with item X | the user's history). The models differ — co-occurrence counts, matrix factorisation, deep networks — but the question they answer is a conditional probability.

Product suggestions, music playlists और video autoplay सब कुछ ऐसा अनुमान लगाते हैं: P(user item X से जुड़ेगा | user का इतिहास)। Models अलग होते हैं — co-occurrence counts, matrix factorisation, deep networks — पर जिस सवाल का जवाब देते हैं वह conditional probability है।

商品推荐、音乐歌单和视频自动播放,都在估计类似 P(用户会与物品 X 互动 | 用户历史) 的量。模型各不相同 —— 共现计数、矩阵分解、深度网络 —— 但它们回答的问题都是条件概率。


SectionSection第 08 节

Application 3 — Medical Testing 🏥उपयोग 3 — Medical Testing 🏥应用 3 — 医学检测 🏥

A disease affects 2% of people aged 40–60. A new test has 92% sensitivity (it catches 92% of sick people) and 88% specificity (it clears 88% of healthy people). A 50-year-old tests positive. First instinct: "92% accurate — I almost surely have it." That ignores the base rate.

एक बीमारी 40–60 उम्र के 2% लोगों को होती है। नए test की sensitivity 92% है (92% बीमारों को पकड़ता है) और specificity 88% (88% स्वस्थ लोगों को साफ़ बताता है)। एक 50 साल के व्यक्ति का test positive आया। पहला ख़याल: "92% सटीक — मुझे लगभग पक्का बीमारी है।" यह base rate को नज़रअंदाज़ करता है।

某疾病在 40–60 岁人群中的患病率为 2%。新检测的灵敏度 92%(能查出 92% 的患者),特异度 88%(能排除 88% 的健康人)。一位 50 岁的人检测阳性。第一反应:“准确率 92%,我几乎肯定得病了。”这忽视了基础比率。

🧮 Medical Test — Step by StepMedical Test — क़दम दर क़दम医学检测 — 逐步计算
Givenदिया है已知
P(D) = 0.02, P(+ | D) = 0.92, P(+ | no D) = 0.12 (1 − 0.88)
P(D) = 0.02, P(+ | D) = 0.92, P(+ | D नहीं) = 0.12 (1 − 0.88)
P(D) = 0.02,P(+ | D) = 0.92,P(+ | 无 D) = 0.12(1 − 0.88)
Step 1Step 1第 1 步
P(+ ∩ D) = 0.92 × 0.02 = 0.0184
P(+ ∩ D) = 0.92 × 0.02 = 0.0184
P(+ ∩ D) = 0.92 × 0.02 = 0.0184
Step 2Step 2第 2 步
P(+ ∩ no D) = 0.12 × 0.98 = 0.1176
P(+ ∩ D नहीं) = 0.12 × 0.98 = 0.1176
P(+ ∩ 无 D) = 0.12 × 0.98 = 0.1176
Step 3Step 3第 3 步
P(+) = 0.0184 + 0.1176 = 0.136 (law of total probability)
P(+) = 0.0184 + 0.1176 = 0.136 (law of total probability)
P(+) = 0.0184 + 0.1176 = 0.136(全概率公式)
Resultनतीजा结果
P(D | +) = 0.0184 / 0.136 = 0.135 (13.5%)
P(D | +) = 0.0184 / 0.136 = 0.135 (13.5%)
P(D | +) = 0.0184 / 0.136 = 0.135(13.5%)
Verdictनिष्कर्ष结论
Only about a 13.5% chance of disease. The low 2% base rate dominates. The sensible next step is a confirmatory test, not immediate treatment.
बीमारी का सिर्फ़ लगभग 13.5% chance। कम 2% base rate हावी है। समझदारी भरा अगला क़दम पुष्टि वाला test है, तुरंत इलाज नहीं।
患病概率只有约 13.5%。2% 的低基础比率占主导。合理的下一步是做确认检查,而不是立即治疗。
🩺 PICTURE 3 — WHO ARE THE POSITIVES?तस्वीर 3 — POSITIVE कौन हैं?图 3 — 阳性者都是谁?
Of 136 positive tests per 1,000 people, about 18 are sick Per 1,000 people tested:हर 1,000 जाँचे गए लोगों में:每检测 1,000 人: 136 test positive136 positive आते हैं136 人检测阳性 ≈ 18 are sick (18.4)≈ 18 बीमार हैं (18.4)≈ 18 人真正患病(18.4) ≈ 118 are healthy (117.6)≈ 118 स्वस्थ हैं (117.6)≈ 118 人其实健康(117.6) P(sick | +) = 18.4 / 136 ≈ 13.5% Prevalence 2%, sensitivity 92%, specificity 88%Prevalence 2%, sensitivity 92%, specificity 88%患病率 2%,灵敏度 92%,特异度 88%

Each square is one positive test (per 1,000 people tested).

हर खाना एक positive test है (हर 1,000 जाँचे गए लोगों में)।

每个方块代表一个阳性结果(每检测 1,000 人)。

Has disease (20)बीमारी है (20)患病(20)No disease (980)बीमारी नहीं (980)未患病(980)Row totalपंक्ति कुल行合计
Test positiveTest positive检测阳性True positive: 18.4 (20 × 0.92)True positive: 18.4 (20 × 0.92)真阳性:18.4(20 × 0.92)False positive: 117.6 (980 × 0.12)False positive: 117.6 (980 × 0.12)假阳性:117.6(980 × 0.12)136
Test negativeTest negative检测阴性False negative: 1.6 (20 × 0.08)False negative: 1.6 (20 × 0.08)假阴性:1.6(20 × 0.08)True negative: 862.4 (980 × 0.88)True negative: 862.4 (980 × 0.88)真阴性:862.4(980 × 0.88)864
Column totalस्तंभ कुल列合计209801,000
⚠️
Base-Rate Neglect — Even Experts Fall for ItBase-Rate Neglect — विशेषज्ञ भी फँसते हैं忽视基础比率 — 专家也会中招

People hear "92% accurate" and think "92% chance I am sick". This is base-rate neglect. In a classic 1978 study, 60 Harvard medical students and doctors were asked about a disease with prevalence 1 in 1,000 and a 5% false-positive rate. The correct answer is about 2%, but the most common answer was 95%, and only 11 of the 60 got it right.

लोग "92% सटीक" सुनकर सोचते हैं "मेरे बीमार होने का chance 92% है"। यह base-rate neglect है। 1978 की एक मशहूर study में Harvard के 60 medical छात्रों और doctors से 1,000 में 1 prevalence और 5% false-positive दर वाली बीमारी के बारे में पूछा गया। सही जवाब लगभग 2% है, पर सबसे आम जवाब 95% था, और 60 में से सिर्फ़ 11 सही थे।

人们听到“准确率 92%”就以为“我有 92% 的概率患病”。这就是忽视基础比率。在 1978 年的一项经典研究中,研究者向哈佛的 60 名医学生和医生提问:某病患病率为千分之一,假阳性率 5%。正确答案约 2%,但最常见的回答是 95%,60 人中只有 11 人答对。


SectionSection第 09 节

Application 4 — The Hiring Decision 🎯उपयोग 4 — Hiring का फ़ैसला 🎯应用 4 — 招聘决策 🎯

Last year a company assessed 500 applicants with a coding test (pass/fail) and a later judgement of "good fit" or "not a fit":

पिछले साल एक कंपनी ने 500 आवेदकों को coding test (pass/fail) और बाद में "good fit" या "not a fit" के आकलन से परखा:

去年一家公司用编程测试(通过/未通过)和之后的“合适/不合适”评估考察了 500 名应聘者:

Good fit (GF)Good fit (GF)合适(GF)Not a fit (NF)Not a fit (NF)不合适(NF)Totalकुल合计
Passed coding (PC)Coding pass (PC)编程通过(PC)18070250
Failed coding (FC)Coding fail (FC)编程未通过(FC)45205250
Totalकुल合计225275500
🧮 Hiring — Conditional Probability AnalysisHiring — Conditional Probability Analysis招聘 — 条件概率分析
Q1
P(GF | PC) = 180/250 = 0.72
P(GF | PC) = 180/250 = 0.72
P(GF | PC) = 180/250 = 0.72
Q2
P(GF | FC) = 45/250 = 0.18
P(GF | FC) = 45/250 = 0.18
P(GF | FC) = 45/250 = 0.18
Q3
P(GF) = 225/500 = 0.45
P(GF) = 225/500 = 0.45
P(GF) = 225/500 = 0.45
Decisionफ़ैसला决策
Passing lifts the good-fit chance from 45% to 72%; failing drops it to 18%. The test is a strong signal, though not perfect: 45 good-fit people failed it.
Pass होने से good-fit chance 45% से 72% हो जाता है; fail होने पर 18%। Test एक मज़बूत संकेत है, पर परफ़ेक्ट नहीं: 45 good-fit लोग इसमें fail हुए।
通过测试把“合适”的概率从 45% 提升到 72%;未通过则降到 18%。这是一个强信号,但并不完美:有 45 名合适的人没通过。
Checkजाँच验证
Law of total probability: P(GF) = 0.72 × 0.50 + 0.18 × 0.50 = 0.36 + 0.09 = 0.45 ✓
Law of total probability: P(GF) = 0.72 × 0.50 + 0.18 × 0.50 = 0.36 + 0.09 = 0.45 ✓
全概率公式:P(GF) = 0.72 × 0.50 + 0.18 × 0.50 = 0.36 + 0.09 = 0.45 ✓

SectionSection第 10 节

The Law of Total Probability 🧮Law of Total Probability 🧮全概率公式 🧮

If the sample space splits into non-overlapping groups B₁, B₂, …, Bₙ that cover everything, then the chance of A is a weighted average of the chances of A inside each group. The weights are the group sizes.

अगर sample space बिना overlap वाले groups B₁, B₂, …, Bₙ में बँटा हो जो सब कुछ ढकते हैं, तो A का chance हर group के अंदर A के chance का weighted average है। Weights groups के आकार हैं।

若样本空间被划分为互不重叠且覆盖全部的组 B₁、B₂、…、Bₙ,那么 A 的概率就是各组内 A 的概率的加权平均,权重是各组的大小。

Law of total probabilityLaw of total probability全概率公式
P(A) = Σ P(A | Bᵢ) × P(Bᵢ)
Sum over a partition of Ω: mutually exclusive groups that together cover everything.
Ω के partition पर योग: mutually exclusive groups जो मिलकर सब कुछ ढकते हैं।
对 Ω 的一个划分求和:互斥且合起来覆盖全部的组。
Two-group versionदो-group रूप两组形式
P(A) = P(A|B) P(B) + P(A|Bᶜ) P(Bᶜ)
The simplest case. It is the denominator of Bayes' theorem.
सबसे सरल स्थिति। यही Bayes' theorem का denominator है।
最简单的情形,也是贝叶斯定理的分母。
🧮 Total Probability — The Factory StoryTotal Probability — Factory की कहानी全概率 — 工厂故事
Storyकहानी故事
Laptops come from Factory A (30% of supply, 2% defective), B (45%, 5%) and C (25%, 8%). What share of all laptops is defective?
Laptops Factory A (supply का 30%, 2% ख़राब), B (45%, 5%) और C (25%, 8%) से आते हैं। सभी laptops में कितने ख़राब हैं?
笔记本来自工厂 A(占供货 30%,次品率 2%)、B(45%,5%)和 C(25%,8%)。所有笔记本中次品占多少?
Calculateगणना计算
P(defect) = 0.02×0.30 + 0.05×0.45 + 0.08×0.25 = 0.006 + 0.0225 + 0.020 = 0.0485 (4.85%)
P(defect) = 0.02×0.30 + 0.05×0.45 + 0.08×0.25 = 0.006 + 0.0225 + 0.020 = 0.0485 (4.85%)
P(次品) = 0.02×0.30 + 0.05×0.45 + 0.08×0.25 = 0.006 + 0.0225 + 0.020 = 0.0485(4.85%)
Reverseउल्टा सवाल反向问题
Given a defect, where did it come from? P(A | defect) = 0.006/0.0485 = 12.4%, P(B | defect) = 46.4%, P(C | defect) = 41.2%.
Defect दिया हो, तो यह कहाँ से आया? P(A | defect) = 0.006/0.0485 = 12.4%, P(B | defect) = 46.4%, P(C | defect) = 41.2%।
已知是次品,它来自哪里?P(A | 次品) = 0.006/0.0485 = 12.4%,P(B | 次品) = 46.4%,P(C | 次品) = 41.2%。
Insightसीख启示
Factory C makes only 25% of laptops but 41% of the defects. Fixing C gives the biggest quality gain per laptop.
Factory C सिर्फ़ 25% laptops बनाती है पर 41% defects। C को सुधारने से हर laptop पर सबसे बड़ा quality फ़ायदा।
工厂 C 只生产 25% 的笔记本,却贡献了 41% 的次品。改进 C 对每台笔记本的质量提升最大。
🌳 PICTURE 4 — THE FACTORY TREEतस्वीर 4 — FACTORY TREE图 4 — 工厂概率树
Factory defect probability tree 0.30 A 0.02 A ∩ defect = 0.30×0.02 = 0.006 0.98 OK 0.45 B 0.05 B ∩ defect = 0.45×0.05 = 0.0225 0.95 OK 0.25 C 0.08 C ∩ defect = 0.25×0.08 = 0.02 0.92 OK P(defect) = 0.0485 sum of the red pathsलाल रास्तों का योग红色路径之和

Multiply along each red path, then add the paths.

हर लाल रास्ते पर गुणा करें, फिर रास्ते जोड़ें।

沿每条红色路径相乘,再把路径相加。

LIVELIVE互动Total Probability as AreasAreas के रूप में Total Probability用面积理解全概率

Each column's width is a factory's share and its height is the defect rate, so each coloured area is P(factory ∩ defect). The bar on the right splits the defects by factory — that is P(factory | defect). Inspect 1,000 laptops to compare with a real sample.

हर column की चौड़ाई factory का हिस्सा और ऊँचाई defect दर है, इसलिए हर रंगीन area P(factory ∩ defect) है। दाईं ओर का bar defects को factory के अनुसार बाँटता है — यही P(factory | defect) है। असली sample से तुलना के लिए 1,000 laptops जाँचें।

每列宽度是工厂份额,高度是次品率,所以每块彩色面积就是 P(工厂 ∩ 次品)。右侧条形按工厂拆分次品 —— 即 P(工厂 | 次品)。检查 1,000 台笔记本与真实样本比较。


SectionSection第 11 节

Simpson's Paradox — When the Condition Reverses the Answer 🔄Simpson's Paradox — जब शर्त जवाब पलट दे 🔄辛普森悖论 — 条件让结论反转 🔄

A real 1986 study (Charig et al., British Medical Journal) compared two kidney-stone treatments: A (open surgery) and B (percutaneous nephrolithotomy, a keyhole method). Overall, B looked better. Yet A did better for small stones and for large stones. How?

1986 की एक असली study (Charig et al., British Medical Journal) ने गुर्दे की पथरी के दो इलाजों की तुलना की: A (open surgery) और B (percutaneous nephrolithotomy, एक keyhole तरीका)। कुल मिलाकर B बेहतर दिखा। फिर भी A छोटी पथरी में और बड़ी पथरी में बेहतर था। कैसे?

1986 年的一项真实研究(Charig 等,《英国医学杂志》)比较了两种肾结石治疗:A(开放手术)和 B(经皮肾镜取石术,一种微创方法)。总体上 B 看起来更好,但 A 在小结石和大结石上都更好。这怎么可能?

Treatmentइलाज治疗Small stonesछोटी पथरी小结石Large stonesबड़ी पथरी大结石Overallकुल总体
A (open surgery)A (open surgery)A(开放手术)93% (81/87)73% (192/263)78% (273/350)78% (273/350)78%(273/350)
B (keyhole)B (keyhole)B(微创)87% (234/270)69% (55/80)83% (289/350)83% (289/350)83%(289/350)
⚠️
Simpson's Paradox ExplainedSimpson's Paradox की व्याख्या辛普森悖论解析

A was used mostly on large stones (263 of 350), which are harder to treat. B was used mostly on small stones (270 of 350). The overall rates mix easy and hard cases in very different amounts. Comparing within stone size — P(success | treatment, size) — removes that imbalance: A is better in both groups. Stone size is a confounder: it affected both the choice of treatment and the outcome.

A ज़्यादातर बड़ी पथरी (350 में 263) पर इस्तेमाल हुआ, जिनका इलाज कठिन है। B ज़्यादातर छोटी पथरी (350 में 270) पर। कुल दरें आसान और कठिन मामलों को बहुत अलग मात्रा में मिलाती हैं। पथरी के आकार के अंदर तुलना — P(सफलता | इलाज, आकार) — वह असंतुलन हटाती है: A दोनों groups में बेहतर है। पथरी का आकार एक confounder है: इसने इलाज के चुनाव और नतीजे दोनों पर असर डाला।

A 主要用于大结石(350 例中 263 例),这些更难治。B 主要用于小结石(350 例中 270 例)。总体比率以非常不同的比例混合了易治和难治病例。按结石大小分组比较 —— P(成功 | 治疗, 大小) —— 消除了这种失衡:A 在两组中都更好。结石大小是一个混杂因素:它同时影响了治疗选择和结果。

LIVELIVE互动Make Simpson's Paradox Appear and DisappearSimpson's Paradox को लाएँ और हटाएँ让辛普森悖论出现又消失

The success rates inside each stone size are fixed at the real values. Only the mix of patients changes. Move the sliders and watch the "overall" pair flip.

हर पथरी आकार के अंदर सफलता दरें असली मानों पर तय हैं। सिर्फ़ मरीज़ों का मिश्रण बदलता है। Sliders खिसकाएँ और "कुल" जोड़ी को पलटते देखें।

各结石大小内的成功率固定为真实值,只改变病例构成。拖动滑块,看“总体”那一对如何翻转。

🧭
Should You Always Split the Data?क्या हमेशा Data को बाँटना चाहिए?总要拆分数据吗?

Not always. Split by a variable that comes before the treatment and affects both who gets it and the outcome (like stone size). Do not split by something the treatment itself changes. Deciding which is which needs knowledge of how the data were produced — the numbers alone cannot tell you. This is why randomised trials, which balance confounders automatically, are so valuable.

हमेशा नहीं। उस variable से बाँटें जो इलाज से पहले आता है और इलाज किसे मिलेगा व नतीजे दोनों पर असर डालता है (जैसे पथरी का आकार)। उस चीज़ से न बाँटें जिसे इलाज ख़ुद बदलता है। कौन-सा कौन है, यह तय करने के लिए जानना पड़ता है कि data कैसे बना — सिर्फ़ संख्याएँ यह नहीं बता सकतीं। इसीलिए randomised trials, जो confounders को अपने आप संतुलित करते हैं, इतने क़ीमती हैं।

不一定。应按发生在治疗之前、且同时影响谁接受治疗和结果的变量拆分(如结石大小)。不要按治疗本身会改变的变量拆分。要判断属于哪种,需要了解数据是如何产生的 —— 光看数字无法判断。这正是随机对照试验如此宝贵的原因:它能自动平衡混杂因素。


SectionSection第 12 节

Python ImplementationPython ImplementationPython 实现

Row and column conditionals with pandaspandas से row और column conditionals用 pandas 计算按行与按列的条件概率

# 1) Conditional probability from a table: the classroom
import pandas as pd
df = pd.DataFrame({
    "major":  ["DS"] * 90 + ["BUS"] * 110,
    "result": ["Pass"] * 72 + ["Fail"] * 18 + ["Pass"] * 66 + ["Fail"] * 44,
})
print(pd.crosstab(df.major, df.result, margins=True))
print()
print("P(Pass | major)  -> divide each ROW by its row total")
print(pd.crosstab(df.major, df.result, normalize="index").round(3))
print()
print("P(major | result) -> divide each COLUMN by its column total")
print(pd.crosstab(df.major, df.result, normalize="columns").round(3))
OUTPUT
result Fail Pass All major BUS 44 66 110 DS 18 72 90 All 62 138 200 P(Pass | major) -> divide each ROW by its row total result Fail Pass major BUS 0.4 0.6 DS 0.2 0.8 P(major | result) -> divide each COLUMN by its column total result Fail Pass major BUS 0.71 0.478 DS 0.29 0.522

A spam filter, from one word to Naive BayesSpam filter: एक शब्द से Naive Bayes तक垃圾邮件过滤:从单词到朴素贝叶斯

# 2) Spam filter: one word, then Naive Bayes with two words
p_spam = 0.20
p_free = {"spam": 0.80, "ham": 0.05}      # P("FREE" | class)
p_win  = {"spam": 0.30, "ham": 0.01}      # P("WINNER" | class)

num = p_free["spam"] * p_spam
den = num + p_free["ham"] * (1 - p_spam)
print(f'P(spam | FREE)          = {num / den:.3f}')

# Naive Bayes: multiply the word likelihoods for each class, then normalise
s = p_spam * p_free["spam"] * p_win["spam"]
h = (1 - p_spam) * p_free["ham"] * p_win["ham"]
print(f'P(spam | FREE, WINNER)  = {s / (s + h):.4f}')
OUTPUT
P(spam | FREE) = 0.800 P(spam | FREE, WINNER) = 0.9917

Medical test: formula and simulation agreeMedical test: formula और simulation मेल खाते हैं医学检测:公式与模拟一致

# 3) Medical test: Bayes by formula and by simulation
import numpy as np
prev, sens, spec = 0.02, 0.92, 0.88
p_pos = sens * prev + (1 - spec) * (1 - prev)            # total probability
print(f"P(positive)           = {p_pos:.4f}")
print(f"P(disease | positive) = {sens * prev / p_pos:.4f}")

rng = np.random.default_rng(0)
n = 1_000_000
sick = rng.random(n) < prev
pos = np.where(sick, rng.random(n) < sens, rng.random(n) < 1 - spec)
print(f"simulated, {n:,} people: {sick[pos].mean():.4f}")
OUTPUT
P(positive) = 0.1360 P(disease | positive) = 0.1353 simulated, 1,000,000 people: 0.1362

Total probability and the reverse questionTotal probability और उल्टा सवाल全概率与反向问题

# 4) Law of total probability and the reverse question
share  = {"A": 0.30, "B": 0.45, "C": 0.25}
defect = {"A": 0.02, "B": 0.05, "C": 0.08}
joint = {f: share[f] * defect[f] for f in share}
p_def = sum(joint.values())
print(f"P(defect) = {p_def:.4f}")
for f in share:
    print(f"P({f} | defect) = {joint[f] / p_def:.3f}   (share of supply {share[f]:.2f})")
OUTPUT
P(defect) = 0.0485 P(A | defect) = 0.124 (share of supply 0.30) P(B | defect) = 0.464 (share of supply 0.45) P(C | defect) = 0.412 (share of supply 0.25)

Simpson's paradox in a few linesकुछ lines में Simpson's paradox几行代码看辛普森悖论

# 5) Simpson's paradox: kidney stones (Charig et al., BMJ 1986)
import pandas as pd
d = pd.DataFrame({
    "treatment": ["A", "A", "B", "B"],
    "stone":     ["small", "large", "small", "large"],
    "success":   [81, 192, 234, 55],
    "patients":  [87, 263, 270, 80],
})
d["rate"] = (d.success / d.patients).round(3)
print(d.pivot(index="treatment", columns="stone", values="rate"))
overall = d.groupby("treatment")[["success", "patients"]].sum()
print((overall.success / overall.patients).round(3).rename("overall"))
OUTPUT
stone large small treatment A 0.730 0.931 B 0.688 0.867 treatment A 0.780 B 0.826 Name: overall, dtype: float64

SectionSection第 13 节

Complete Formula Referenceपूरा Formula सारांश公式速查

FormulaFormula公式ExpressionExpression表达式Use whenकब इस्तेमाल करें何时使用
Conditional probabilityConditional probability条件概率P(A|B) = P(A∩B) / P(B)Chance of A inside the world where B happenedउस दुनिया में A का chance जहाँ B हुआ在 B 已发生的世界里 A 的概率
Multiplication ruleMultiplication rule乘法法则P(A∩B) = P(A|B) × P(B)Chance both happenदोनों होने का chance两者同时发生的概率
IndependenceIndependence独立性P(A|B) = P(A)Does knowing B change A?क्या B जानने से A बदलता है?知道 B 会改变 A 吗?
Total probabilityTotal probability全概率P(A) = Σ P(A|Bᵢ) × P(Bᵢ)Average over a partitionPartition पर औसत对划分加权平均
Bayes' theoremBayes' theorem贝叶斯定理P(H|E) = P(E|H) × P(H) / P(E)Flip the direction of the conditionशर्त की दिशा पलटना翻转条件的方向
Chain ruleChain rule链式法则P(A∩B∩C) = P(A) P(B|A) P(C|A∩B)Events in sequenceक्रम में events依次发生的事件
LiftP(B|A) / P(B)How much A raises the chance of BA, B का chance कितना बढ़ाता हैA 把 B 的概率提高了多少

SectionSection第 14 节

Where Conditional Probability Lives in Data ScienceData Science में Conditional Probability कहाँ है条件概率在数据科学中的位置

Applicationउपयोग应用Methodतरीका方法Condition (given)शर्त (दिया हुआ)条件(已知)Targetलक्ष्य目标
📧 Spam filteringSpam filtering垃圾邮件过滤Naive BayesWords in the emailEmail के शब्द邮件中的词P(spam | words)
🎬 RecommendationRecommendation推荐Collaborative filteringCollaborative filtering协同过滤Items the user likedUser को पसंद items用户喜欢过的物品P(likes Z | liked X, Y)
🏥 Medical diagnosisMedical diagnosis医学诊断Bayesian diagnosticsBayesian diagnostics贝叶斯诊断Symptoms + test resultsलक्षण + test नतीजे症状 + 检测结果P(disease | evidence)
🔐 Fraud detectionFraud detection欺诈检测Risk scoring modelsRisk scoring models风险评分模型Location, time, amountजगह, समय, राशि地点、时间、金额P(fraud | features)
📈 Credit scoringCredit scoring信用评分Logistic regressionLogistic regression逻辑回归Income, history, debt ratioआय, इतिहास, debt ratio收入、历史、负债率P(default | profile)
🚗 Robot / car localisationRobot / car localisation机器人 / 汽车定位Bayesian filters (Kalman, particle)Bayesian filters (Kalman, particle)贝叶斯滤波(卡尔曼、粒子)Sensor readings so farअब तक की sensor readings迄今的传感器读数P(position | readings)
🔤 Language modelsLanguage models语言模型Next-token predictionNext-token prediction下一个词元预测Previous tokensपिछले tokens前面的词元P(next token | context)
🧬 GenomicsGenomics基因组学Disease risk modelsDisease risk models疾病风险模型Genetic variantsGenetic variants基因变异P(disease | genotype)
📐
Language Models Estimate Conditional ProbabilitiesLanguage Models, Conditional Probabilities का अनुमान लगाते हैं语言模型在估计条件概率

A language model such as GPT, Claude or Gemini outputs, at each step, a probability distribution P(next token | all previous tokens). It is trained to make these conditional probabilities match real text, and later tuned further. The text you see is produced by picking tokens from these distributions one after another — the chain rule in action.

GPT, Claude या Gemini जैसा language model हर step पर एक probability distribution देता है: P(अगला token | पिछले सभी tokens)। इसे इन conditional probabilities को असली text से मिलाने के लिए train किया जाता है, और बाद में और tune किया जाता है। आप जो text देखते हैं वह इन distributions से एक के बाद एक tokens चुनकर बनता है — chain rule काम करते हुए।

像 GPT、Claude 或 Gemini 这样的语言模型,每一步都会输出一个概率分布 P(下一个词元 | 之前所有词元)。它先被训练得让这些条件概率贴近真实文本,之后再进一步调整。你看到的文字就是从这些分布中依次挑选词元生成的 —— 正是链式法则在起作用。


SectionSection第 15 节

The Golden Rules of Conditional ProbabilityConditional Probability के सुनहरे नियम条件概率的黄金法则

🎯 10 Rules Every Analyst Should Know10 नियम जो हर Analyst को पता हों每位分析师应知的 10 条法则
1
P(A | B) and P(B | A) are different numbers. Mixing them up is the prosecutor's fallacy. Always ask: "What is the condition — what am I dividing by?"
P(A | B) और P(B | A) अलग संख्याएँ हैं। इन्हें मिलाना prosecutor's fallacy है। हमेशा पूछें: "शर्त क्या है — मैं किससे भाग दे रहा हूँ?"
P(A | B) 与 P(B | A) 是不同的数。把它们混淆就是检察官谬误。始终要问:“条件是什么 —— 我在除以什么?”
2
Conditioning shrinks the world. P(A | B) is worked out only inside B. Everything outside B is ignored.
Conditioning दुनिया को छोटा करती है। P(A | B) सिर्फ़ B के अंदर निकाली जाती है। B के बाहर सब नज़रअंदाज़।
条件化缩小世界。P(A | B) 只在 B 内部计算,B 之外的一切都被忽略。
3
Always bring in the base rate. A 99% sensitive and 99% specific test for a condition in 0.1% of people still gives only about 9% true positives among positives.
हमेशा base rate जोड़ें। 0.1% लोगों वाली स्थिति के लिए 99% sensitive और 99% specific test भी positives में सिर्फ़ लगभग 9% true positives देता है।
始终考虑基础比率。对患病率 0.1% 的情况,即使检测灵敏度和特异度都是 99%,阳性中也只有约 9% 是真阳性。
4
Use total probability for the overall rate. P(A) = P(A|B) P(B) + P(A|Bᶜ) P(Bᶜ). It is also the denominator in Bayes.
कुल दर के लिए total probability लें। P(A) = P(A|B) P(B) + P(A|Bᶜ) P(Bᶜ)। यही Bayes का denominator भी है।
用全概率求总体比率。P(A) = P(A|B) P(B) + P(A|Bᶜ) P(Bᶜ),它也是贝叶斯的分母。
5
Independence means the condition adds nothing. P(A | B) = P(A). Check it in data before assuming it in a model.
Independence मतलब शर्त कुछ नहीं जोड़ती। P(A | B) = P(A)। Model में मानने से पहले data में जाँचें।
独立意味着条件不提供信息。P(A | B) = P(A)。在模型中假设之前先用数据验证。
6
Bayes' theorem reverses the condition. From P(evidence | hypothesis) it gives P(hypothesis | evidence) — the question we usually care about.
Bayes' theorem शर्त को पलटता है। P(सबूत | hypothesis) से यह P(hypothesis | सबूत) देता है — वही सवाल जिसकी हमें आम तौर पर परवाह होती है।
贝叶斯定理翻转条件。它由 P(证据 | 假设) 得出 P(假设 | 证据) —— 这通常才是我们关心的问题。
7
Watch for confounders. Simpson's paradox shows a lurking variable can reverse a comparison. Ask whether a third variable drives both the grouping and the outcome.
Confounders से सावधान। Simpson's paradox दिखाता है कि छिपा variable तुलना पलट सकता है। पूछें कि क्या कोई तीसरा variable grouping और नतीजे दोनों को चला रहा है।
警惕混杂因素。辛普森悖论表明潜在变量可以反转比较结论。问问是否有第三个变量同时驱动分组和结果。
8
Sequences need the chain rule. P(A ∩ B ∩ C) = P(A) × P(B | A) × P(C | A ∩ B). Draw a tree to keep track.
क्रम के लिए chain rule। P(A ∩ B ∩ C) = P(A) × P(B | A) × P(C | A ∩ B)। हिसाब रखने के लिए tree बनाएँ।
序列事件用链式法则。P(A ∩ B ∩ C) = P(A) × P(B | A) × P(C | A ∩ B)。画树来理清。
9
A high P(A | B) can still be rare overall. If B itself is rare, A ∩ B is rare too. Report P(B) alongside P(A | B).
ऊँची P(A | B) भी कुल मिलाकर दुर्लभ हो सकती है। अगर B ख़ुद दुर्लभ है तो A ∩ B भी दुर्लभ है। P(A | B) के साथ P(B) भी बताएँ।
P(A | B) 很高,总体上仍可能罕见。若 B 本身罕见,A ∩ B 也罕见。报告 P(A | B) 时也要报告 P(B)。
10
Most supervised ML models estimate a conditional quantity. Classifiers estimate P(class | features); regression estimates E[Y | X]. Seeing this makes models easier to interpret and to criticise.
ज़्यादातर supervised ML models एक conditional मात्रा का अनुमान लगाते हैं। Classifiers P(class | features) का; regression E[Y | X] का। यह समझने से models को पढ़ना और परखना आसान होता है।
大多数监督学习模型都在估计条件量。分类器估计 P(类别 | 特征),回归估计 E[Y | X]。看清这一点,模型就更容易解释和审视。
🧮
The Thread That Runs Through Everythingवह धागा जो सबमें चलता है贯穿一切的主线

Conditional probability is how we reason when new information arrives. Bayesian updating, classifiers, recommenders, diagnostic tests and language models all use it. Master three ideas — conditioning shrinks the world, P(A | B) ≠ P(B | A), and base rates matter — and you will read data far more clearly.

Conditional probability वह तरीका है जिससे हम नई जानकारी आने पर सोचते हैं। Bayesian updating, classifiers, recommenders, diagnostic tests और language models सब इसका इस्तेमाल करते हैं। तीन विचार पक्के करें — conditioning दुनिया को छोटा करती है, P(A | B) ≠ P(B | A), और base rates मायने रखते हैं — और आप data को कहीं ज़्यादा साफ़ पढ़ेंगे।

条件概率是我们在获得新信息时的推理方式。贝叶斯更新、分类器、推荐系统、诊断检测和语言模型都离不开它。掌握三个要点 —— 条件化缩小世界、P(A | B) ≠ P(B | A)、基础比率很重要 —— 你读数据会清楚得多。