# Probability using Bayes Rule

I had a question of probability in one of my tests which I couldn't solve. I think that it could be solved using Bayes rule.

I am not looking for the exact solution but if anyone could explain the concept underlying the tricky problem would be really helpful.

Here is the question -

I have two boxes containing apples and banana. One box contains 3 times the number of bananas as apples. Another box contains 3 times the number of apples as bananas. I chose one box at random and from that box chose 5 fruits with replacement. I got 4 apples and 1 banana. What is the probability that we select the basket mainly with apples?

You have two boxes $B_1$ and $B_2$, where $P(Apple) = 0.25$ for $B_1$ and $P(Apple) = 0.75$ for $B_2$.

You observe data $D$, where you do 5 draws and get 4 apples and 1 banana.

You can formulate your question using the Bayes rule to calculate the probability that you picked box 2:

$$P(B_2|D) = \frac{P(D|B_2) * P(B_2)}{P(D|B_2) * P(B_2) + P(D|B_1) * P(B_1)}$$

Here the priors (of choosing either box) are the same:

$$P(B_1) = P(B_2) = \frac{1}{2}$$

And both likelihood functions (for box 1 and 2) follow a binomial distribution:

$$P(D|B_i) \stackrel{}{\sim} Binomial(n,k) = C(n,k)* p_i^k * (1-p_i)^k$$

where $C(n,k)$ is the combination, and $p_i^k$ is the probability of picking an apple for box $i$.

So now you can just plug in the numbers to the top equation and get the solution for yourself.