Let's look at a priori in action.
Imagine a transactional data set like this we have 20 transactions and two items purchased in every
single transaction.
Let's calculate the association between bacon and eggs.
First, we want to calculate the support for each one of these.
And together.
The support for Bacon is 10, divided by 20 because we had 10 transactions where we saw bacon out of
20 total transactions.
So the support is zero point five.
The support for eggs is seven divided by 20, which is zero point three five, because seven transactions
had eggs out of 20 transactions total.
The support for both bacon and eggs together is six divided by 20, which is 0.3 because only six transactions
out of 20 transactions had both bacon and eggs.
Now this gives us some information already.
Bacon is pretty frequently.
Eggs are a little bit less frequent, but still occur often in just a 120 transaction data set, and
they also co-occur a decent amount out of all these transactions.
Six out of 20.
Now, the confidence of bacon in playing egg transaction would be the support for both bacon and eggs
divided by the support for just bacon.
Now we already calculated these above so we can just plug these numbers in and calculate that 60 percent.
So what does this tell us?
This is the conditional probability of purchasing eggs, given that we've purchased bacon.
Good to know when somebody is going to purchase bacon, they're also going to purchase eggs 60 percent
of the time.
Now, this is good to know, but that final metric lift is really important.
Lift here is still going to associate bacon and eggs, but we're going to calculate this as the support
for bacon and eggs divided by the support for just bacon times, the support for just eggs here on the
bottom.
We're not just taking into account the probability or the support of bacon, but also eggs.
And our result once we plug those numbers in because again, we've already calculated these is 1.7.
Now, since lift is greater than one, we can interpret the association between eggs and bacon or bacon
and eggs as real and properly informative.
Right.
Eggs are likely to be purchased with bacon given this result and the value of one for lift.
That's the real cutoff greater than one tells us that there is an association between these two products.
But that's just one example where we see high support, pretty high confidence and also a high lift,
let's look at another example.
Let's calculate the association between bacon and basil.
The support for bacon is 0.5.
Support for basil is 0.25, and the support for both of them together is zero point zero five.
Pretty low because only one transaction out of 20 had both bacon and basil.
We can do the same confidence calculation that we've seen before to get 10 percent.
So 10 percent of the time that you're buying bacon, you're also going to buy basil as well.
And the lift calculation, once we plug those same numbers into that same calculation gets to zero point
four.
So there is no association between basil and bacon.
So since this lift is less than one, we can conclude that there is no positive association between
bacon and basil, buying bacon gives us no real information about whether we're also going to buy basil.
Let's jump into another example now, which is a little bit more complex and shows why looking at each
one of these metrics is really important.
For this example, let's calculate the association between bacon and water support for bacon is 0.5
as we keep seeing support for water in this transactional data set is just zero point zero five or one
out of 20.
And the support is one out of 20 zero point zero five as well, because that one transaction line 17
had both bacon and water.
When we calculate the confidence here, we see that the confidence is 10 percent.
Not too high.
But when we look at the lift and plug those numbers into calculate the lift, we see that the lift is
two that's greater than one.
So that would imply in most cases that there is an association between bacon and water.
But really, this lift is only at two or greater than one, simply because water only appears in one
transaction and it just happens to have bacon at the same time.
So if you just looked at lift, you may think that there's an association between bacon and water when
in reality there's not.
In the next video, we'll talk about minimum support thresholds, which solve this problem for us to
make sure that we're not drawing the wrong conclusion from a left calculation.