Guest User

Untitled

a guest
Jan 20th, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. # name: Gonul Ayci
  2. # e-mail: aycignl@gmail.com
  3. # date: Jan. 2018
  4.  
  5. def bayesian(A_total, B_total):
  6. total = A_total + B_total
  7.  
  8. prob_A = (A_total * 1.0)/ total
  9. prob_B = ((B_total) * 1.0)/ total
  10.  
  11. # Assume that A and B are independent from each other
  12. prob_A_and_B = prob_A * prob_B
  13. prob_A_given_B = prob_A_and_B * 1.0/ prob_B
  14. prob_B_given_A = (prob_B * prob_A_given_B)/ (prob_A * 1.0)
  15.  
  16. #
  17. # Bayes Theorem
  18. # p(B|A) = p(B, A)/p(A) = (p(A|B)*p(B))/p(A)
  19.  
  20. # params: A and B
  21. # A: model
  22. # p(A), p(B): prior probabilities
  23. # p(A|B): likelihood
  24.  
  25. print "Posterior probability: ", prob_B_given_A
  26.  
  27. bayesian(10, 10)
  28.  
  29. # Result:
  30. # Posterior probability: 0.5
Add Comment
Please, Sign In to add comment