I was looking into simple problems related to Data Science and Machine learning to practice, when I stumbled upon the Data Science Prep website and I signed up. Over the next few days, I received some problems on a variety of topics related to Probability, Statistics and Machine learning. The questions are from interviews of companies like Google, Facebook and so on. Thus, I thought of starting a series of these problems and here we are. So, Let’s begin.

Question

There is a fair coin (one side heads, one side tails) and an unfair coin (both sides tails). You pick one at random, flip it 5 times, and observe that it comes up as tails all five times. What is the chance that you are flipping the unfair coin?

Probability, Facebook, Easy

Solution

I was a bit confused when I first read the question because I am not great with Probability and was thinking about the problem naively. But, if you remember Bayes Theorem, this is a fairly simple problem. Thinking naively, it seems that we have a probability of \(\frac{1}{2}\) for selecting either coin but, knowing the fact that we have observed a tail for every filp, we need to find the posterior probability of flipping the unfair coin.

Mathematically, the Bayes theorem is:

\[P(A|B) = \frac{P(B|A)P(A)}{P(B)}\]

where, \(P(A)\), \(P(B)\) and \(P(B\mid A)\) are the priori of events A, B and A given B respectively. And, \(P(A\mid B)\) is the posterior probability of the event A occuring given the priori information we have at hand.

For our problem, let \(P(U)\) be the probability of flipping the unfair coin. Similarly, \(P(5T\mid U)\) be the probability of getting five tails, provided that we chose the unfair coin. \(P(U^{c})\) be the probability of choosing the fair coin, then

\[P(U) = P(U^{c}) = \frac{1}{2}\]

If we chose the unfair coin, then \(P(T) = 1\) since both sides of the unfair coin are tails. Thus,

\[P(5T|U) = 1\]

Then, Using Bayes theorem, we need to find the probability of flipping an unfair coin given that we flipped tails five times.

\[P(U|5T) = \frac{P(5T|U)P(U)}{P(5T)}\]

By law of total probability,

\[P(5T) = P(5T|U)P(U) + P(5T|U^{c})P(U^{c})\]

Thus,

\[\begin{align} P(U|5T) & = \frac{P(5T|U)P(U)}{P(5T|U)*P(U) + P(5T|U^{c})P(U^{c})} \\ & = \frac{1*\frac{1}{2}}{1*\frac{1}{2} + \frac{1}{2^{5}}*\frac{1}{2}} \\ & = 0.97 \end{align}\]

Thus, the probability of having chosen an unfair coin is 0.97, which is very high unlike our naive probability of \(\frac{1}{2}\).