Docsity

Mining Frequent Patterns and Association Rules - Prof. Lise Getoor, Study notes of Computer Science

Partial preview of the text

Download Mining Frequent Patterns and Association Rules - Prof. Lise Getoor and more Study notes Computer Science in PDF only on Docsity!

CMSC828G

Principles of Data Mining

Lecture #

-^ Today’s Reading:– HMS 6.7, ch. 13•^ Today’s Lecture:– Finding Patterns and Rules - Association Rules -^ Upcoming Due Dates:– H3 due today– Project Writeup due 4/

Big Picture

PredictiveModels

DescriptiveModels

emphasis on a single attribute

full description of the data

PatternDiscovery

characterizes local aspects of data

Mining Rules

•^ Problems?– number of rules grows exponentially with the number of

attributes– among the large number of rules generated, how do wedetermine interesting rules?

What Is Association Mining?

•^ Association rule mining:–

Finding frequent patterns, associations, correlations, or causalstructures among sets of items or objects in transactiondatabases, relational databases, and other informationrepositories.

•^ Applications:–

Basket data analysis, cross-marketing, catalog design, loss-leaderanalysis, clustering, classification, etc.

•^ Examples.–

Rule form:

“Body

ead [support, confidence]”.

-^ buys(x, “diapers”)

→^ buys(x, “beers”) [0.5%, 60%]

-^ major(x, “CS”) ^ takes(x, “DB”)

→^ grade(x, “A”) [1%, 75%]

Market Basket Analysis

•^ Given some set of

items

1.^ database of transactions,2.^ each transaction is a list of items (purchased by a customer in avisit), called a

basket

•^ Find: all rules that correlate the presence of one set ofitems with that of another set of items in a basket–

E.g.,

98% of people who purchase tires and auto accessories also

get automotive services done

•^ Other problems with this structure:–

baskets = documents; items = words– baskets = web pages; items = links

Market Basket Analysis, cont

•^ Typically transaction database too large to fit in mainmemory–

common sizesnumber of transactions: 10

5 – 10

8

number of items: 10

2 – 10

6

-^ typically sparse, 0.1% chance of random purchase–^ commonly stored•

in a relational data base, Baskets(BID,item)• flat file (BID,item

,item 1

,…,item 2

)n

•^ Evaluating running time:–

count the number of passes through the data– principle cost time to read data from disk

Example: Support and Confidence

Transaction ID Items Bought

A,B,C

A,C

A,D

B,E,F

Let minimum support 50%, and minimum confidence 50%,we have:

A^ ⇒^

C^

S =?

C =?

50%^

C^ ⇒^

A^

S =?

C =?

50%^

Mining Association Rules—An Example

Transaction ID Items Bought^2000 The Apriori principle:Any subset of a frequent itemset must be frequent

A,B,C

A,C

A,D

B,E,F

Frequent Itemset Support{A}^

75%

{B}^

50%

{C}^

50%

{A,C}

50%

Min. support 50%Min. confidence 50%

For rule

A^ ⇒

C:

support = support({

A,C}) = 50%

confidence = support({

A,C})/support({

A}) = 66.6%

Finding frequent itemsets, cont.

•^ Two approaches– Proceed levelwise, first find frequent items (sets of size 1),

then frequent pairs, next frequent triples• most time consuming step is often finding pairs• one pass over the data is made for each level– Find all maximal frequent itemsets (I.e., sets S such that noproper superset of S is frequent)• one or several passes over the data

The Apriori Algorithm

•^ Join Step:

Cis generated by joining Lk^

with itselfk-

•^ Prune Step:

Any (k-1)-itemset that is not frequent cannot be a subset of a frequent k-itemset

C: Candidate itemset of size kk^ L: frequent itemset of size kk^ L= {frequent items};^1 for^ (k = 1;

L!=∅k^

;k++)

do begin

C= candidates generated fromk+^

L;k^

for each

transaction

t in database do increment the count of all candidates in

Ck+

that are contained in

t

L= candidates ink+^

Cwith min_supportk+^

endreturn^ ∪

L; k k^

How to Generate Candidates?

•^ Suppose the items in

Lare orderedk-^

•^ Step 1: self-joining

Lk-

insert into

Ck select

p.item

, p.item 1

, …, p.item 2

, q.itemk-

k-

from^ L

p, Lk-^

qk-^ where

p.item

=q.item 1

, …, p.item 1

=q.itemk-

, p.itemk-

< q.itemk-

k-

1

•^ Step 2: pruningforall

itemsets c in C

do k

forall

(k-1)-subsets s of c

do

if^ (s is not in L

)^ then delete k-

c^ from

Ck

How to Count Supports of

Candidates?

•^ Why counting supports of candidates a problem?– The total number of candidates can be very huge–

One transaction may contain many candidates

•^ Method:– Candidate itemsets are stored in a

hash-tree

  • Leaf node of hash-tree contains a list of itemsets and counts–Interior node contains a hash table–Subset function: finds all the candidates contained in atransaction

Methods to Improve Apriori’s Efficiency

-^ Hash-based itemset counting: A

k-itemset whose corresponding

hashing bucket count is below the threshold cannot be frequent• Transaction reduction: A transaction that does not contain anyfrequent k-itemset is useless in subsequent scans• Partitioning: Any itemset that is potentially frequent in DB must befrequent in at least one of the partitions of DB• Sampling: mining on a subset of given data, lower supportthreshold + a method to determine the completeness• Dynamic itemset counting: add new candidate itemsets only whenall of their subsets are estimated to be frequent

Is Apriori Fast Enough? — Performance

Bottlenecks

-^ The core of the Apriori algorithm:–

Use frequent (

k – 1)-itemsets to generate candidate frequent

k-itemsets

-^ Use database scan and pattern matching to collect counts for thecandidate itemsets• The bottleneck of

Apriori: candidate generation

  • Huge candidate sets:• 10

4 frequent 1-itemset will generate 10

7 candidate 2-itemsets

  • To discover a frequent pattern of size 100, e.g., {a

, a, …, a 12

}, one 100

needs to generate 2

100 ≈^10

30 candidates.

  • Multiple scans of database:• Needs (

n +1 ) scans,

n^ is the length of the longest pattern