How Do You Fight Spam With Bayes’ Rule?

It might surprise you to know that in 2013, 70.7% of all worldwide emails were spam. Spam emails are unsolicited email that are sent out in bulk. To combat these emails, companies utilize spam filters provided by software companies to block the spam emails from reaching the desired recipient.

One provider, SpamTitan, advertises the following data

  • It blocks 99.9% of all spam email.
  • It blocks 0.03% of all emails that are not spam.

Based on the information above, what is the probability that a delivered email is spam?

To start a problem like this, let’s identify the relevant events.

  • S is the event that an email is spam
  • ′ is the event that an email is not spam
  • B is the event the an email is blocked
  • B′ is the event an email is not blocked

Based on these events, we want to compute the probability that an email is spam given that it is not blocked, P(S|B′).

Let’s look at a tree diagram of the situation.

 

Next, we’ll label the given information on the diagram.

The key here is to recognize that the data provided by the software company are conditional probabilities. Since we know that the probabilities on branches from a single point must add to 1, we can finish labeling the diagram.

The diagram is labeled nicely, but none of the probabilities match P(S|B′). The conditional probabilities on the second set of branches are all given the event S or the event ′. To find P(S|B′), we’ll utilize Bayes’ Rule. Start with the relationship between conditional probabilities,

and solve for P(S|B′). This gives

All of the probabilities on the right side may be found from the tree diagram.

The probabilities in the numerator are located along the branch in red through S and B′.

The probability in the denominator corresponds to all branches in green that lead to B′. Since the events along each branch are disjoint, the probabilities for each branch add. This gives us

So the likelihood that an unblocked email is spam is 0.24%.

Users are typically very tolerant of getting spam that has made it through a spam filter. However, they are not very tolerant of blocked emails turning out to not be spam. This probability is P(S′|B). We can compute this probability in a similar manner:

This likelihood equates to 0.012%. This should make customers very happy since it means that there important emails will rarely be blocked by the spam filter.

How Do You Pick Stocks With Bayes’ Rule?

A stock brokerage is grading its trainees by evaluating their stock picks over a 6 month period. The company has analyzed the trainees’ stock portfolios and computer usage to determine that 60% of the stocks picked by the trainees were up in the 6 month period and 45% of the trainees do research on their stock picks. In addition, the brokerage determined that of the stocks that were up, 30 of the trainees picking a particular stock did research on the stock and 30 of the trainees picking a particular stock did not do any research on the stock.

By Dipsey, via Wikimedia Commons

If a trainee buys the stock of a company they have researched, what is the likelihood that the stock was up over the 6 month period?

Before we start calculating haphazardly, let’s define two events for the problem:

S is the event that a stock that was picked by a trainee was up

R is the event that a trainee did research on a stock that they picked

In terms of these events, we need to find the probability P(S | R), the probability that a stock picked by a trainee was up, given that that stock pick was researched by the trainee. Now let’s examine the information in the problem statement.

The statement says, “60% of the stocks picked by the trainees were up in the 6 month period.” This information is given as a percentage so it corresponds to an empirical probability. In terms of the event S, it tells us that

P(S) = 0.60

The statement also says, “45% of the trainees do research on their stock picks.” This information relates to the event R and tells us that

P(R) = 0.45

The statement “the brokerage determined that of the stocks that were up, 30 of the trainees picking a particular stock did research on the stock and 30 of the trainees picking a particular stock did not do any research on the stock” relates the events S and R. By saying that “of the stocks that were up”, we are establishing that the following information corresponds only to stocks picked by the trainees that are up or that the information matches a conditional probability where we are given S. Additionally, we know that a total of 60 trainees picked stocks that were up since of the stocks that were up, 30 trainees did research and 30 did not do research. Based on this information,

stocks_01

On a tree diagram, we can label the branches as shown.

stocks_02

For this particular way of constructing the tree diagram, the probability P(R) = 0.45 cannot be labeled on the diagram directly. Remember, we are looking for P(S | R) which is NOT the same as the probability P(R | S) = 0.5. To relate these conditional probabilities, utilize Bayes’ Rule in the form,

stocks_03

Solving for P(S | R), we get

stocks_04

Each of the probabilities on the right side we have already found and can be substituted to yield

stocks_05

This number does not have much meaning unless we compare it to the likelihood of picking a stock that is up, given that the trainee did not do any research on the stock, . Using Bayes’ Rule in this case yields

stocks_06

The only probability that we have not calculated is P(R′). Using the compliment rule, this is easily calculated as

stocks_07

Now we can return to Bayes’ Rule to calculate

stocks_08

In summary, we now know that

stocks_09

Now we can compare these two probabilities to draw conclusions about the events. Based on these numbers, we see that it is more likely that a stock chosen by a trainee goes up provided the do research. The probabilities P(′ | R) and P(′ | R′) can be found with similar versions of Bayes’ Rule.

How Do You Use Bayes’ Rule In Quality Control?

Based on past experience, a company knows that an experienced machine operator (one or more years of experience) will produce a defective item 1% of the time. Operators with some experience (up to one year) have a 2.5% defect rate, and new operators have a 6% defect rate. At any one time, the company has 60% experienced operators, 30% with some experience, and 10% new operators. Find the probability that a particular defective item was produced by a new operator.

The first thing we need to do is organize the information we have been given. So let’s create some events to work with.

D: “operator produces a defective item”
E: “experienced operator”
S: “operator with some experience”
N: “new operator”

With these definitions, the information in the problem statement can be written as

P(E) = 0.60     P(E) = 0.01

P(S) = 0.30     P(| S) = 0.025

P(N) = 0.10     P(D | N) = 0.06

The tree diagram below reflects this information.

qc_01

If we want to know the probability that an experience operator produces a defective item, we are interested in the event E and D. These probabilities lie along the top branch so

qc_02

To find the probability that a particular defective item was produced by a new operator, we need to compute P(N | D). The appropriate form of Baye’s Theorem is

qc_03

Solving for P(D) yields

qc_04

Both factors in the numerator are branches in the tree. The denominator is simply the sum of the branches leading to defective or

qc_05

The key to using Bayes’ Theorem is to write the proper tree and appropriate rule based on the events in the problem.