Answers.Body: <p>Your probability hasn't been <em>normalized</em>!</p>
  
  <p>In this case, you are computing the probability of being good, <em>given that the other features have a fixed value</em>. To obtain the correct probability, you need to normalize (divide) the value from your calculation by the probability that the features have taken on those fixed values.</p>
  
  <p>You can calculate this as follows:
   $$P(Fem:dv/m/s, Young, own, Ex-credpaid) = \\ \sum_{x \in \{good,bad\}} P(Fem:dv/m/s, Young, own, Ex-credpaid, x) $$</p>
  
  <p>by the marginalization rule.</p>
  
  <p>Then, by the chain rule, you may write:</p>
  
  <p>$$\\ \sum_{x \in \{good,bad\}} P(Fem:dv/m/s, Young, own, Ex-credpaid | x) * P(x) $$</p>
  
  <p>So the correct probability of 0.62 should be obtained by the equation:</p>
  
  <p>$$ \frac{P(Fem:dv/m/s, Young, own, Ex-credpaid | good) * P(good)}{\sum_{x \in \{good,bad\}} P(Fem:dv/m/s, Young, own, Ex-credpaid | x) * P(x)}$$</p>
  
  <p>You just need to calculate </p>
  
  <p>$$P(Fem:dv/m/s, Young, own, Ex-credpaid | bad) * P(bad)$$ </p>
  
  <p>and it should be easy to compute the rest.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-20T21:36:33.480Z
Answers.Text: thanks for the Answer, but I dont have the same result of 0.62. when I doing: P(Fem:dv/m/s | bad)*P(Young | bad)*P(own | bad)*P(Ex-credpaid | bad)*P(bad) -> 2/4*3/4*1/4*2/4*0.4= 0,01875 and 0,01389/(0,01389+0,01875)=0,4255
  
  @John Doucette
Answers.UserDisplayName: TomaateTip
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-21T12:23:24.507Z
Answers.Text: Hmm. You are correct.  Do you have more context for that table? Where does it come from?
Answers.UserDisplayName: John Doucette
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-21T14:05:23.293Z
Answers.Text: the table comes from this paper:
  (page 3)
  https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4909197
Answers.UserDisplayName: TomaateTip
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-21T15:15:32.277Z
Answers.Text: Hmm. It looks like there are several things at play. First, I think the authors may have used Laplacian Smoothing. This is a usual thing to do, but it changes the calculation. Basically, you add one additional observation of each kind to each of the conditional distributions to make a uniform prior, and then continue to count these when computing the posteriors. Even doing that however, I only get 50%. It's possible that the table is simply incorrect.
Answers.UserDisplayName: John Doucette
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-29T14:58:51.760Z
Answers.Text: I hear, that the probability was false, and I do the same algorithm in Python and I dont know how do you did the naivebayes algorithm, how do you did?
Answers.UserDisplayName: TomaateTip
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-29T20:37:37.650Z
Answers.Text: @TomaateTip I'm not sure I understand what you mean. I think the probability in the table is incorrect, and doing Naive Bayes the way you described (plus the normalization in my answer) will yield the correct probabilities.
Answers.UserDisplayName: John Doucette
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-29T20:40:42.747Z
Answers.Text: yes, is incorrect, but you said that you get 50%, do you programmed it? when yes, how?
Answers.UserDisplayName: TomaateTip
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-30T00:56:04.740Z
Answers.Text: No, I computed it by hand.
Answers.UserDisplayName: John Doucette
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-20T19:41:13.490Z
Answers.LastActivityDate: 2018-08-20T19:41:13.490Z
Answers.UserDisplayName: John Doucette
Body: <p>In the attached image</p>
  <p><a href="https://i.sstatic.net/mmcbd.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mmcbd.jpg" alt="Table1" /></a></p>
  <p>there is the probability with the Naive Bayes algorithm of:</p>
  <blockquote>
  <p>Fem:dv/m/s Young own Ex-credpaid Good -&gt;62%</p>
  </blockquote>
  <p>I calculated the probability so:</p>
  <p><span class="math-container">$$P(Fem:dv/m/s \mid Good) * P(Young \mid Good)*P(own \mid Good)*P(Ex-credpaid \mid good)*P(Good) =  1/6*2/6*5/6*3/6*0.6 = 0,01389$$</span></p>
  <p>I don't know where I failed. Could someone please tell me where is my error?</p>
  
Tags: <naive-bayes>
Title: Why is my calculation of the probability of an object being in a certain class incorrect?
UserDisplayName: TomaateTip
ThreadText: # Why is my calculation of the probability of an object being in a certain class incorrect?
  
  (Asked by: username_0 on 2018-08-20)
  
  In the attached image
  
  [![Table1](https://i.sstatic.net/mmcbd.jpg)](https://i.sstatic.net/mmcbd.jpg)
  
  there is the probability with the Naive Bayes algorithm of:
  
  > Fem:dv/m/s Young own Ex-credpaid Good ->62%
  
  I calculated the probability so:
  
  $$P(Fem:dv/m/s \mid Good) \* P(Young \mid Good)\*P(own \mid Good)\*P(Ex-credpaid \mid good)\*P(Good) = 1/6\*2/6\*5/6\*3/6\*0.6 = 0,01389$$
  
  I don't know where I failed. Could someone please tell me where is my error?
  
  **Tags:** naive-bayes
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-20. Score: 2
  
  Your probability hasn't been *normalized*!
  
  In this case, you are computing the probability of being good, *given that the other features have a fixed value*. To obtain the correct probability, you need to normalize (divide) the value from your calculation by the probability that the features have taken on those fixed values.
  
  You can calculate this as follows:
  $$P(Fem:dv/m/s, Young, own, Ex-credpaid) = \\ \sum\_{x \in \{good,bad\}} P(Fem:dv/m/s, Young, own, Ex-credpaid, x) $$
  
  by the marginalization rule.
  
  Then, by the chain rule, you may write:
  
  $$\\ \sum\_{x \in \{good,bad\}} P(Fem:dv/m/s, Young, own, Ex-credpaid | x) \* P(x) $$
  
  So the correct probability of 0.62 should be obtained by the equation:
  
  $$ \frac{P(Fem:dv/m/s, Young, own, Ex-credpaid | good) \* P(good)}{\sum\_{x \in \{good,bad\}} P(Fem:dv/m/s, Young, own, Ex-credpaid | x) \* P(x)}$$
  
  You just need to calculate
  
  $$P(Fem:dv/m/s, Young, own, Ex-credpaid | bad) \* P(bad)$$
  
  and it should be easy to compute the rest.
  
  > **Comments:**
  > **username_0**: thanks for the Answer, but I dont have the same result of 0.62. when I doing: P(Fem:dv/m/s | bad)*P(Young | bad)*P(own | bad)*P(Ex-credpaid | bad)*P(bad) -> 2/4*3/4*1/4*2/4*0.4= 0,01875 and 0,01389/(0,01389+0,01875)=0,4255  @John Doucette  
  > **username_1**: Hmm. You are correct.  Do you have more context for that table? Where does it come from?  
  > **username_0**: the table comes from this paper: (page 3) https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4909197  
  > **username_1**: Hmm. It looks like there are several things at play. First, I think the authors may have used Laplacian Smoothing. This is a usual thing to do, but it changes the calculation. Basically, you add one additional observation of each kind to each of the conditional distributions to make a uniform prior, and then continue to count these when computing the posteriors. Even doing that however, I only get 50%. It's possible that the table is simply incorrect.  
  > **username_0**: I hear, that the probability was false, and I do the same algorithm in Python and I dont know how do you did the naivebayes algorithm, how do you did?  
  > **username_1**: @TomaateTip I'm not sure I understand what you mean. I think the probability in the table is incorrect, and doing Naive Bayes the way you described (plus the normalization in my answer) will yield the correct probabilities.  
  > **username_0**: yes, is incorrect, but you said that you get 50%, do you programmed it? when yes, how?  
  > **username_1**: No, I computed it by hand.  
  
  ---
  
  