# Market Basket Analysis - Interpretation of mirrored association rules

I have performed Market Basket Analysis on sales data, that comes from non-sequential receipts. I've read into the meaning of the different metrics, but there is one thing I don't understand. When looking at the strongest association rules, I detect a lot of mirrored rules. For example:

I'm not sure how to interpret this. Looking at confidence, it seems that people are more likely to buy pie, and then buy a cup of coffee. But how is this determined? We're talking about the same products, and my assumption would be identical values for all metrics for both rules. How can it be calculated that pie is more likely to lead to coffee, and less so the other way around? The support and lift are equal and any kind of order is not maintained when analyzing the products on receipts.

• Consider instead the case of coffee machine (A) and coffee grounds (B). We might see that most times someone buys a coffee machine, they also buy coffee grounds. Therefore P(B|A) is high which means there is high confidence in rule A->B. On the other hand, most of the time someone buys coffee grounds, they aren't also buying a coffee machine, so P(A|B) is much lower and therefore the confidence in the rule B->A is much lower. May 23 at 15:44
• @RyanVolpi So this is saying that Pie is a better predictor for Coffee, instead of the other way around? May 24 at 9:05
• Yes, that's one way of looking at it! May 24 at 16:09

The existing answer explains how the table is calculated. If you are still confused, one way to look at it is to start with the number of people who bought things.

Say 100 people visited the cafe, and 36 bought coffee, 18 bought pie, and 8 bought both. Then this is how the numbers in your table are calculated, using the formulas given by b-r-oleary:

P(A) P(C) P(A,C) P(C|A) P(A,C)/P(A)P(C) P(A,C)-P(A)P(C) (1-P(C))/(1-P(C|A))
36/100 18/100 8/100 8/36 100 x 8/(18x36) 8/100 - (18/100)(36/100) (1-18/100)/(1-8/36)
18/100 36/100 8/100 8/18 100 x 8/(18x36) 8/100 - (36/100)(18/100) (1-36/100)/(1-8/18)

Out of 18 people who bought pie, 8 also bought coffee, so the confidence is 8/18. But out of 36 people who bought coffee, only 8 also bought pie, so the confidence is 8/36.

The numbers in bold are the ones which aren't necessarily equal. This is just a consequence of how they are defined. The names "support", "lift" etc. are just names, which hopefully hint at how the numbers should be interpreted.

• Thanks! I accepted this answer because it explains how the differences (where I didn't expected them) come to be, and what it means May 26 at 20:18

The confidence for a rule $$A \Rightarrow C$$ with antecedent $$A$$ and consequent $$C$$ is the conditional probability $$P(C|A)$$ for a customer to purchase product $$C$$ given that they purchased product $$A$$. This is not a statement about whether the purchase for product $$C$$ is likely to occur after a purchase for product $$A$$ in time, but rather a statement about whether customers purchase these products together.

The confidence for the rule $$C \Rightarrow A$$ is related to the confidence for the mirror rule $$A \Rightarrow C$$ by Bayes theorem: $$P(C|A) = P(A|C) \frac{P(C)}{P(A)}$$

So, the confidence for these two mirror rules is related by the ratio of the probability of purchase for products $$A$$ and $$C$$. The example that you provided suggests that purchases for coffee are about twice as likely as purchases for pie:

$$\frac{P(\mathrm{Coffee}|\mathrm{Pie})}{P(\mathrm{Pie}|\mathrm{Coffee})} = \frac{P(\mathrm{Coffee})}{P(\mathrm{Pie})} = \frac{0.46}{0.24}$$

The other metrics that you are measuring can be defined as follows:

• Antecedent support: $$P(A)$$
• Consequent support: $$P(C)$$
• Support: $$P(A, C)$$
• Confidence: $$P(C|A)$$
• Lift: $$\frac{P(A, C)}{P(A)P(C)}$$
• Leverage: $$P(A, C) - P(A)P(C)$$
• Conviction: $$\frac{1 - P(C)}{1 - P(C|A)}$$

Amongst these metrics, the Support, Lift, and Leverage are symmetric with respect to interchange of the two products $$A \leftrightarrow C$$, so we would expect those metrics to be the same for the rule and its mirror rule. On the other hand the Confidence and the Conviction are not symmetric with respect to interchange of the two products, so we would not expect those metrics to be the same for the rule and its mirror rule.

• Thank you for the explanation. One thing is not entirely clear to me. How can there be a difference in confidence (or mirrored rule) at all, when all other metrics are the same? May 23 at 7:39