5 Mining Frequent Patterns

Data Warehousing and Data Mining ยท Unit 5 ยท 6 hrs

Mining Frequent Patterns

Exam-focused notes for Mining Frequent Patterns (Data Warehousing and Data Mining, CSC420): what the TU syllabus asks and how it has actually been tested, with 6 solved past questions from this unit.

Mining Frequent Patterns in short

Finding the itemsets that occur together often in transaction data, and turning them into if-then rules, is the classic problem of frequent pattern and association rule mining. This unit works a single running example, a small nine-transaction retail database, all the way through: counting frequent itemsets level by level with Apriori, building and mining an FP-tree, generating rules with support and confidence, and finally correcting the support-confidence framework with lift.

Mining Frequent Patterns: notes

Frequent patterns

A frequent pattern is a pattern, an itemset, a subsequence, or a substructure, that appears in a data set often enough to be worth reporting. A frequent itemset is a set of items, such as milk and bread, that appears together frequently in transactions. A frequent subsequence is an ordering that recurs often, such as customers who buy a PC, then a digital camera, then a memory card, in that order, across many shopping histories. A frequent substructure is a recurring structural form, such as a sub-graph or sub-tree, for example a molecular fragment that recurs across many compounds. Finding such patterns is the foundation for mining associations, correlations, and many other relationships that hold within data.

Market basket analysis

Market basket analysis is the earliest and most direct application of frequent pattern mining. It studies customer buying habits by looking for associations between the different items customers place in a single shopping basket, for example asking how likely a customer who buys milk is to also buy bread on the same visit. The associations this analysis uncovers let a retailer design better store layouts and selective marketing, placing items that are frequently bought together within easy reach of one another, or promoting one item to customers already buying its usual companion.

Frequent itemsets, closed itemsets, association rules

A set of items is called an itemset; an itemset containing $k$ items is a $k$-itemset, so ${\text{computer}, \text{antivirus software}}$ is a 2-itemset. The support count of an itemset is simply how often it occurs across the transactions. An itemset is a frequent itemset once its support count meets or exceeds a chosen minimum support threshold. An itemset $X$ is a closed itemset in a data set $D$ if no proper superset $Y \supset X$ exists with exactly the same support count as $X$ in $D$; closed itemsets are a compact, lossless summary of all frequent itemsets, since any frequent itemset's support can be recovered from the smallest closed itemset that contains it.

An association rule is an if-then statement uncovering a relationship between otherwise unrelated data, written $A \Rightarrow B$, with an antecedent $A$ (the if part) and a consequent $B$ (the then part): "if a customer buys a dozen eggs, they are 60% likely to also buy milk" is a rule of this form. Two measures characterize a rule. Support is how often the antecedent and consequent occur together across the whole database:

$$ \mathit{support}(A \Rightarrow B) = P(A \cup B) $$

Confidence is how often the rule has been found true whenever the antecedent held, that is, the conditional probability of the consequent given the antecedent:

$$ \mathit{confidence}(A \Rightarrow B) = P(B \mid A) = \frac{\mathit{support}(A \cup B)}{\mathit{support}(A)} $$

For a first, small illustration, consider five transactions over milk, bread and butter:

TransactionMilkBreadButter
1110
2001
3000
4111
5010

For the rule $\mathit{Bread} \Rightarrow \mathit{Milk}$: bread and milk occur together in transactions 1 and 4, so $\mathit{support} = 2/5 = 40%$; bread occurs in transactions 1, 4 and 5, so $\mathit{confidence} = 2/3 \approx 66%$.

What this unit covers

  • Frequent patterns
  • Market basket analysis
  • Frequent itemsets, closed itemsets, association rules
  • Types of association rule (Single dimensional, multidimensional, multilevel, quantitative)
  • Finding frequent itemset (Apriori algorithm, FP growth)
  • Generating association rules from frequent itemset
  • Limitation and improving Apriori
  • From Association Mining to Correlation Analysis
  • Lift

Finding frequent itemset

2081 ยท 10 marks

How do you generate strong association rules? From the following dataset find the frequent item set using FP growth algorithm using 3 as minimum support.

Transaction IDItems
T1{K, E, M, O, Y}
T2{K, E, O, Y}
T3{K, E, M}
T4{K, M, Y}
T5{K, E, O}

[10]

Show solved answer

Strong Association Rules and FP-Growth

Given Data

Transactions:

  • T1: {K, E, M, O, Y}
  • T2: {K, E, O, Y}
  • T3: {K, E, M}
  • T4: {K, M, Y}
  • T5: {K, E, O}

Minimum support = 3

Part 1: Generating Strong Association Rules

A strong association rule $X \Rightarrow Y$ satisfies both thresholds:

  • $\text{support}(X \cup Y) \geq \text{min_support}$
  • $\text{confidence}(X \Rightarrow Y) = \dfrac{\text{support}(X \cup Y)}{\text{support}(X)} \geq \text{min_confidence}$

Procedure:

  1. Find all frequent itemsets satisfying min support (via Apriori or FP-Growth).
  2. For each frequent itemset $l$, generate every non-empty proper subset $s$.
  3. For each such $s$, form the rule $s \Rightarrow (l - s)$ and compute confidence $= \dfrac{\text{support}(l)}{\text{support}(s)}$.
  4. Output the rule only if confidence $\geq$ min_confidence. These are the strong rules.

Part 2: FP-Growth (min_support = 3)

Step 1: Item frequency (1st scan)

ItemCount
K5
E4
M3
O3
Y3

All satisfy min support. Order (descending, ties alphabetical): K:5, E:4, M:3, O:3, Y:3

Step 2: Reordered transactions

TIDOrdered
T1K, E, M, O, Y
T2K, E, O, Y
T3K, E, M
T4K, M, Y
T5K, E, O

Step 3: FP-Tree

null
 โ””โ”€โ”€ K:5
      โ”œโ”€โ”€ E:4
      โ”‚    โ”œโ”€โ”€ M:1
      โ”‚    โ”‚    โ””โ”€โ”€ O:1
      โ”‚    โ”‚         โ””โ”€โ”€ Y:1
      โ”‚    โ””โ”€โ”€ O:2
      โ”‚         โ””โ”€โ”€ Y:1
      โ””โ”€โ”€ M:2
           โ””โ”€โ”€ Y:1

Note on M placement:

  • T1 (KEMOY) and T3 (KEM) go under E-branch: Eโ†’M appears twice (M:2 under E).
  • T4 (KMY) goes under K directly: Kโ†’M (M:1 under K, no E).

So M under E has count 2, and M under K (no E) has count 1. Total M = 3. โœ“

Corrected FP-Tree:

null
 โ””โ”€โ”€ K:5
      โ”œโ”€โ”€ E:4
      โ”‚    โ”œโ”€โ”€ M:2   (from T1, T3)
      โ”‚    โ”‚    โ””โ”€โ”€ O:1   (T1)
      โ”‚    โ”‚         โ””โ”€โ”€ Y:1
      โ”‚    โ””โ”€โ”€ O:2   (T2, T5)
      โ”‚         โ””โ”€โ”€ Y:1   (T2)
      โ””โ”€โ”€ M:1   (T4)
           โ””โ”€โ”€ Y:1

Take care with the M counts: the correct placement is M:2 under E and M:1 under K, not the other way round.

Header table:

ItemSupportNode links
K5K:5
E4E:4
M3M:2, M:1
O3O:1, O:2
Y3Y:1, Y:1, Y:1

Step 4: Mining (bottom-up)

Item Y (support 3): Conditional pattern base:

  • {K,E,M,O}:1 (T1)
  • {K,E,O}:1 (T2)
  • {K,M}:1 (T4)

Counts: K=3, E=2, M=2, O=2. Only K:3 โ‰ฅ 3. Frequent: {K,Y}:3

Item O (support 3): Conditional pattern base:

  • {K,E,M}:1 (T1)
  • {K,E}:2 (T2, T5)

Counts: K=3, E=3, M=1. Survive: K:3, E:3. Conditional FP-tree: Kโ†’E (3). Frequent: {K,O}:3, {E,O}:3, {K,E,O}:3

Item M (support 3): Conditional pattern base:

  • {K,E}:2 (T1, T3)
  • {K}:1 (T4)

Counts: K=3, E=2. Only K:3 survives. Frequent: {K,M}:3

Item E (support 4): Conditional pattern base:

  • {K}:4

Frequent: {K,E}:4

Item K: root, no conditional patterns.

Final Frequent Itemsets (support โ‰ฅ 3)

1-itemsets:

  • {K}:5, {E}:4, {M}:3, {O}:3, {Y}:3

2-itemsets:

  • {K,E}:4
  • {K,M}:3
  • {K,O}:3
  • {E,O}:3
  • {K,Y}:3

3-itemsets:

  • {K,E,O}:3

The maximal/most useful frequent itemset is {K, E, O} with support 3.

Open this answer on its own page โ†’

2080 ยท 10 marks

Apriori Algorithm - Frequent Itemsets and Association Rules

TID Items ------ 1 Bread, Cheese, Egg, Juice 2 Bread, Cheese, Juice 3 Bread, Milk, Yogurt 4 Bread, Juice, Milk 5 Cheese, Juice, Milk - Total transactions $N = 5$ - Minimum support $= 50%$ - Minimum confidence $= 75%$ Minimum support count $= 0.50 \times 5 = 2.5$. Important interpretation note: ...

Open this answer on its own page โ†’

2079 ยท 10 marks

Drawbacks of Apriori Algorithm and FP-Growth Analysis

Drawback 1: Generation of a huge number of candidate itemsets. Apriori generates a large number of candidate itemsets at every level. If there are $10^4$ frequent 1-itemsets, it must generate more than $10^7$ candidate 2-itemsets. To discover a long frequent pattern of size 100, roughly

Open this answer on its own page โ†’

2078 ยท 10 marks

How Concept Hierarchy is Used in Extracting Information

Concept hierarchy is used in extracting information by:

  • Organizing data at different levels of abstraction
  • Enabling generalization and specialization of patterns
  • Allowing drill-down and roll-up operations for multi-level analysis
  • Facilitating hierarchical association rule mining
  • Supporting semantic understanding of discovered patterns

--- A concept hierarchy is a sequence of mappings from low-level (specific) concepts to higher-level (general) concepts. It organizes data values into levels of abstraction. How it is used in extracting information: 1. Multilevel mining: Patterns/rules can be extracted at several abstraction leve...

Open this answer on its own page โ†’

2075 ยท 10 marks

Association Rules and Apriori Algorithm Analysis

  • Support threshold (min support count) = 2 - Confidence threshold = 60% - Total transactions = 6 TID Items ------------ T1 HotDogs, Buns, Ketchup T2 HotDogs, Buns T3 HotDogs, Coke, Chips T4 Chips, Coke T5 Chips, Ketchup T6 HotDogs, Coke, Chips --- 1. Single-dimensional (Boolean) Association Rule...
Open this answer on its own page โ†’

Limitation and improving Apriori

2076 ยท 10 marks

List the problems of Apriori algorithm with its possible solutions. Consider the following transaction dataset. What association rules can be found in this set, if the minimum support is 3 and the minimum confidence is 80%?

Transaction_IDItem_List
T1{K, A, D, B}
T2{D, A, C, E, B}
T3{C, A, B, E}
T4{B, A, D}

[10]

Show solved answer

Apriori Algorithm: Problems, Solutions, and Association Rule Mining

Part 1: Problems of Apriori and Solutions

Problems

  1. Huge number of candidate itemsets. At each level Apriori generates many candidates. For example, $10^4$ frequent 1-itemsets produce roughly $\binom{10^4}{2}\approx 5\times10^7$ candidate 2-itemsets.
  2. Multiple database scans. The full database must be scanned once for every level $k$, causing heavy I/O cost.
  3. Costly pattern matching / support counting. Each candidate must be checked against every transaction.
  4. High memory usage. Storing all candidates at each iteration is infeasible for large data.

Possible Solutions

ProblemSolution
Too many candidatesHash-based technique to bucket and prune candidate k-itemsets
Repeated scansFP-Growth (only 2 scans, no candidate generation)
Large candidate setsTransaction reduction (drop transactions with no frequent itemsets)
Memory bottleneckPartitioning the database to fit in memory
Full-database costSampling a representative subset, then verify
Support counting costDynamic Itemset Counting (DIC) to reduce passes

Part 2: Association Rule Mining

Given data

  • Transactions: T1{K,A,D,B}, T2{D,A,C,E,B}, T3{C,A,B,E}, T4{B,A,D}
  • Minimum support count = 3
  • Minimum confidence = 80%
  • Total transactions = 4

Step 1: L1 (1-itemsets)

ItemCountFrequent (>=3)?
K1No
A4Yes
D3Yes
B4Yes
C2No
E2No

$L_1 = { {A}, {D}, {B} }$

Step 2: L2

Candidates: {A,D}, {A,B}, {D,B}

ItemsetTransactions containingCountFrequent?
{A,D}T1,T2,T43Yes
{A,B}T1,T2,T3,T44Yes
{D,B}T1,T2,T43Yes

$L_2 = { {A,D}, {A,B}, {D,B} }$

Step 3: L3

Candidate {A,D,B}. All subsets ({A,D},{A,B},{D,B}) are frequent, so retain.

ItemsetTransactionsCountFrequent?
{A,D,B}T1,T2,T43Yes

$L_3 = { {A,D,B} }$

No 4-itemsets possible. Terminate.

Step 4: Association Rules

$$\text{Conf}(X\Rightarrow Y)=\frac{\text{Sup}(X\cup Y)}{\text{Sup}(X)}$$

Support values: A=4, D=3, B=4, {A,D}=3, {A,B}=4, {D,B}=3, {A,D,B}=3.

From {A,D} (sup 3):

RuleConfidence>=80%?
A โ‡’ D3/4 = 75%No
D โ‡’ A3/3 = 100%Yes

From {A,B} (sup 4):

RuleConfidence>=80%?
A โ‡’ B4/4 = 100%Yes
B โ‡’ A4/4 = 100%Yes

From {D,B} (sup 3):

RuleConfidence>=80%?
D โ‡’ B3/3 = 100%Yes
B โ‡’ D3/4 = 75%No

From {A,D,B} (sup 3):

RuleConfidence>=80%?
A โ‡’ D,B3/4 = 75%No
D โ‡’ A,B3/3 = 100%Yes
B โ‡’ A,D3/4 = 75%No
A,D โ‡’ B3/3 = 100%Yes
A,B โ‡’ D3/4 = 75%No
D,B โ‡’ A3/3 = 100%Yes

Final Strong Association Rules (support >= 3, confidence >= 80%)

  1. $D \Rightarrow A$ (100%)
  2. $A \Rightarrow B$ (100%)
  3. $B \Rightarrow A$ (100%)
  4. $D \Rightarrow B$ (100%)
  5. $D \Rightarrow A,B$ (100%)
  6. $A,D \Rightarrow B$ (100%)
  7. $D,B \Rightarrow A$ (100%)
Open this answer on its own page โ†’