<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Karthik S Krishna Iyer on Medium]]></title>
        <description><![CDATA[Stories by Karthik S Krishna Iyer on Medium]]></description>
        <link>https://medium.com/@skiyer2?source=rss-4a90db78246e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OHrGgN_IalWkj2C2QoL_6A.jpeg</url>
            <title>Stories by Karthik S Krishna Iyer on Medium</title>
            <link>https://medium.com/@skiyer2?source=rss-4a90db78246e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:02:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@skiyer2/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Bayes Rule: Intuitive and Mathematical understanding]]></title>
            <link>https://medium.com/@skiyer2/bayes-rule-intuitive-and-mathematical-understanding-fc8125246f40?source=rss-4a90db78246e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc8125246f40</guid>
            <dc:creator><![CDATA[Karthik S Krishna Iyer]]></dc:creator>
            <pubDate>Fri, 11 Feb 2022 07:54:45 GMT</pubDate>
            <atom:updated>2022-02-11T17:46:31.703Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I will be taking a closer look at Bayes Theorem, most commonly referred as Bayes Rule. This rule bas been around for quite a few years, well before even Statistics formally existed as a discipline.</p><p>Bayes Rule has seen many different kinds of applications across various different sectors. Let’s take an example from the field of medicine to make it more interesting. Let’s say we are trying to diagnose a disease cancer and we have the below information about the disease.</p><p>Test for cancer is 95% accurate. Now, what can we infer from this statement. If a person has cancer, with Probability 0.95 the test will say that the person has cancer. In other words, 95% of the time the test will say that the person has cancer actually has cancer and also 95% of the time the test will say the person who does not have cancer actually does not have cancer. Both ways, the test is 95% correct OR correct 95% of the time. Pretty good so far.</p><p>I would want to draw your attention here. We do not know whether the person has cancer or not. The most pertinent question is, given the test is positive, what is the chance that the person actually has cancer ? We know that the test is not 100% accurate. There is an error of 5%. This means that there is a 5% chance that a person who actually has cancer, but the test indicated no cancer or vice versa. Such a possibility can occur. In other words, what is the probability of cancer ?</p><p>Think about this for a while. The test is 95% accurate. 95% of the time it gives a right answer. It is now saying that there is a positive result, indicating that the person has cancer. Should the person taking the test be worried that he/she has cancer ?. There might be a tendency to say that this should also be 95%, and the person should be worried as the chances are very high. Well, the answer to this depends on how rare or common the disease is in general population. If the disease is quiet common, we will see that the test is good, however if it is a rare disease, 95% accuracy is not so good.</p><p>Bayes Rule gives a surprising answer to this question. And what I want to do is to take you through this calculation and see what it comes out to be.</p><p>Before getting into the details, I want to explain what Bayes rule is:<br><strong>Bayes rule is used to revise initial or prior probabilities in the light of some given information. The revised probabilities are called posterior probabilities. The posterior probabilities are calculated by combining prior, conditional and joint probabilities.</strong><br>This may sound too technical. Don’t worry. I will make it simple.</p><p>Let’s put down everything in probability terms. We have the following.</p><p>C → indicates cancer; N → indicates no cancer; + → indicates test yielding positive, and <strong>-</strong> → indicates test yielding negative</p><p>We have the information that the test is 95% accurate. From Conditional Probability, we can interpret these as:</p><p>P(+|C) → Probability that the test is positive, given that a person has cancer = 0.95 Similarly, P(-|N) → Probability that the test is negative, given that a person has no cancer = 0.95.</p><p>The vertical bar | (pipe character on the keyboard) indicate conditioning. The event on the right of the bar is being told, and now you are being asked what is the probability of event on the left of the bar. We are interested in knowing P(C|+). You are told that the test yielded positive result, what is the likelihood that the person has cancer. It is important to note that P(+|C) is not same as P(C|+). We often fail to make this distinction in practice. We know that that the test is not 100% accurate. 5% of the time the test failed. I could be one of those 5 persons (assuming there are 100 people who were tested) where the test yielded positive result, but I actually did not have cancer.</p><p>So, P(C|+) = P(C and +)/P(+), by the rules of conditional probability. In other words, Of all the people who are positive, how many had cancer and positive. This is what we are interested in. We do not know P(+) in the denominator, but we can do something interesting here.</p><p>P(+) = P(C and +) + P(N and +)</p><p>Take a look at the above. I have said that that there are 2 ways in which someone can be positive. Either a person can be positive with cancer or a person can be positive and not have cancer. Note that such a possibility exist as the test is not 100% accurate and there is uncertainty. What allows me to add these 2 probabilities i.e. P(C and +) and P(N and +). These 2 events are mutually disjoint. Either a person has cancer or does not have cancer. It cannot be both. And by addition rule of probability, we can add them.</p><p>So this is what we have,<br>P(C|+) = P(C and +)/(P(C and +) + P(N and +)), please note I have wrapped each component in the denominator with parenthesis to make you understand that it is one unit and should not be read otherwise.</p><p>Now, P(C and +) = P(+|C) * P(C)<br>Think about this. The chance that a person has cancer and + is a product of 2 things. First, the person should have cancer and second, perhaps the interesting one to note, given that the person has cancer what are the chances the person is positive. This is also the generalized form of multiplication rule of probability. I am doing this, because what is known to me at this point, is P(+|C) which is 0.95<br>And, what I also need is P(C) i.e. the proportion of people who have cancer. This can be obtained from oncological studies or if there is enough study made to know how much prevalent the disease is and it has nothing to do with the individual.<br>Let’s make an assumption here, P(C) = 0.01 which means 1% of those tested have cancer.</p><p>Now, I have all those information to make the calculation.<br>P(C and +) = P(+|C) * P(C) = 0.95 * 0.01<br>Similarly,<br>P(N and +) = P(+|N) * P(N)<br>Do we have enough information to calculate this, of course we do.<br>P(N and +) = (1–0.95) * (1–0.01), since total probability will add up to 1.<br>So, P(C|+) = (0.95*0.01)/((0.95*0.01) + (0.05*0.99)) = 0.161 OR 16% approx.</p><p>This is somewhat surprising and interesting. Even though the stats on the test sounded good, it is still rather unlikely that the person has cancer (only 16%) given that the test yielded positive. Bayes rule gave a surprising result. Isn’t it!</p><p>Let’s try to intuitively understand as to why this could be happening with the help of below tree diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*kwkMhES2pSmlWW2I81objw.png" /></figure><p>Let’s say we start with 100,000 people and we divide them into 2 groups. Those who have cancer and those who do not. Considering that the disease incidence rate is 1% (assumption), we have 1,000 who have cancer and 99,000 who do not have cancer. Of these 1000, some will be tested positive and some will be negative. A tree diagram is indicating the split as 950 and 50. Similarly, 4950 and 94050 on the other side. Now, let’s find out how many people are positive in all.<br>This would be, Those who are actually positive/(Total positives)<br>i.e. 950/(950+4950), And this would result in 16%, consistent with what we saw previously in Bayes rule.<br>The reason why this is happening is not 950, but the 4950. A large number of people are false positives. Most people who return a positive test are actually false positives. This is because, a very large number (99,000) are actually negative, and even a small proportion of this very large number leads to a large number of false positives which swamped the true positives. Bayes rule makes this clear.</p><p>In business terms, this would mean that most people do not have cancer. But of the large number of people who do not have cancer, the algorithm will find a few who have cancer and these falsely identified patients will swamp the true cancer patients. In other words, even if there is a small possibility of false positives, the test will identify a lot of them. A place where this is causing a challenge in Analytics today is Fraud Detection (Credit Card, Insurance claims to name a few). There aren’t many cases of Fraud, but in order to pick up most cases of Fraud, there should be certain possibility of picking up or making a mistake. But as soon as an event is misidentified as being fraudulent incorrectly, lots and lots of false positives show up and it becomes hard to detect Fraud.</p><p>Mathematically, Bayes rule can be explained as follows:<br>Lets us say we know the probability of an event B given another event A. Now we want to know the probability of A given B. Bayes Rule helps to find that. It is simply written as:<br>P(A|B) = P(B|A) * P(A)/P(B) → equation(1)<br>It can be easily derived from the definition of conditional probability.<br>Now let’s say, there are n mutually disjoint events Aᵢ, where i = 1,2,3….n and their union is sample space: ∪ⁿᵢ₌₁Aᵢ = <em>S<br></em>Then probability of any event B ⊂ S can be written in the following way:<br>P(B) = P(B∩S), as B is completely contained in <em>S<br></em>P(B) = P(B∩(∪ᵢAᵢ)), as given above<br>P(B) = P(∪ᵢ(B∩Aᵢ)), after rearranging<br>P(B) = ΣᵢP(B∩Aᵢ), as all B∩Aᵢ are disjoint we can add them<br>P(B) = ΣᵢP(B|Aᵢ)*P(Aᵢ), from the definition of conditional probability</p><p>Substituting for P(B) in equation(1) above, we get a more general Bayes Theorem:<br><strong>P(Aᵢ|B) = P(B|Aᵢ)*P(Aᵢ)/ΣᵢP(B|Aᵢ)*P(Aᵢ)</strong></p><p>Please note that, P(Aᵢ|B) is called <strong>Posterior Probability</strong> which we are interested to calculate given we already know P(B|Aᵢ) which is called <strong>Prior Probability</strong>. The term P(Aᵢ)/ΣᵢP(B|Aᵢ)*P(Aᵢ) is called <strong>Likelihood Ratio</strong>, which indicates what is the likelihood of an event, and is of course the ratio Probability of an event/Sum of probabilities of all events.</p><p>I have made an attempt to cover both the intuition and mathematics behind Bayes rule. Hope you enjoyed reading it ! This is my first post on medium.com, any feedback is welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc8125246f40" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>