Скачать презентацию CPS 196 03 Information Management and Mining Association Скачать презентацию CPS 196 03 Information Management and Mining Association

07375018a9f12faafd90a6d71fdba10b.ppt

  • Количество слайдов: 45

CPS 196. 03: Information Management and Mining Association Rules and Frequent Itemsets 1 CPS 196. 03: Information Management and Mining Association Rules and Frequent Itemsets 1

Let Us Begin with an Example u A common marketing problem: examine what people Let Us Begin with an Example u A common marketing problem: examine what people buy together to discover patterns. 1. What pairs of items are unusually often found together at Kroger checkout? • Answer: diapers and beer. 2. What books are likely to be bought by the same Amazon customer? 2

Caveat u. A big risk when data mining is that you will “discover” patterns Caveat u. A big risk when data mining is that you will “discover” patterns that are meaningless. u. Statisticians call it Bonferroni’s principle: (roughly) if you look in more places for interesting patterns than your amount of data will support, you are bound to find “false patterns”. 3

Rhine Paradox --- (1) u. David Rhine was a parapsychologist in the 1950’s who Rhine Paradox --- (1) u. David Rhine was a parapsychologist in the 1950’s who hypothesized that some people had Extra-Sensory Perception. u. He devised an experiment where subjects were asked to guess 10 hidden cards --red or blue. u. He discovered that almost 1 in 1000 had ESP --- they were able to get all 10 right! 4

Rhine Paradox --- (2) u. He told these people they had ESP and called Rhine Paradox --- (2) u. He told these people they had ESP and called them in for another test of the same type. u. Alas, he discovered that almost all of them had lost their ESP. u. What did he conclude? w Answer on next slide. 5

Rhine Paradox --- (3) u. He concluded that you shouldn’t tell people they have Rhine Paradox --- (3) u. He concluded that you shouldn’t tell people they have ESP; it causes them to lose it. 6

“Association Rules” Market Baskets Frequent Itemsets A-priori Algorithm 7 “Association Rules” Market Baskets Frequent Itemsets A-priori Algorithm 7

The Market-Basket Model u. A large set of items, e. g. , things sold The Market-Basket Model u. A large set of items, e. g. , things sold in a supermarket. u. A large set of baskets, each of which is a small set of the items, e. g. , the things one customer buys on one day. 8

Association Rule Mining n sa tra sales records: n tio c id r me Association Rule Mining n sa tra sales records: n tio c id r me to us id c cts u od ght pr ou b market-basket data • Trend: Products p 5, p 8 often bought together 9

Support u. Simplest question: find sets of items that appear “frequently” in the baskets. Support u. Simplest question: find sets of items that appear “frequently” in the baskets. u. Support for itemset I = the number of baskets containing all items in I. u. Given a support threshold s, sets of items that appear in > s baskets are called frequent itemsets. 10

Example u. Items={milk, coke, pepsi, beer, juice}. u. Support = 3 baskets. B 1 Example u. Items={milk, coke, pepsi, beer, juice}. u. Support = 3 baskets. B 1 B 3 B 5 B 7 = = {m, c, b} {m, p, b} {c, b, j} B 2 B 4 B 6 B 8 = = {m, p, j} {c, j} {m, c, b, j} {b, c} u. What are the possible itemsets? w The Lattice of itemsets u. How would you find the frequent itemsets? 11

Example u. Frequent itemsets: {m}, {c}, {b}, {j}, {m, b}, {c, b}, {j, c}. Example u. Frequent itemsets: {m}, {c}, {b}, {j}, {m, b}, {c, b}, {j, c}. 12

Applications --- (1) u. Real market baskets: chain stores keep terabytes of information about Applications --- (1) u. Real market baskets: chain stores keep terabytes of information about what customers buy together. w Tells how typical customers navigate stores, lets them position tempting items. w Suggests tie-in “tricks, ” e. g. , run sale on diapers and raise the price of beer. u. High support needed, or no $$’s. 13

Applications --- (2) u“Baskets” = documents; “items” = words in those documents. w Lets Applications --- (2) u“Baskets” = documents; “items” = words in those documents. w Lets us find words that appear together unusually frequently, i. e. , linked concepts. u“Baskets” = sentences, “items” = documents containing those sentences. w Items that appear together too often could represent plagiarism. 14

Applications --- (3) u“Baskets” = Web pages; “items” = linked pages. w Pairs of Applications --- (3) u“Baskets” = Web pages; “items” = linked pages. w Pairs of pages with many common references may be about the same topic. w Ex: think of our two data mining textbooks u“Baskets” = Web pages p ; “items” = pages that link to p. w Pages with many of the same links may be mirrors or about the same topic. w Ex: think of people with similar interests 15

Important Point u“Market Baskets” is an abstraction that models any many-many relationship between two Important Point u“Market Baskets” is an abstraction that models any many-many relationship between two concepts: “items” and “baskets. ” w Items need not be “contained” in baskets. u. The only difference is that we count cooccurrences of items related to a basket, not vice-versa. 16

Scale of Problem u. Wal. Mart sells 100, 000 items and can store billions Scale of Problem u. Wal. Mart sells 100, 000 items and can store billions of baskets. u. The Web has over 100, 000 words and billions of pages. 17

Association Rules u. If-then rules about the contents of baskets. u{i 1, i 2, Association Rules u. If-then rules about the contents of baskets. u{i 1, i 2, …, ik} → j means: “if a basket contains all of i 1, …, ik then it is likely to contain j. u. Confidence of this association rule is the probability of j given i 1, …, ik. 18

Example + B 1 = {m, c, b} _ B 3 = {m, b} Example + B 1 = {m, c, b} _ B 3 = {m, b} _ B 5 = {m, p, b} B 7 = {c, b, j} B 2 B 4 + B 6 B 8 = = {m, p, j} {c, j} {m, c, b, j} {b, c} u. An association rule: {m, b} → c. w Confidence = 2/4 = 50%. 19

Interest u. The interest of an association rule is the absolute value of the Interest u. The interest of an association rule is the absolute value of the amount by which the confidence differs from what you would expect, were items selected independently of one another. 20

Example B 1 B 3 B 5 B 7 = = {m, c, b} Example B 1 B 3 B 5 B 7 = = {m, c, b} {m, p, b} {c, b, j} B 2 B 4 B 6 B 8 = = {m, p, j} {c, j} {m, c, b, j} {b, c} u. For association rule {m, b} → c, item c appears in 5/8 of the baskets. u. Interest = | 2/4 - 5/8 | = 1/8 --- not very interesting. 21

Relationships Among Measures u. Rules with high support and confidence may be useful even Relationships Among Measures u. Rules with high support and confidence may be useful even if they are not “interesting. ” w We don’t care if buying bread causes people to buy milk, or whether simply a lot of people buy both bread and milk. u. But high interest suggests a cause that might be worth investigating. 22

Finding Association Rules u. A typical question: “find all association rules with support ≥ Finding Association Rules u. A typical question: “find all association rules with support ≥ s and confidence ≥ c. ” w Note: “support” of an association rule is the support of the set of items it mentions. u. Hard part: finding the high-support (frequent ) itemsets. w Checking the confidence of association rules involving those sets is relatively easy. 23

Finding Association Rules u Two-step approach: 1. Frequent Itemset Generation – Generate all itemsets Finding Association Rules u Two-step approach: 1. 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 binary partitioning of a frequent itemset u Frequent itemset generation is still computationally expensive 24

Computation Model u. Typically, data is kept in a “flat file” rather than a Computation Model u. Typically, data is kept in a “flat file” rather than a database system. w Stored on disk. w Stored basket-by-basket. w Expand baskets into pairs, triples, etc. as you read baskets. 25

Computation Model --- (2) u. The true cost of mining disk-resident data is usually Computation Model --- (2) u. The true cost of mining disk-resident data is usually the number of disk I/O’s. u. In practice, association-rule algorithms read the data in passes --- all baskets read in turn. u. Thus, we measure the cost by the number of passes an algorithm takes. 26

Main-Memory Bottleneck u. In many algorithms to find frequent itemsets we need to worry Main-Memory Bottleneck u. In many algorithms to find frequent itemsets we need to worry about how main memory is used. w As we read baskets, we need to count something, e. g. , occurrences of pairs. w The number of different things we can count is limited by main memory. w Swapping counts in/out is a disaster. 27

Finding Frequent Pairs u. The hardest problem often turns out to be finding the Finding Frequent Pairs u. The hardest problem often turns out to be finding the frequent pairs. u. We’ll concentrate on how to do that, then discuss extensions to finding frequent triples, etc. 28

The Lattice of Item. Sets Given d items, there are 2 d possible candidate The Lattice of Item. Sets Given d items, there are 2 d possible candidate itemsets 29

Naïve Algorithm u. A simple way to find frequent pairs is: w Read file Naïve Algorithm u. A simple way to find frequent pairs is: w Read file once, counting in main memory the occurrences of each pair. • Expand each basket of n items into its (n -1)/2 pairs. n u. Fails if #items-squared exceeds main memory. 30

Details of Main-Memory Counting u There are two basic approaches: 1. Count all item Details of Main-Memory Counting u There are two basic approaches: 1. Count all item pairs, using a triangular matrix. 2. Keep a table of triples [i, j, c] = the count of the pair of items {i, j } is c. u (1) requires only (say) 4 bytes/pair; (2) requires 12 bytes, but only for those pairs with >0 counts. 31

4 per pair Method (1) 12 per occurring pair Method (2) 32 4 per pair Method (1) 12 per occurring pair Method (2) 32

Details of Approach (1) u. Number items 1, 2, … u. Keep pairs in Details of Approach (1) u. Number items 1, 2, … u. Keep pairs in the order {1, 2}, {1, 3}, …, {1, n }, {2, 3}, {2, 4}, …, {2, n }, {3, 4}, …, {3, n }, …{n -1, n }. u. Find pair {i, j } at the position (i – 1)(n –i /2) + j – i. u. Total number of pairs n (n – 1)/2; total bytes about 2 n 2. 33

Details of Approach (2) u. You need a hash table, with i and j Details of Approach (2) u. You need a hash table, with i and j as the key, to locate (i, j, c) triples efficiently. w Typically, the cost of the hash structure can be neglected. u. Total bytes used is about 12 p, where p is the number of pairs that actually occur. w Beats triangular matrix if at most 1/3 of possible pairs actually occur. 34

A-Priori Algorithm --- (1) u. A two-pass approach called a-priori limits the need for A-Priori Algorithm --- (1) u. A two-pass approach called a-priori limits the need for main memory. u. Key idea: monotonicity : if a set of items appears at least s times, so does every subset. w Contrapositive for pairs: if item i does not appear in s baskets, then no pair including i can appear in s baskets. 35

Illustrating Apriori Principle Found to be Infrequent Pruned supersets 36 Illustrating Apriori Principle Found to be Infrequent Pruned supersets 36

Illustrating Apriori Principle u Consider the following market-basket data Market-Basket transactions 37 Illustrating Apriori Principle u Consider the following market-basket data Market-Basket transactions 37

Illustrating Apriori Principle Items (1 -itemsets) Pairs (2 -itemsets) (No need to generate candidates Illustrating Apriori Principle Items (1 -itemsets) Pairs (2 -itemsets) (No need to generate candidates involving Coke or Eggs) Minimum Support = 3 Triplets (3 -itemsets) If every subset is considered, 6 C + 6 C = 41 1 2 3 With support-based pruning, 6 + 1 = 13 38

A-Priori Algorithm --- (2) u. Pass 1: Read baskets and count in main memory A-Priori Algorithm --- (2) u. Pass 1: Read baskets and count in main memory the occurrences of each item. w Requires only memory proportional to #items. u. Pass 2: Read baskets again and count in main memory only those pairs both of which were found in Pass 1 to be frequent. w Requires memory proportional to square of frequent items only. 39

Picture of A-Priori Item counts Frequent items Counts of candidate pairs Pass 1 Pass Picture of A-Priori Item counts Frequent items Counts of candidate pairs Pass 1 Pass 2 40

Detail for A-Priori u. You can use the triangular matrix method with n = Detail for A-Priori u. You can use the triangular matrix method with n = number of frequent items. w Saves space compared with storing triples. u. Trick: number frequent items 1, 2, … and keep a table relating new numbers to original item numbers. 41

Frequent Triples, Etc. u. For each k, we construct two sets of –tuples: k Frequent Triples, Etc. u. For each k, we construct two sets of –tuples: k w Ck = candidate k – tuples = those that might be frequent sets (support > s ) based on information from the pass for k – 1. w Lk = the set of truly frequent k –tuples. 42

C 1 Filter First pass L 1 Construct C 2 Filter L 2 Construct C 1 Filter First pass L 1 Construct C 2 Filter L 2 Construct C 3 Second pass 43

A-Priori for All Frequent Itemsets u. One pass for each k. u. Needs room A-Priori for All Frequent Itemsets u. One pass for each k. u. Needs room in main memory to count each candidate k –tuple. u. For typical market-basket data and reasonable support (e. g. , 1%), k = 2 requires the most memory. 44

Frequent Itemsets --- (2) u. C 1 = all items u. L 1 = Frequent Itemsets --- (2) u. C 1 = all items u. L 1 = those counted on first pass to be frequent. u. C 2 = pairs, both chosen from L 1. u. In general, Ck = k –tuples each k – 1 of which is in Lk-1. u. Lk = those candidates with support ≥ s. 45