Pattern Mining Concepts and Methods
Pattern Mining Concepts and Methods
Basic Concepts
Summary
1
What Are Patterns?
What are patterns?
Patterns: A set of items, subsequences, or substructures that occur
frequently together (or strongly correlated) in a data set
Patterns represent intrinsic and important properties of datasets
2
What Is Pattern Discovery?
Pattern discovery: Uncovering patterns from massive data sets
It can answer questions such as:
What products were often purchased together?
What are the subsequent purchases after buying an iPad?
3
Pattern Discovery: Why Is It Important?
Foundation for many essential data mining tasks
Association, correlation, and causality analysis
Mining sequential, structural (e.g., sub-graph) patterns
Classification: Discriminative pattern-based analysis
Cluster analysis: Pattern-based subspace clustering
Broad applications
Market basket analysis, cross-marketing, catalog design, sale
campaign analysis, Web log analysis, biological sequence
analysis
Many types of data: spatiotemporal, multimedia, time-series,
and stream data
4
Basic Concepts: Transactional Database
Transactional Database (TDB)
Each transaction is associated with an identifier, called a TID.
May also have counts associated with each item sold
5
Basic Concepts: k-Itemsets and Their Supports
Itemset: A set of one or more items Tid Items bought
1 Beer, Nuts, Diaper
2 Beer, Coffee, Diaper
k-itemset: An itemset containing k items: 3 Beer, Diaper, Eggs
7
From Frequent Itemsets to Association Rules
Compared with itemsets, association rules can be more telling
Ex. Diaper Beer
Buying diapers may likely lead to buying beers
Containing both Containing diaper
{Beer}
Beer Diaper
{Diaper}
Containing beer
{Beer} {Diaper} = {Beer, Diaper}
(Q: Are these all the rules satisfying the two conditions?)
10
Challenge: There Are Too Many Frequent Patterns!
A long pattern contains a combinatorial number of sub-patterns
How many frequent itemsets does the following TDB1 contain (minsup = 1)?
TDB1: T1: {a1, …, a50}; T2: {a1, …, a100}
Let’s have a try
1-itemsets: {a1}: 2, {a2}: 2, …, {a50}: 2, {a51}: 1, …, {a100}: 1,
2-itemsets: {a1, a2}: 2, …, {a1, a50}: 2, {a1, a51}: 1 …, …, {a99, a100}: 1,
…, …, …, …
99-itemsets: {a1, a2, …, a99}: 1, …, {a2, a3, …, a100}: 1
100-itemset: {a1, a2, …, a100}: 1
A too huge set for any
The total number of frequent itemsets:
one to compute or store!
11
Expressing Patterns in Compressed Form: Closed Patterns
How to handle such a challenge?
Solution 1: Closed patterns: A pattern (itemset) X is closed if X is
frequent, and there exists no super-pattern Y כX, with the same
support as X
Let Transaction DB TDB1: T1: {a1, …, a50}; T2: {a1, …, a100}
Suppose minsup = 1. How many closed patterns does TDB1
contain?
Two: P1: “{a1, …, a50}: 2”; P2: “{a1, …, a100}: 1”
Closed pattern is a lossless compression of frequent patterns
Reduces the # of patterns but does not lose the support
information!
12
You will still be able to say: “{a2, …, a40}: 2”, “{a5, a51}: 1”
Expressing Patterns in Compressed Form: Max-Patterns
Solution 2: Max-patterns: A pattern X is a max-pattern if X is
frequent and there exists no frequent super-pattern Y כX
Difference from close-patterns?
Do not care the real support of the sub-patterns of a max-pattern
Let Transaction DB TDB1: T1: {a1, …, a50}; T2: {a1, …, a100}
Suppose minsup = 1. How many max-patterns does TDB1 contain?
One: P: “{a1, …, a100}: 1”
Max-pattern is a lossy compression!
We only know {a1, …, a40} is frequent
But we do not know the real support of {a1, …, a40}, …, any more!
Thus in many applications, mining close-patterns is more desirable
than mining max-patterns
13
Pattern Mining: Basic Concepts and Methods
Basic Concepts
Summary
14
Efficient Pattern Mining Methods
The Downward Closure Property of Frequent Patterns
15
The Downward Closure Property of Frequent Patterns
Observation: From TDB1: T1: {a1, …, a50}; T2: {a1, …, a100}
We get a frequent itemset: {a1, …, a50}
Also, its subsets are all frequent: {a1}, {a2}, …, {a50}, {a1, a2}, …, {a1, …, a49}, …
There are some hidden relationships among frequent patterns!
The downward closure (also called “Apriori”) property of frequent patterns
If {beer, diaper, nuts} is frequent, so is {beer, diaper}
Every transaction containing {beer, diaper, nuts} also contains {beer, diaper}
Apriori: Any subset of a frequent itemset must be frequent
Efficient mining methodology
If any subset of an itemset S is infrequent, then there is no chance for S to
be frequent—why do we even have to consider S!? A sharp knife for pruning!
16
Apriori Pruning and Scalable Mining Methods
Apriori pruning principle: If there is any itemset which is
infrequent, its superset should not even be generated! (Agrawal &
Srikant @VLDB’94, Mannila, et al. @ KDD’ 94)
Scalable mining Methods: Three major approaches
Level-wise, join-based approach: Apriori (Agrawal &
Srikant@VLDB’94)
Vertical data format approach: Eclat (Zaki, Parthasarathy,
Ogihara, Li @KDD’97)
Frequent pattern projection and growth: FPgrowth (Han, Pei,
Yin @SIGMOD’00)
17
Apriori: A Candidate Generation & Test Approach
Outline of Apriori (level-wise, candidate generation and test)
Scan DB once to get frequent 1-itemset
Repeat
Generate length-(k+1) candidate itemsets from length-k frequent
itemsets
Test the candidates against DB to find frequent (k+1)-itemsets
Set k := k +1
Until no frequent or candidate set can be generated
Return all the frequent itemsets derived
18
The Apriori Algorithm (Pseudo-Code)
Ck: Candidate itemset of size k
Fk : Frequent itemset of size k
K := 1;
Fk := {frequent items}; // frequent 1-itemset
While (Fk != ) do { // when Fk is non-empty
Ck+1 := candidates generated from Fk; // candidate generation
Derive Fk+1 by counting candidates in Ck+1 with respect to TDB at minsup;
k := k + 1
}
return k Fk // return Fk generated at each level
19
The Apriori Algorithm—An Example
minsup = 2 Itemset sup
Database TDB Itemset sup
{A} 2 F1
Tid Items C1 {A} 2
{B} 3
10 A, C, D {B} 3
{C} 3
20 B, C, E 1st scan {C} 3
{D} 1
30 A, B, C, E {E} 3
{E} 3
40 B, E
C2 Itemset sup C2 Itemset
F2 Itemset sup {A, B} 1 {A, B}
{A, C} 2 {A, C} 2 {A, C}
2nd scan
{B, C} 2 {A, E} 1
{A, E}
{B, E} 3 {B, C} 2
{B, C}
{C, E} 2 {B, E} 3
{B, E}
{C, E} 2
{C, E}
20
Apriori: Implementation Tricks
How to generate candidates?
self-join self-join
Step 1: self-joining Fk
abc abd acd ace bcd
Step 2: pruning
Example of candidate-generation abcd acde
F3 = {abc, abd, acd, ace, bcd}
pruned
Self-joining: F3*F3
abcd from abc and abd
acde from acd and ace
Pruning:
acde is removed because ade is not in F3
C4 = {abcd}
21
Candidate Generation (Pseudo-Code)
Suppose the items in Fk-1 are listed in an order
self-join self-join
// Step 1: Joining
zabc zabd acd ace bcd
for each p in Fk-1
for each q in Fk-1 zabcd acde
if p.item1= q.item1, …, [Link]-2 = [Link]-2, [Link]-1 < [Link]-1 {
c = join(p, q)
// Step 2: pruning
if has_infrequent_subset(c, Fk-1)
continue // prune
else add c to Ck
}
22
Apriori: Improvements and Alternatives
Reduce passes of transaction database scans
To be discussed in
Partitioning (e.g., Savasere, et al., 1995) subsequent slides
Dynamic itemset counting (Brin, et al., 1997)
Shrink the number of candidates
To be discussed in
Hashing (e.g., DHP: Park, et al., 1995) subsequent slides
Pruning by support lower bounding (e.g., Bayardo 1998)
Sampling (e.g., Toivonen, 1996)
Exploring special data structures
Tree projection (Agarwal, et al., 2001)
H-miner (Pei, et al., 2001)
Hypecube decomposition (e.g., LCM: Uno, et al., 2004)
23
Partitioning: Scan Database Only Twice
Theorem: Any itemset that is potentially frequent in TDB must be frequent in at least
one of the partitions of TDB
Properties of Tid-Lists 20 a, b, e
30 b, c, e
t(X) = t(Y): X and Y always happen together (e.g., t(ac} = t(d})
The transaction DB in Vertical
t(X) t(Y): transaction having X always has Y (e.g., t(ac) t(ce)) Data Format
Item TidList
Frequent patterns: vertical intersections t(e) = {T10, T20, T30};
t(a) = {T10, T20}; a 10, 20
Using diffset to accelerate mining b 20, 30
t(ae) = {T10, T20}
Only keep track of differences of tids c 10, 30
d 10
t(e) = {T10, T20, T30}, t(ce) = {T10, T30} → Diffset (ce, e) = {T20}
e 10, 20, 30
26
Why Mining Frequent Patterns by Pattern Growth?
Apriori: A breadth-first search mining algorithm
First find the complete set of frequent k-itemsets
Then derive frequent (k+1)-itemset candidates
Scan DB again to find true frequent (k+1)-itemsets
Motivation for a different mining methodology
Can we develop a depth-first search mining algorithm?
For a frequent itemset ρ, can subsequent search be confined to only those
transactions that containing ρ?
Such thinking leads to a frequent pattern growth approach: FPGrowth
FPGrowth (J. Han, J. Pei, Y. Yin, “Mining Frequent Patterns without Candidate Generation,” SIGMOD 2000)
27
Example: From Transactional DB to Ordered Frequent Itemlist
Example: A Sample Transactional Database TID Items in the Transaction
100 {f, a, c, d, g, i, m, p}
200 {a, b, c, f, l, m, o}
300 {b, f, h, j, o, w}
400 {b, c, k, s, p}
Let min_support = 3 500 {a, f, c, e, l, p, m, n}
Scan DB once, find single item frequent pattern: f:4, a:3, c:4, b:3, m:3, p:3
Sort frequent items in frequency descending order, f-list F-list = f-c-a-b-m-p
Scan DB again, use the ordered frequent itemlist for each transaction to construct an
FP-tree TID Items in the Transaction Ordered, frequent itemlist
100 {f, a, c, d, g, i, m, p} f, c, a, m, p
200 {a, b, c, f, l, m, o} f, c, a, b, m
300 {b, f, h, j, o, w} f, b
400 {b, c, k, s, p} c, b, p
500 {a, f, c, e, l, p, m, n} f, c, a, m, p
28
Example: Construct FP-tree from Transaction DB
After inserting
TID Ordered, After inserting
the 1st frequent
frequent itemlist the 2nd frequent After inserting all the
Itemlist: {} {} {}
itemlist frequent itemlists
100 f, c, a, m, p “f, c, a, m, p”
“f, c, a, b, m”
200 f, c, a, b, m
f:1 f:2 f:4 c:1
300 f, b
Item Frqncy hdr Itm hdr Itm hdr
400 c, b, p
f 4 c:1 f c:2 f c:3 b:1 b:1
500 f, c, a, m, p
c 4 c c
a:1 a:2 a:3 p:1
FP-Tree Construction: a 3 a a
For each transaction, b 3 m:1 b
m:1 b:1 b m:2 b:1
insert the ordered m 3 m m
frequent itemlist into an p 3 p:1 p p:1 m:1 p p:2 m:1
FP-tree, with shared
sub-branches merged,
counts accumulated Header Table
29
Mining FP-Tree: Divide and Conquer
Based on Patterns and Data
Pattern mining can be partitioned according to current patterns
Patterns containing p: p’s conditional database: fcam:2, cb:1
p’s conditional database (i.e., the database under the condition that p exists):
transformed prefix paths of item p
Patterns having m but no p: m’s conditional database: fca:2, fcab:1
…… …… {}
min_support = 3 Conditional database of each pattern
32
FPGrowth: Mining Frequent Patterns by Pattern Growth
Essence of frequent pattern growth (FPGrowth) methodology
Find frequent single items and partition the database based on each
such single item pattern
Recursively grow frequent patterns by doing the above for each
partitioned database (also called the pattern’s conditional database)
To facilitate efficient processing, an efficient data structure, FP-tree, can
be constructed
Mining becomes
Recursively construct and mine (conditional) FP-trees
Until the resulting FP-tree is empty, or until it contains only one path—
single path will generate all the combinations of its sub-paths, each of
which is a frequent pattern
33
Scaling FP-growth by Item-Based Data Projection
What if FP-tree cannot fit in memory?—Do not construct FP-tree
“Project” the database based on frequent single items
Construct & mine FP-tree for each projected DB
Parallel projection vs. partition projection
Parallel projection: Project the DB on each frequent item
Space costly, all partitions can be processed in parallel
Partition projection: Partition the DB in order
Passing the unprocessed parts to subsequent partitions
Trans. DB Parallel projection Partition projection
Basic Concepts
Summary
36
How to Judge if a Rule/Pattern Is Interesting?
Pattern-mining will generate a large set of patterns/rules
Not all the generated patterns/rules are interesting
Interestingness measures: Objective vs. subjective
Objective interestingness measures
Support, confidence, correlation, …
Subjective interestingness measures:
Different users may judge interestingness differently
Let a user specify
Query-based: Relevant to a user’s particular request
Judge against one’s knowledge-base
unexpected, freshness, timeliness
37
Limitation of the Support-Confidence Framework
Are s and c interesting in association rules: “A B” [s, c]? Be careful!
Example: Suppose one school may have the following statistics on #
of students who may play basketball and/or eat cereal:
play-basketball not play-basketball sum (row)
eat-cereal 400 350 750
not eat-cereal 200 50 250
sum(col.) 600 400 1000
40
Lift and 2 : Are They Always Good Measures?
B ¬B ∑row
Null transactions: Transactions that contain
C 100 1000 1100
neither B nor C ¬C 1000 100000 101000
∑col. 1100 101000 102100
Let’s examine the new dataset D
null transactions
BC (100) is much rarer than B¬C (1000) and ¬BC
(1000), but there are many ¬B¬C (100000) Contingency table with expected values added
Essentially min,
max, mean variants
of 𝑝, 𝑞
42
Null Invariance: An Important Property
Why is null invariance crucial for the analysis of massive transaction data?
Many transactions may contain neither milk nor coffee!
milk vs. coffee contingency table Lift and 2 are not null-invariant: not good to
evaluate data that contain too many or too
few null transactions!
Many measures are not null-invariant!
Null-transactions
w.r.t. m and c
43
Comparison of Null-Invariant Measures
Not all null-invariant measures are created equal
Which one is better? 2-variable contingency table
D4—D6 differentiate the null-invariant measures
Kulc (Kulczynski 1927) holds firm and is in balance of
both directional implications
All 5 are null-invariant
44
Imbalance Ratio with Kulczynski Measure
IR (Imbalance Ratio): measure the imbalance of two itemsets A and B in
rule implications:
Kulczynski and Imbalance Ratio (IR) together present a clear picture for all
the three datasets D4 through D6
D4 is neutral & balanced; D5 is neutral but imbalanced
D6 is neutral but very imbalanced
45
Example: Analysis of DBLP Coauthor Relationships
DBLP: Computer science research publication bibliographic database
> 3.8 million entries on authors, paper, venue, year, and other information
Basic Concepts
Summary
48
Summary
Basic Concepts
What Is Pattern Discovery? Why Is It Important?
Basic Concepts: Frequent Patterns and Association Rules
Compressed Representation: Closed Patterns and Max-Patterns
Efficient Pattern Mining Methods
The Downward Closure Property of Frequent Patterns
The Apriori Algorithm
Extensions or Improvements of Apriori
Mining Frequent Patterns by Exploring Vertical Data Format
FPGrowth: A Frequent Pattern-Growth Approach
Mining Closed Patterns
Pattern Evaluation
Interestingness Measures in Pattern Mining
Interestingness Measures: Lift and χ2
Null-Invariant Measures
Comparison of Interestingness Measures
49
Recommended Readings (Basic Concepts)
R. Agrawal, T. Imielinski, and A. Swami, “Mining association rules between sets of
items in large databases”, in Proc. of SIGMOD'93
R. J. Bayardo, “Efficiently mining long patterns from databases”, in Proc. of
SIGMOD'98
N. Pasquier, Y. Bastide, R. Taouil, and L. Lakhal, “Discovering frequent closed itemsets
for association rules”, in Proc. of ICDT'99
J. Han, H. Cheng, D. Xin, and X. Yan, “Frequent Pattern Mining: Current Status and
Future Directions”, Data Mining and Knowledge Discovery, 15(1): 55-86, 2007
50
Recommended Readings (Efficient Pattern Mining Methods)
R. Agrawal and R. Srikant, “Fast algorithms for mining association rules”, VLDB'94
A. Savasere, E. Omiecinski, and S. Navathe, “An efficient algorithm for mining association rules in large
databases”, VLDB'95
J. S. Park, M. S. Chen, and P. S. Yu, “An effective hash-based algorithm for mining association rules”,
SIGMOD'95
S. Sarawagi, S. Thomas, and R. Agrawal, “Integrating association rule mining with relational database
systems: Alternatives and implications”, SIGMOD'98
M. J. Zaki, S. Parthasarathy, M. Ogihara, and W. Li, “Parallel algorithm for discovery of association
rules”, Data Mining and Knowledge Discovery, 1997
J. Han, J. Pei, and Y. Yin, “Mining frequent patterns without candidate generation”, SIGMOD’00
M. J. Zaki and Hsiao, “CHARM: An Efficient Algorithm for Closed Itemset Mining”, SDM'02
J. Wang, J. Han, and J. Pei, “CLOSET+: Searching for the Best Strategies for Mining Frequent Closed
Itemsets”, KDD'03
C. C. Aggarwal, M.A., Bhuiyan, M. A. Hasan, “Frequent Pattern Mining Algorithms: A Survey”, in
Aggarwal and Han (eds.): Frequent Pattern Mining, Springer, 2014
51
Recommended Readings (Pattern Evaluation)
C. C. Aggarwal and P. S. Yu. A New Framework for Itemset Generation. PODS’98
S. Brin, R. Motwani, and C. Silverstein. Beyond market basket: Generalizing
association rules to correlations. SIGMOD'97
M. Klemettinen, H. Mannila, P. Ronkainen, H. Toivonen, and A. I. Verkamo. Finding
interesting rules from large sets of discovered association rules. CIKM'94
E. Omiecinski. Alternative Interest Measures for Mining Associations. TKDE’03
P.-N. Tan, V. Kumar, and J. Srivastava. Selecting the Right Interestingness Measure for
Association Patterns. KDD'02
T. Wu, Y. Chen and J. Han, Re-Examination of Interestingness Measures in Pattern
Mining: A Unified Framework, Data Mining and Knowledge Discovery, 21(3):371-397,
2010
52