How to find the probabilities of a list of lists using python and without any libraries

P(S2)=3/5 (since there are 3 lists containing S=2) of the total 5 lists
P(F1)=2/5 (since there are 2 lists containing F=1) of the total 5 lists
P(F1|S2) = 1/3 ( since given S=S2, means there are only 3 lists, and out of which F=F1 is only 1 list)

There you go!

So you’ve just proven to yourself that these two things are not independent.

Now. Your problem gives you a list of lists. You dont know what they are, but you know what they are made up of: For each element, F will be 1,2,3,4,or 5, and S will be 1,2 or 3.

You know how to find P(S2). The only thing you’re missing from your formula at this point is P(F1 n S2), and then you can find P(F1|S2), right?

Well, what is P(F1 n S2) ?

1 Like

Events A and B are independent if the equation P(A∩B) = P(A) · P(B) holds true.
P(F1∩S2) = ?
Here I am not sure if it is dependant or independant.

Ask yourself, does one event in any way affect the outcome (or the odds) of the other event? If yes, it is dependent.

I think its dependent.

P(F1)=2/5 (since there are 2 lists containing F=1) of the total 5 lists
P(F1|S2) = 1/3 ( since given S=S2, means there are only 3 lists, and out of which F=F1 is only 1 list)
It’s impossible for A and B to be independent if an outcome of one of the events changes the probability of the other event.

P(F1 n S2) can be read as: “The Probability that a randomly chosen list has both F=1 and S=2”.

[F,S]:
[[1,3],[1,2],[2,4],[2,2],[3,2]]

What is P(F1 n S2) ?

P(F1 n S2) = 1/5 (since there is only one list where the list has both F=1 and S=2, out of 5 lists)

Right.

So, let’s go back to your first formula for P(F1|S2).

Lets see if the formula agrees with what you told me.

In our example above, you told me:

 P(F1 n S2) = 1/5.
P(S2) = 3/5.

So.

P(F1 n S2) / P(S2)  =
(1/5) / (3/5) =
(1/5) * (5/3) (multiplicative inverse) =
(1*5) / (5*3) = (cancel the 5's with each other...)
1/3 = P(F1|S2)

And 1/3 is what you told me. So the formula agrees with what you intuited.

So lets take a look at that again.

P(S2)=3/5 (since there are 3 lists containing S=2) of the total 5 lists
P(F1 n S2) = 1/5 (since there is only one list where the list has both F=1 and S=2, out of 5 lists)
P(F1|S2) = P(F1 n S2) / P(S2)
Let’s abstract that a little bit:

P(SX) = I/K there are I lists containing S=X) of the total K lists
P(FY n SX) = J/K there are J lists where the list has both F=Y and S=X, out of K lists)
P(FY|SX) = P(FY n SX) / P(SX)

You’ve demonstrated enough python skills to me so far that you should now be able to code this.

For a given X and Y, and a list of lists:
Find K.
Find I.
Find J.
Find P(SX) using I and K.
Find P(FY n SX) using J and K.
Find P(FY|SX) using P(SX) and P(FY n SX).

EDIT: Cleaning up formatting. silly symbols.

1 Like

You are right, I am getting it. You are awesome, excellent.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.