DATA MINING - DL360 Fall 200 An introductory class in data mining http://www.it.uu.se/edu/course/homepage/infoutv/ht0 Kjell Orsborn Uppsala Database Laboratory Department of Information Technology, Uppsala University, Uppsala, Sweden
Data Mining Association Analysis: Basic Concepts and Algorithms (Tan, Steinbach, Kumar ch. 6) Kjell Orsborn Department of Information Technology Uppsala University, Uppsala, Sweden
Market basket analysis - Association rule mining Given a set of transactions, find rules that will predict the occurrence of an based on the occurrences of other items in the transaction Market-Basket transactions TID Items Bread, Milk 2 Bread, Diaper, Beer, Eggs 3 Milk, Diaper, Beer, Coke 4 Bread, Milk, Diaper, Beer 5 Bread, Milk, Diaper, Coke Example of Association R {Diaper} {Beer}, {Milk, Bread} {Eggs,C {Beer, Bread} {Milk}, Implication means co-occurre not causality!
Definition: frequent itemset Itemset A collection of one or more items Example: {Milk, Bread, Diaper} k-itemset An itemset that contains k items Support count (σ) Frequency of occurrence of an itemset E.g. σ({milk, Bread,Diaper}) = 2 Support Fraction of transactions that contain an itemset E.g. s({milk, Bread, Diaper}) = 2/5 Frequent Itemset An itemset whose support is greater than or equal to a minsup threshold TID Items Bread, Milk 2 Bread, Diaper, Bee 3 Milk, Diaper, Beer 4 Bread, Milk, Diape 5 Bread, Milk, Diape
Definition: association rule Association Rule An implication expression of the form X Y, where X and Y are itemsets Example: {Milk, Diaper} {Beer} Rule Evaluation Metrics Support (s) Fraction of transactions that contain both X and Y Confidence (c) Measures how often items in Y appear in transactions that contain X c s TID Example: Items Bread, Milk 2 Bread, Diaper, Beer, E 3 Milk, Diaper, Beer, Co 4 Bread, Milk, Diaper, B 5 Bread, Milk, Diaper, C { Milk, Diaper}! (Milk, Diaper,Beer) =! T! (Milk, Diaper,Beer) =! (Milk, Diaper) = = 2 3 2 5
Association rule mining task Given a set of transactions T, the goal of association rule mining is to find having support minsup threshold confidence minconf threshold Brute-force approach: List all possible association rules Compute the support and confidence for each rule Prune rules that fail the minsup and minconf thresholds Computationally prohibitive!
Mining association rules TID Items Bread, Milk 2 Bread, Diaper, Beer, Eggs 3 Milk, Diaper, Beer, Coke 4 Bread, Milk, Diaper, Beer 5 Bread, Milk, Diaper, Coke Example of Rules: {Milk,Diaper} {Beer} (s=0.4, c {Milk,Beer} {Diaper} (s=0.4, c {Diaper,Beer} {Milk} (s=0.4, c {Beer} {Milk,Diaper} (s=0.4, c {Diaper} {Milk,Beer} (s=0.4, c {Milk} {Diaper,Beer} (s=0.4, c Observations: All the above rules are binary partitions of the same itemset: {Milk, Diaper, Beer} Rules originating from the same itemset have identical support but can have different confidence Thus, we may decouple the support and confidence requirements
Mining association rules Two-step approach:. Frequent Itemset Generation Generate all itemsets whose support minsup 2. Rule Generation Generate high confidence rules from each frequent itemset, where each rule is a partitioning of a frequent itemset Frequent itemset generation is still computationally expensive
Frequent itemset generation null A B C D E AB AC AD AE BC BD BE CD CE DE ABC ABD ABE ACD ACE ADE BCD BCE BDE CDE Given d items, there are 2 d possible candidate itemsets ABCD ABCE ABDE ACDE BCDE ABCDE
Frequent itemset generation Brute-force approach: Each itemset in the lattice is a candidate frequent itemset Count the support of each candidate by scanning the database N Transactions TID Items Bread, Milk 2 Bread, Diaper, Beer, Eggs 3 Milk, Diaper, Beer, Coke 4 Bread, Milk, Diaper, Beer 5 Bread, Milk, Diaper, Coke w List of Candidates M Match each transaction against every candidate Complexity ~ O(NMw), according to Tan et al. => Expensive since M = 2 d!! (actually ~ O(NMw 2 /2) is probably a better estimation of the brute force approach
Computational complexity Given d unique items: Total number of itemsets = 2 d Total number of possible association rules: 2 3 +! = % & ' +, - (. ) * +, - = +! =! = / / d d d k k d j d k d R If d = 6, R = 602 rules
Frequent itemset generation strategies Reduce the number of candidates (M) Complete search: M = 2 d Use pruning techniques to reduce M Reduce the number of transactions (N) Reduce size of N as the size of itemset increases Used by DHP (dynamic hashing and pruning) and vertical-based mining algor Reduce the number of comparisons (NM) Use efficient data structures to store the candidates or transactions No need to match every candidate against every transaction
Reducing number of candidates Apriori principle: If an itemset is frequent, then all of its subsets must also be frequent Apriori principle holds due to the following property of the support measu $ X, Y : ( X # Y ) " s( X )! s( Y ) Support of an itemset never exceeds the support of its subsets This is known as the anti-monotone property of support
Illustrating Apriori principle null A B C D E AB AC AD AE BC BD BE CD C und to be requent ABC ABD ABE ACD ACE ADE BCD BCE B ABCD ABCE ABDE ACDE BCDE Pruned supersets ABCDE
Illustrating Apriori principle Item Count Bread 4 Coke 2 Milk 4 Beer 3 Diaper 4 Eggs Minimum Support = 3 Items (-itemsets) Itemset Count {Bread,Milk} 3 {Bread,Beer} 2 {Bread,Diaper} 3 {Milk,Beer} 2 {Milk,Diaper} 3 {Beer,Diaper} 3 Pairs (2-itemsets) (No need to genera candidates involving or Eggs) Triplets (3-it f every subset is considered, 6 C + 6 C 2 + 6 C 3 = 4 ith support-based pruning, 6 + 6 + = 3 Itemset Cou {Bread,Milk,Diaper} 3
Apriori algorithm Method: Let k= Generate frequent itemsets of length Repeat until no new frequent itemsets are identified Generate length (k+) candidate itemsets from length k frequent itemsets Prune candidate itemsets containing subsets of length k that are infrequent Count the support of each candidate by scanning the DB Eliminate candidates that are infrequent, leaving only those that are frequent
Reducing number of comparisons Candidate counting: Scan the database of transactions to determine the support of each candidate itemset To reduce the number of comparisons, store the candidates in a hash structure Instead of matching each transaction against every candidate, match it against candidates contained in the hashed buckets Transactions Hash Structure N TID Items Bread, Milk 2 Bread, Diaper, Beer, Eggs 3 Milk, Diaper, Beer, Coke 4 Bread, Milk, Diaper, Beer 5 Bread, Milk, Diaper, Coke k Buckets
Generate hash tree Suppose you have 5 candidate itemsets of length 3: { 4 5}, { 2 4}, {4 5 7}, { 2 5}, {4 5 8}, { 5 9}, { 3 6}, {2 3 4}, {5 6 7}, {3 4 5}, {3 5 6}, {6 8 9}, {3 6 7}, {3 6 8} You need: Hash function Max leaf size: max number of itemsets stored in a leaf node (if number of candida itemsets exceeds max leaf size, split the node) Hash function 3,6,9,4,7 2,5,8 4 5 2 4 4 5 7 2 5 4 5 8 2 3 4 5 6 7 3 4 5 3 5 6 3 6 3 5 7 6 8 9 5 9
Association rule discovery: hash tree Hash Function Candidate Hash Tree,4,7 3,6,9 2,5,8 Hash on, 4 or 7 4 5 3 6 2 4 2 5 5 9 4 5 7 4 5 8 2 3 4 5 6 7 3 4 5 3 5 6 3 5 7 6 8 9
Association rule discovery: hash tree Hash Function Candidate Hash Tree,4,7 3,6,9 2,5,8 Hash on 2, 5 or 8 4 5 3 6 2 4 2 5 5 9 4 5 7 4 5 8 2 3 4 5 6 7 3 4 5 3 5 6 3 5 7 6 8 9
Association rule discovery: hash tree Hash Function Candidate Hash Tree,4,7 3,6,9 2,5,8 Hash on 3, 6 or 9 4 5 3 6 2 4 2 5 5 9 4 5 7 4 5 8 2 3 4 5 6 7 3 4 5 3 5 6 3 5 7 6 8 9
Subset operation Given a transaction t, what are the possible subsets of size 3? Transaction, t 2 3 5 6 Level 2 3 5 6 2 3 5 6 3 5 6 Level 2 2 3 5 6 3 5 6 5 6 2 3 5 6 2 5 6 3 5 6 2 3 2 5 2 6 3 5 3 6 5 6 2 3 5 2 3 6 2 5 6 3 5 6 Level 3 Subsets of 3 items
Subset operation using hash tree 2 3 5 6 transaction Hash Function + 2 3 5 6 2 + 3 5 6,4,7 3,6,9 3 + 5 6 2,5,8 2 3 4 5 6 7 4 5 3 6 2 4 2 5 5 9 4 5 7 4 5 8 3 4 5 3 5 6 3 6 7 3 5 7 3 6 8 6 8 9
Subset operation using hash tree 2 3 5 6 transaction Hash Fu 2 + 3 + 3 5 6 5 6 + 2 3 5 6 2 + 3 5 6 3 + 5 6,4,7 2,5,8 5 + 6 2 3 4 5 6 7 4 5 3 6 2 4 2 5 5 9 4 5 7 4 5 8 3 4 5 3 5 6 3 6 7 3 5 7 3 6 8 6 8 9
Subset operation using hash tree 2 3 5 6 transaction Hash Fu 2 + 3 + 3 5 6 5 6 + 2 3 5 6 2 + 3 5 6 3 + 5 6,4,7 2,5,8 5 + 6 2 3 4 5 6 7 4 5 3 6 2 4 2 5 5 9 4 5 7 4 5 8 3 4 5 3 5 6 3 5 7 6 8 9 3 6 7 3 6 8 Match transaction against 9 out of 5 candidat
Factors affecting complexity Choice of minimum support threshold lowering support threshold results in more frequent itemsets this may increase number of candidates and max length of frequent itemsets Dimensionality (number of items) of the data set more space is needed to store support count of each item if number of frequent items also increases, both computation and I/O costs may also increase Size of database since Apriori makes multiple passes, run time of algorithm may increase with number transactions Average transaction width transaction width increases with denser data sets This may increase max length of frequent itemsets and traversals of hash tree (number o subsets in a transaction increases with its width)
Compact representation of frequent itemsets Some itemsets are redundant because they have identical support as their supersets A A2 A3 A4 A5 A6 A7 A8 A9 A0 B B2 B3 B4 B5 B6 B7 B8 B9 B0 C C2 C3 C4 C5 C6 C7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Number of frequent itemsets Need a compact representation = ' 0$ " = & # 3 0 (!% k k
Maximal frequent itemset An itemset is maximal frequent if none of its immediate supersets is frequent null Maximal Itemsets A B C D E AB AC AD AE BC BD BE CD CE D ABC ABD ABE ACD ACE ADE BCD BCE BDE C ABCD ABCE ABDE ACDE BCDE Infrequent Itemsets ABCD Border
Closed itemset An itemset is closed if none of its immediate supersets has the same support as the TID Items {A,B} 2 {B,C,D} 3 {A,B,C,D} 4 {A,B,D} 5 {A,B,C,D} Itemset Support {A} 4 {B} 5 {C} 3 {D} 4 {A,B} 4 {A,C} 2 {A,D} 3 {B,C} 3 {B,D} 4 {C,D} 3 Itemset {A,B,C} {A,B,D} {A,C,D} {B,C,D} {A,B,C,D}
Maximal vs closed itemsets ID Items ABC 2 ABCD 3 BCE 4 ACDE 5 DE 24 23 234 245 345 A B C D E 2 24 24 4 23 2 3 24 34 AB AC AD AE BC BD BE CD CE null Transaction Ids 2 2 24 4 4 2 3 ABC ABD ABE ACD ACE ADE BCD BCE BDE 2 4 ABCD ABCE ABDE ACDE BCDE Not supported by any transactions
Maximal vs closed frequent itemsets Minimum support = 2 null Closed but not maximal 24 23 234 245 345 A B C D E Closed and maximal 2 24 24 4 23 2 3 24 34 45 AB AC AD AE BC BD BE CD CE DE 2 2 24 4 4 2 3 4 ABC ABD ABE ACD ACE ADE BCD BCE BDE CDE 2 4 ABCD ABCE ABDE ACDE BCDE # Closed = 9 # Maximal = 4 ABCDE
Maximal vs closed itemsets Frequent Itemsets Closed Frequent Itemsets Maximal Frequent Itemsets
Rule Generation Given a frequent itemset L, find all non-empty subsets f L such that f satisfies the minimum confidence requirement If {A,B,C,D} is a frequent itemset, candidate rules: ABC D, ABD C, ACD B, BCD A, A BCD, B ACD, C ABD, D ABC AB CD, AC BD, AD BC, BC AD, BD AC, CD AB, If L = k, then there are 2 k 2 candidate association rules (ignoring L L)
Rule Generation How to efficiently generate rules from frequent itemsets? In general, confidence does not have an anti-monotone property c(abc D) can be larger or smaller than c(ab D) But confidence of rules generated from the same itemset has an anti-monoton e.g., L = {A,B,C,D}: c(abc D) c(ab CD) c(a BCD) Confidence is anti-monotone w.r.t. number of items on the RHS of the rule
Lattice of rules Low Confidence Rule Rule generation for Apriori algorithm ABCD=>{ } BCD=>A ACD=>B ABD=>C ABC=>D CD=>AB BD=>AC BC=>AD AD=>BC AC=>BD Pruned Rules D=>ABC C=>ABD B=>ACD A=>BCD
Rule generation for Apriori algorithm Candidate rule is generated by merging two rules that share the same prefi in the rule consequent join(cd=>ab,bd=>ac) would produce the candidate rule D => ABC CD=>AB BD=>AC Prune rule D=>ABC if its subset AD=>BC does not have high confidence D=>ABC
Rule generation algorithm Key fact: Algorithm Moving items from the antecedent to the consequent never changes support, and never increases confidence For each itemset I with minsup: Find all minconf rules with a single consequent of the form (I - L L ) Repeat: Guess candidate consequents C k by appending items from I - L k- to L k- Verify confidence of each rule I - C k C k using known itemset support values
Algorithm to generate association rules
Pattern evaluation Association rule algorithms tend to produce too many rules many of them are uninteresting or redundant Redundant if {A,B,C} {D} and {A,B} {D} have same support & confidence Interestingness measures can be used to prune/rank the derived patterns In the original formulation of association rules, support & confidence are measures used
Application of Interestingness measure Interestingness Measures
Computing Interestingness measure Given a rule X Y, information needed to compute rule interestingness ca obtained from a contingency table Contingency table for X Y X X Y f f 0 f + Y f 0 f 00 f +0 f + f o+ T f : support of X and Y f 0 : support of X and Y f 0 : support of X and Y f 00 : support of X and Y Used to define various measure support, confidence, lift, Gini, J-measure, etc.
Drawback of Confidence Coffee Coffee Tea 5 5 20 Tea 75 5 80 90 0 00 Association Rule: Tea Coffee Confidence= P(Coffee Tea) = s(t&c)/s(t) = 0.75 but P(Coffee) = 0.9 Although confidence is high, rule is misleading P(Coffee Tea) = 0.9375
Statistical independence Population of 000 students 600 students know how to swim (S) 700 students know how to bike (B) 420 students know how to swim and bike (S,B) P(S B) = 420/000 = 0.42 P(S) P(B) = 0.6 0.7 = 0.42 P(S B) = P(S) P(B) => Statistical independence P(S B) > P(S) P(B) => Positively correlated P(S B) < P(S) P(B) => Negatively correlated
Statistical-based measures Measures that take into account statistical dependence ( ) Lift = P Y X P Y ( ) Interest(I) = = c(x " Y) s(y) P ( X,Y ) P( X)P( Y) = Nf /( f + f ) + PS = P(X,Y) " P(X)P(Y) P(X,Y) # P(X)P(Y) " # coefficient = P(X)[# P(X)]P(Y)[# P(Y)]
Example: Lift/Interest Coffee Coffee Tea 5 5 20 Tea 75 5 80 90 0 00 Association Rule: Tea Coffee Confidence = P(Coffee Tea) = 0.75 However: P(Coffee) = 0.9 Lift = 0.75/0.9= 0.8333 (<, therefore is slightly negatively co
Drawback of Lift & Interest Y Y Y Y X 0 0 0 X 90 0 X 0 90 90 X 0 0 0 90 00 90 0 0. Lift = = 0 0.9 Lift = = (0.)(0.) (0.9)(0.9) Statistical independence: If P(X,Y)=P(X)P(Y) => Lift =
ere are lots of asures proposed in literature me measures are od for certain plications, but not others w can we determine ether a measure is od or bad?
Property under variable permutation Does M(A,B) = M(B,A)? Symmetric measures: support, lift, collective strength, cosine, Jaccard, etc Asymmetric measures: confidence, conviction, Laplace, J-measure, etc
Property under Row/Column Scaling Grade-Gender example (Mosteller, 968): Male Female Male Female High 2 3 5 High 4 30 Low 4 5 Low 2 40 3 7 0 6 70 2x 0x Mosteller: Underlying association should be independent of the relative number of male and female students in the samples
Property under Inversion operation 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A B C D (a) (b) 0 0 (c) E F Transaction Transaction N.....
Example: φ-coefficient φ-coefficient is analogous to correlation coefficient for continuous variable Y Y Y Y X 60 0 70 X 20 0 X 0 20 30 X 0 60 70 30 00 30 70 # = = 0.6 " 0.7! 0.7 0.7! 0.3! 0.7! 0.3 0.2 " 0.3! 0 # = 0.7! 0.3! 0.7 0.5238 = 0.5238 φ Coefficient is the same for both tables
Property under Null addition Invariant measures: cosine, Jaccard, etc Non-invariant measures: support, correlation, Gini, odds ratio, etc
Symmetric objective measures Also support: S = f / f + f 0 + f 0 + f 00 = f / N
Assymetric objective measures Also Confidence: C = f / f + f 0 = f / f +
Properties of symmetric/asymmetric measure Asymmetric measures, such as confidence, conviction, Laplace and J- measure, do not preserve their values under inversion and row/col scaling are invariant under the null addition operation
Rankings of symmetric measures
Rankings of asymmetric measures
Subjective Interestingness Measure Objective measure: Rank patterns based on statistics computed from data e.g. measures of association (support, confidence, Laplace, Gini, mutual infor Jaccard, etc). Subjective measure: Rank patterns according to user s interpretation A pattern is subjectively interesting if it contradicts the expectation of a user (Silberschatz & Tuzhilin) A pattern is subjectively interesting if it is actionable (Silberschatz & Tuzhilin)