Bayes theorem is an indispensable law of probability, allowing you to deductively quantify unknown probabilities. The theory rests upon conditional probability. Let's take a look at it in practice.
You will be able to:
- Define Bayes' theorem in relation to conditional probabilities
- Identify examples of applications of Bayes' theorem
Bayes' theorem is quite intuitive, decomposing the conditional probability of 'A given B' in terms of the probability that both events are true divided by the probability that B is true. Bayes theorem takes this natural idea a step further, expressing the probability that both events are true as a conditional probability multiplied by the condition itself.
To recap:
Bayes' Theorem takes the definition of the conditional likelihood:
and rewrites the
Making this substitution, you have Bayes' Theorem:
Let's take a simple theoretical example to demonstrate. Imagine there are two fish tanks at the local pet store. The small tank holds 10 Betta fish. The large tank has 200 goldfish and 35 Betta fish. Given that a fish is a Betta fish, what's the probability it comes from the small tank?
On the one hand, it seems that if you were to select a fish from the large tank, you'd probably end up with a goldfish. However, because these tanks are of such vastly different sizes, the probability that the fish came from the larger tank is actually more probable.
Using Bayes' theorem, you are looking to find the probability that the fish came from the small tank, given that it is a Betta fish:
Furthermore, you know:
Giving you:
$ P(\text{small_tank | Betta_fish}) = \dfrac{10}{45}$
While concrete, this example fails to demonstrate the full power of Bayes' theorem since you had all of the underlying information, so you don't even need to use Bayes' theorem. You could have simply looked at the number of Betta fish in the small tank versus the number of Betta fish overall:
giving you exactly the same result.
With this simple example out of the way, let's examine a more practical example from the field of Natural Language Processing.
A common introductory example to Natural Language Processing or classification is detecting spam. While you may enjoy spam in a can, you probably don't enjoy getting spam in your inbox. Bayes' theorem can serve as a natural classification method in these scenarios. Assume that the word "offer" (as in Special Offer, We Have an Offer for You, or Don't Miss This Offer!) occurs in 73% of the spam messages you receive. In comparison, only 10% of your desired mail contains the word "offer". If 20% of the messages you receive are spam, and you receive another message with the word "offer", what is the probability that it is spam?
As you might have guessed, you can solve this using the Bayes' theorem!
First, set up the problem:
Then substituting some of the immediate knowledge we have from the scenario:
Finally, the probability of receiving an email with the word "offer",
Finally, substituting this into the original Bayes formula you have:
As you can see, while spam has a much higher occurrence of the word "offer", the presence of the word alone does not provide strong confidence that the message is spam. To provide more statistical power, you will eventually extend Bayes' theorem to multiple observations simultaneously using the relative probabilities of multiple words.
In this lesson, you were introduced to the Bayes' theorem, and saw how it can be used to quantify conditional probabilities. With that, let's turn to some more simple examples for you to practice and deepen your understanding.