How to write conditional probability in Python?

7k views Asked by At

I am not sure if that's a place to ask here (my type question)?

I am working to code in python but I am struggling to interpreter that to Python.

My question is : I have Pr(A | B) in the case of dependent which is equal to

Pr ( A ∩ B ) / Pr(B). I know how to do it by program, but I mean can I do that by python. On my idea I just multiply Pr ( A ) * Pr (B) then I / Pr(B). Which I think is not correct is there anyway to write that the conditional probability in python program, or what did is correct?

1

There are 1 answers

0
Sarit Adhikari On

if you know values of P(A ∩ B) and P(B) , you can compute P(A | B) using

pB = 0.3
pAB=0.4

pAifB = pAB / pB
print(pAifB)