user3462393
user3462393

Reputation: 51

How to write conditional probability in Python?

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?

Upvotes: 0

Views: 7276

Answers (1)

Sarit Adhikari
Sarit Adhikari

Reputation: 1402

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)

Upvotes: 2

Related Questions