Skip to main content

Apriori on restaurant orders

Short answer

Apriori with min support 2 on restaurant orders. L1={Beer,buff,coke,lemon,peanut}. L2={Beer-lemon, Beer-peanut, buff-coke, buff-lemon, coke-lemon, coke-peanut}. L3={buff,coke,lemon} (count 2). Pruning removes candidates with infrequent subsets like lemon-peanut. Algorithm stops as no C4 possible.

Write the A-priori algorithm with its pruning principle. Find the candidate and large item sets from the following transaction in a restaurant using A-priori algorithm. (Min. support: 2)

Transaction IDOrder Combination
1Beer, chicken, peanut
2Whisky, buff, coke, lemon
3Beer, buff, coke, lemon
4Buff, coke, peanut
5Beer, peanut, lemon, fish
6Peanut, coke

Apriori algorithm and pruning principle

Apriori principle: if an itemset is frequent, all its subsets are frequent; so if an itemset is infrequent, no superset of it can be frequent. This pruning removes candidates without counting them.

L1 = frequent 1-itemsets (scan database)
for k = 2; L(k-1) not empty; k++:
    Ck = join L(k-1) with itself
    prune candidates having an infrequent (k-1)-subset
    scan database, count Ck
    Lk = candidates with count >= min_support
return all Lk

Solution (minimum support = 2 transactions)

Transactions: T1 {Beer, chicken, peanut}; T2 {Whisky, buff, coke, lemon}; T3 {Beer, buff, coke, lemon}; T4 {buff, coke, peanut}; T5 {Beer, peanut, lemon, fish}; T6 {peanut, coke}.

C₁ and L₁

ItemCountFrequent?
Beer3Yes
chicken1No
peanut4Yes
Whisky1No
buff3Yes
coke4Yes
lemon3Yes
fish1No

L₁ = {Beer, buff, coke, lemon, peanut}

C₂ (all 10 pairs of L₁) and L₂

ItemsetCountFrequent?
Beer, buff1No
Beer, coke1No
Beer, lemon2Yes
Beer, peanut2Yes
buff, coke3Yes
buff, lemon2Yes
buff, peanut1No
coke, lemon2Yes
coke, peanut2Yes
lemon, peanut1No

L₂ = {Beer-lemon, Beer-peanut, buff-coke, buff-lemon, coke-lemon, coke-peanut}

C₃ (join of L₂ pairs having the same first item, then prune)

CandidateFromAll 2-subsets frequent?Count
Beer, lemon, peanutBeer-lemon + Beer-peanutNo (lemon-peanut) → pruned-
buff, coke, lemonbuff-coke + buff-lemonYes2 (T2, T3)
coke, lemon, peanutcoke-lemon + coke-peanutNo (lemon-peanut) → pruned-

L₃ = {buff, coke, lemon} (count 2). No C₄ can be formed, so the algorithm stops.

Answer: candidate sets C₁, C₂, C₃ as above. Large (frequent) itemsets: L₁ = {Beer, buff, coke, lemon, peanut}; L₂ = the six pairs; L₃ = {buff, coke, lemon}.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Mining chapter 4 questions →