Association Mining

Frequent Pattern Mining

Frequent patterns are patterns that appear frequently in a dataset.

Example: Customers frequently purchasing milk and bread together represent a frequent pattern.

Frequent pattern mining searches for recurring relationships or patterns in a given dataset.

Market Basket Analysis

An example of frequent itemset mining is Market Basket Analysis.

This process analyzes customer buying habits by finding associations between different items that customers place in their shopping baskets.

For example, if customers frequently purchase milk and bread together, a retailer can identify this association and use it to improve product placement and marketing strategies.

Applications

  • Selective marketing: Businesses can target customers based on frequently purchased combinations of products.
  • Product placement: Items that are frequently purchased together can be placed in clos

Association Rule Mining

Association rule mining is a two-step process:

  1. Find all frequent itemsets Identify itemsets that satisfy the minimum support threshold.
  2. Generate strong association rules Generate association rules from the frequent itemsets. The generated rules must satisfy both:
    • Minimum support
    • Minimum confidence

Support: It refers to the popularity of an item and can be calculated by finding the number of transactions containing a particular item ÷ total number of transactions.

Support(B)=Transactions containing BTotal transactions\text{Support}(B) = \frac{\text{Transactions containing } B}{\text{Total transactions}}

Example: 1000 transactions, 100 transactions contain ketchup.

Support (ketchup)=1001000=10%\text{Support (ketchup)} = \frac{100}{1000} = 10\%

Confidence: It refers to the likelihood that an item B is also bought if item A is bought.

Confidence(A→B)=Transactions containing both (A and B)Transactions containing A\text{Confidence}(A \rightarrow B) = \frac{\text{Transactions containing both } (A \text{ and } B)}{\text{Transactions containing } A}

50 transactions → burger and ketchup were bought.

Then we can find the likelihood of buying ketchup when a burger is bought.

150 transactions → burgers are bought.

The association rule is:

Burger→Ketchup\text{Burger} \rightarrow \text{Ketchup}

Confidence(Burger→Ketchup)=50150=33.33%\text{Confidence}(\text{Burger} \rightarrow \text{Ketchup}) = \frac{50}{150} = 33.33\%

Apriori Algorithm

The Apriori algorithm works in 2 main steps:

1. Join Step →

This step generates (k + 1)-itemsets from k-itemsets by joining frequent k-itemsets with each other.

For example, two frequent 2-itemsets can be joined to generate a candidate 3-itemset.

2. Prune Step →

In this step, the candidate itemsets are checked against the minimum support threshold.

If a candidate itemset does not satisfy the minimum support, it is removed (pruned).

The remaining itemsets are called frequent itemsets and are used to generate the next set of candidate itemsets.

Solved Problem

Transaction List

TIDItems Purchased
1Milk, Egg, Bread, Butter
2Milk, Butter, Egg, Ketchup
3Bread, Butter, Ketchup
4Milk, Bread, Butter
5Bread, Butter, Cookies
6Milk, Bread, Butter, Cookies
7Milk, Cookies
8Milk, Bread, Butter
9Bread, Butter, Egg, Cookies
10Milk, Butter, Bread
11Milk, Bread, Butter
12Milk, Bread, Cookies, Ketchup

Support level = 30%

Confidence = 60%

Solution:


1-itemsets

There are 12 transactions in the database.

For a support level of 30%:

0.30×12=3.60.30 \times 12 = 3.6

Since the support count must be a whole number, the minimum support count is 4.

Therefore, only items occurring 4 or more times are considered frequent.

1-itemsetsFreqSupport
Milk99/12
Bread1010/12
Butter1010/12
Egg33/12
Ketchup33/12
Cookies55/12

Frequent 1-itemsets

After applying the minimum support count of 4, the frequent 1-itemsets are:

Frequent 1-itemsetsFreq
Milk9
Bread10
Butter10
Cookies5

List is {Milk, Bread, Butter, Cookies}\{\text{Milk, Bread, Butter, Cookies}\}

2-itemsets

2-itemsetsFreqSupp
Milk, Bread77/12
Milk, Butter77/12
Milk, Cookies33/12 = 25%
Bread, Butter99/12
Bread, Cookies44/12
Butter, Cookies33/12 = 25%

Frequent 2-itemsets

Frequent 2-itemsetsFreqSupp
Milk, Bread77/12 = 0.58 = 58%
Milk, Butter77/12 = 0.58 = 58%
Bread, Butter99/12 = 0.75 = 75%
Butter, Cookies44/12 = 0.33 = 33%

List is {Milk, Bread, Butter, Cookies}\{\text{Milk, Bread, Butter, Cookies}\}

Frequent 3-itemsets

3-itemsetsFreq
Milk, Bread, Butter6
Milk, Bread, Cookies1
Bread, Butter, Cookies3
Milk, Butter, Cookies2

Frequent 3-itemsets

After applying the minimum support count of 4, only one 3-itemset is frequent:

Frequent 3-itemsetsFreq
Milk, Bread, Butter6

Therefore:

Frequent 3-itemset=I={Milk, Bread, Butter}\text{Frequent 3-itemset} = I = \{\text{Milk, Bread, Butter}\}


Non-empty Subsets

The non-empty subsets of I are:

{Milk}, {Bread}, {Butter}\{\text{Milk}\},\ \{\text{Bread}\},\ \{\text{Butter}\} , {Milk, Bread}, {Milk, Butter}, {Bread, Butter}\{\text{Milk, Bread}\},\ \{\text{Milk, Butter}\},\ \{\text{Bread, Butter}\}

These subsets can be used to generate the association rules.


How to Form Association Rules?

For every non-empty subset S of I, an association rule can be generated as:

S→{I−S}S \rightarrow \{I-S\}

If Support(I)Support(S)≥min_confidence\text{If } \frac{\text{Support}(I)}{\text{Support}(S)} \geq \text{min\_confidence}

Minimum Support = 30%, Minimum Confidence = 60%


Rule 1:
{milk}→{milk, bread, butter}−{milk}\{\text{milk}\} \rightarrow \{\text{milk, bread, butter}\} – \{\text{milk}\}

Therefore,

{milk}→{bread, butter}\{\text{milk}\} \rightarrow \{\text{bread, butter}\}

  • Support(I) = 6/12 = 50%
  • Support(milk) = 9/12

Confidence=Support(milk, bread, butter)Support(milk)\text{Confidence} = \frac{\text{Support}(\text{milk, bread, butter})}{\text{Support}(\text{milk})}

=6/129/12= \frac{6/12}{9/12}

=612×129=66.67%= \frac{6}{12} \times \frac{12}{9} = 66.67\%

66.67%>60%66.67\% > 60\%

→ Valid


Rule 2:
{bread}→{milk, bread, butter}−{bread}\{\text{bread}\} \rightarrow \{\text{milk, bread, butter}\} – \{\text{bread}\}

Therefore,

{bread}→{milk, butter}\{\text{bread}\} \rightarrow \{\text{milk, butter}\}

Confidence=Support(milk, bread, butter)Support(bread)\text{Confidence} = \frac{\text{Support}(\text{milk, bread, butter})}{\text{Support}(\text{bread})}

=610=60%= \frac{6}{10} = 60\%

60%≥60%60\% \geq 60\%

→ Valid


Rule 3:
{butter}→{milk, bread, butter}−{butter}\{\text{butter}\} \rightarrow \{\text{milk, bread, butter}\} – \{\text{butter}\}

Therefore,

{butter}→{milk, bread}\{\text{butter}\} \rightarrow \{\text{milk, bread}\}

Confidence=Support(milk, bread, butter)Support(butter)\text{Confidence} = \frac{\text{Support}(\text{milk, bread, butter})}{\text{Support}(\text{butter})}

=610=60%= \frac{6}{10} = 60\%

60%≥60%60\% \geq 60\%

→ Valid


Rule 4:
{milk, bread}→{milk, bread, butter}−{milk, bread}\{\text{milk, bread}\} \rightarrow \{\text{milk, bread, butter}\} – \{\text{milk, bread}\}

Therefore,

{milk, bread}→{butter}\{\text{milk, bread}\} \rightarrow \{\text{butter}\}

Confidence=Support(milk, bread, butter)Support(milk, bread)\text{Confidence} = \frac{\text{Support}(\text{milk, bread, butter})}{\text{Support}(\text{milk, bread})}

=67=85.7%= \frac{6}{7} = 85.7\%

85.7%>60%85.7\% > 60\%

→ Valid

Rule 5:

{milk, butter}→{milk, bread, butter}−{milk, butter}\{\text{milk, butter}\} \rightarrow \{\text{milk, bread, butter}\} – \{\text{milk, butter}\}

Therefore,

{milk, butter}→{bread}\{\text{milk, butter}\} \rightarrow \{\text{bread}\}

Confidence=Support({milk, bread, butter})Support(milk, butter)\text{Confidence} = \frac{\text{Support}(\{\text{milk, bread, butter}\})}{\text{Support}(\text{milk, butter})}

=67=85.7%= \frac{6}{7} = 85.7\%

85.7%≥60%85.7\% \geq 60\%

→ Valid


Rule 6:

{bread, butter}→{milk, bread, butter}−{bread, butter}\{\text{bread, butter}\} \rightarrow \{\text{milk, bread, butter}\} – \{\text{bread, butter}\}

Therefore,

{bread, butter}→{milk}\{\text{bread, butter}\} \rightarrow \{\text{milk}\}

Confidence=Support({milk, bread, butter})Support(bread, butter)\text{Confidence} = \frac{\text{Support}(\{\text{milk, bread, butter}\})}{\text{Support}(\text{bread, butter})}

=69=66.67%= \frac{6}{9} = 66.67\%

66.67%≥60%66.67\% \geq 60\%

→ Valid

Valid Association Rules

RuleConfidenceResult
Milk → Bread, Butter66.67%Valid
Bread → Milk, Butter60%Valid
Butter → Milk, Bread60%Valid
Milk, Bread → Butter85.7%Valid
Milk, Butter → Bread85.7%Valid
Bread, Butter → Milk66.67%Valid

Therefore, all 6 possible association rules are valid for the given frequent 3-itemset when the minimum confidence is 60%.

Final Set of Valid Rules

Milk→{Bread, Butter}\text{Milk} \rightarrow \{\text{Bread, Butter}\}

Bread→{Milk, Butter}\text{Bread} \rightarrow \{\text{Milk, Butter}\}

Butter→{Milk, Bread}\text{Butter} \rightarrow \{\text{Milk, Bread}\}

{Milk, Bread}→Butter\{\text{Milk, Bread}\} \rightarrow \text{Butter}

{Milk, Butter}→Bread\{\text{Milk, Butter}\} \rightarrow \text{Bread}

{Bread, Butter}→Milk\{\text{Bread, Butter}\} \rightarrow \text{Milk}