Finding Frequent Itemsets and Association Rules with Apriori

Last updated

Problem Setup

Scenario:Identify the item combinations that occur frequently enough in the six transactions, then use the surviving combinations to form association rules.

Given:Six transactions containing items A, B, C, D, and E, with a minimum support of 50% and a minimum confidence of 70%.

Task:Apply Apriori to generate and filter candidate itemsets by support, continue until no larger frequent itemsets remain, and then evaluate the resulting association rules against the confidence threshold.

Need a quick refresher? Review Apriori theory

Transaction Dataset

Data Point
Items (Comma-Separated)✎
P1
a, b, c
P2
a, c, d
P3
b, c, e
P4
a, b, c, d
P5
a, c, e
P6
b, d, e

Mining Solution

Total Transactions (N): 6

Required Support Count: 3(50% of 6)

Required Confidence: 70%

Iteration 1: Finding 1-Itemsets

1. Generate Candidates (C1C_{1})Count
{a}4
{b}4
{c}5
{d}3
{e}3
2. Filter by Min Support (L1L_{1})≥ 3
{a}4
{b}4
{c}5
{d}3
{e}3

Iteration 2: Finding 2-Itemsets

1. Generate Candidates (C2C_{2})Count
{a, b}2Drop
{a, c}4
{a, d}2Drop
{a, e}1Drop
{b, c}3
{b, d}2Drop
{b, e}2Drop
{c, d}2Drop
{c, e}2Drop
{d, e}1Drop
2. Filter by Min Support (L2L_{2})≥ 3
{a, c}4
{b, c}3

Stopping Condition

The only possible 3-itemset is {a, b, c}, but its subset {a, b} has support count 2, below the required 3. By the Apriori property, {a, b, c} is pruned without another transaction scan.

Final Association Rules

Rule (X→YX \rightarrow Y)Support Count (X∪YX \cup Y)Support Count (XX)ConfidenceStatus
{a} → {c}44100 %Keep
{c} → {a}4580 %Keep
{b} → {c}3475 %Keep
{c} → {b}3560 %Drop

Final Answer

Frequent itemsets:The frequent itemsets are {a}, {b}, {c}, {d}, {e}, {a, c}, and {b, c}.

Accepted rules:{a} → {c} (100%), {c} → {a} (80%), and {b} → {c} (75%) meet the 70% confidence requirement.

The strongest accepted rule is {a} → {c}, with 100% confidence: every transaction containing a also contains c. The reverse rule has only 80% confidence because c also appears in a transaction without a. This shows why association rules must be evaluated in both directions.

Exam Takeaway

  • Convert minimum support into a count before filtering: For NN transactions and minimum support ss, use ⌈sN⌉\lceil sN \rceil as the minimum required count. An itemset meeting the threshold exactly must be retained.
  • Prune candidates using the Apriori property: A larger itemset cannot be frequent if any of its subsets are infrequent. Check the relevant subsets before counting a new candidate to avoid unnecessary scans.
  • Confidence depends on the rule's direction: For X→YX \rightarrow Y, divide the support count of X∪YX \cup Y by the support count of XX. Reversing the rule changes the denominator, so calculate each direction separately.