Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-001

Bayes Theorem

Problem

Apply Bayes' theorem to compute P(A|B):

P(A|B) = (P(B|A) * P(A)) / P(B)

where P(B) = P(B|A) * P(A) + P(B|¬A) * P(¬A).

Inputs: P(A), P(B|A), P(B|¬A). Return 0.0 if P(B) is 0.

Hint

Total probability of B uses both branches (A and ¬A).

Test cases

case 1
in: [0.01,0.9,0.05]
expected: 0.15384615384615385
case 2
in: [0.5,0.8,0.2]
expected: 0.8
case 3
in: [0.1,1,0]
expected: 1
case 4
in: [0,0.9,0.1]
expected: 0
Starter codePython
def bayes_theorem(p_a, p_b_given_a, p_b_given_not_a):
    # Your code here
    pass

4 test cases · run your code against them in the editor