Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # name: Gonul Ayci
- # e-mail: aycignl@gmail.com
- # date: Jan. 2018
- def bayesian(A_total, B_total):
- total = A_total + B_total
- prob_A = (A_total * 1.0)/ total
- prob_B = ((B_total) * 1.0)/ total
- # Assume that A and B are independent from each other
- prob_A_and_B = prob_A * prob_B
- prob_A_given_B = prob_A_and_B * 1.0/ prob_B
- prob_B_given_A = (prob_B * prob_A_given_B)/ (prob_A * 1.0)
- #
- # Bayes Theorem
- # p(B|A) = p(B, A)/p(A) = (p(A|B)*p(B))/p(A)
- # params: A and B
- # A: model
- # p(A), p(B): prior probabilities
- # p(A|B): likelihood
- print "Posterior probability: ", prob_B_given_A
- bayesian(10, 10)
- # Result:
- # Posterior probability: 0.5
Add Comment
Please, Sign In to add comment