Docsity

Frequent Pattern Mining: Association Rules and Apriori Algorithm, Study notes of Computer Science

Partial preview of the text

Download Frequent Pattern Mining: Association Rules and Apriori Algorithm and more Study notes Computer Science in PDF only on Docsity!

Frequent

pattern

mining:

association

rules

November

8,^

2007

CS^

434

  • Fall

2007

What

Is

Frequent

Pattern

Mining?

•^

Frequent

pattern:

a

pattern

(a

set

of

items,

subsequences,

substructures,

etc.)

that

occurs

frequently

in

a

data

set

•^

Motivation:

Finding

inherent

regularities

in

data

–^

What

products

were

often

purchased

together?— Beer

and

diapers?!

–^

What

are

the

subsequent

purchases

after

buying

a

PC?
–^

What

kinds

of

DNA

are

sensitive

to

this

new

drug?

–^

Can

we

automatically

classify

web

documents?

-^

Broad

applications

-^

Basket

data

analysis,

cross

‐marketing,

catalog

design,

sale

campaign

analysis

-^

Web

log

(click

stream)

analysis

DNA

l^

i

November

8,^

2007

CS^

434

  • Fall

2007

-^

DNA

sequence

analysis

Definition:

Frequent

Itemset

•^

Itemset^ –

A

collection

of

one

or

more

items

-^

Example: {Milk Bread Diaper}Example:

{Milk

,^ Bread

,^ Diaper}

-^

k‐itemset^ •

An

itemset that

contains

k^

items

•^

Support count (

σ )

TID

Items

1

Bread, Milk

2

Bread Diaper Beer Eggs

Support

count

( σ

-^

Frequency

of

occurrence

of

an

itemset

-^

E.g.

σ

({Milk,

Bread,Diaper})

=^

2

•^

Support

2

Bread, Diaper, Beer, Eggs

3

Milk, Diaper, Beer, Coke

4

Bread, Milk, Diaper, Beer

5

Bread Milk Diaper Coke

•^

Support^ –

Fraction

of

transactions

that

contain

an

itemset

-^

E g

s({Milk Bread Diaper}) = 2/

5

Bread, Milk, Diaper, Coke

E.g.

s({Milk

,^ Bread

,^ Diaper})

2/

•^

Frequent

Itemset

-^

An

itemset whose

support

is

greater

than

or equal to a

minsup

threshold

or

equal

to

a^

minsup

threshold

Definition:

Association

Rule

z^

Association

Rule

-^

An

implication

expression

of

the

form

X^ →

Y where X and Y are

itemsets

TID

Items

1

Bread, Milk

X^ →

Y,

where

X

and

Y^

are

itemsets

-^

Example:{Milk,

Diaper}

→

{Beer}

2

Bread, Diaper, Beer, Eggs

3

Milk, Diaper, Beer, Coke

4

Bread, Milk, Diaper, Beer

Example:

z^

Rule

Evaluation

Metrics

-^

Support

(s)

‹^

F^

ti^

f t

ti^

th t

t i

5

Bread, Milk, Diaper, Coke

Example:

Beer

Diaper,

Milk{

Beer

Diaper,,

Milk(

σ

‹^

Fraction

of

transactions

th

at^

contain

both

X^

and

Y:

P(X

^^

Y)

-^

Confidence

(c)

‹^

Measures how often items in Y

T|

p^

(^

s

Beer

Diaper,

Milk,(

σ

c

‹^

Measures

how

often

items

in

Y

appear

in

transactions

that

contain

X^

:^ P(Y|X)

Diaper,

Milk(

σ

c

November

8,^

2007

5

CS^

434

  • Fall

2007

Brute

‐force solution

Brute

force

solution

•^

List

all possible association rules

List

all

possible

association

rules

•^

Compute

the

support

and

confidence

for

each

rulerule

•^

Prune

rules

that

fail

the

min_sup

and

i^

f^

h

h ld

min_conf

thresholds

Computationally

prohibitive!

November

8,^

2007

CS^

434

  • Fall

2007

Mining Association RulesMining

Association

Rules

Example

of

Rules:

{Milk Diaper}

{Beer} (s=0 4 c=0 67)

TID

Items

1

B^

d Milk

{Milk

,Diaper}

{Beer}

(s=

c=

{Milk,Beer}

{Diaper}

(s=0.4,

c=1.0)

{Diaper,Beer}

{Milk}

(s=0.4,

c=0.67)

{Beer}

{Milk,

Diaper}

(s

c=0.67)

1

Bread, Milk

2

Bread, Diaper, Beer, Eggs

3

Milk, Diaper, Beer, Coke

{ eer}

{Milk,

iaper} (s 0.4, c 0.67)

{Diaper}

{Milk,Beer}

(s=0.4,

c=0.5)

{Milk}

{Diaper,Beer}

(s=0.4,

c=0.5)

4

Bread, Milk, Diaper, Beer

5

Bread, Milk, Diaper, Coke

Observations: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

Th

d^

l^

h^

d^

fid

i

  • Thus,

we

may

d

ecouple

the

support

and

confidence

requirements

  • We

can

first

find

all

frequent

itemsets that

satisfy

the

support

requirement

Frequent Itemset GenerationFrequent

Itemset

Generation

null

A^

B^

C^

D^

E

AB

AC

AD

AE

BC

BD

BE

CD

CE

DE

AB

AC

AD

AE

BC

BD

BE

CD

CE

DE

ABC

ABD

ABE

ACD

ACE

ADE

BCD

BCE

BDE

CDE

ABCD

ABCE

ABDE

ACDE

BCDE

Given

d

items,

there

are

d 2 possible

candidate

ABCDE

p itemsets

November

8,^

2007

CS^

434

  • Fall

2007

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

Transactions

TID

Items

1

Bread, Milk

2

B^

d Di

B^

E

Transactions

2

Bread, Diaper, Beer, Eggs

3

Milk, Diaper, Beer, Coke

4

Bread, Milk, Diaper, Beer

5

Bread, Milk, Diaper, Coke

Match

each

transaction

against

every

candidate

C

l^

i^

O(NM

)^

E^

i^

i^

M

d 2 !!!

5

Bread, Milk, Diaper, Coke

C

omplexity

~

O(

NM

w)

=>

E

xpensive

since

M

=

2

d^

!!!

Reducing Number of CandidatesReducing

Number

of

Candidates

-^

Apriori

principle:

–^

If^

an

itemset

is

frequent,

then

all

of

its

subsets

must

also

be

frequent

f^ {b

di

}^ i

f

i^

{b

di

–^

If^

{b

eer,

di

aper,

nuts}

is

frequent,

so

is

{b

eer,

di

aper}

–^

i.e.,

every

transaction

having

{beer,

diaper,

nuts}

also

contains

{beer,

diaper}

-^

Apriori

principle

holds

due

to

the

following

property

of

the

t

support

measure:

,^

Y s X s Y X Y X

–^

Support

of

an

itemset

never

exceeds

the

support

of

its

subsets

–^

This

is

known

as

the

anti

‐monotone property

of

support

November

8,^

2007

CS^

434

  • Fall

2007

Illustrating

Apriori

Principle

g^

p

p

Found

to

be

InfrequentInfrequent

Pruned supersets

November

8,^

2007

CS^

434

  • Fall

2007

Apriori AlgorithmApriori

Algorithm

•^

Method:^ –

Let

k=

Generate

frequent

itemsets

of

length

1

Repeat

until

no

new

frequent

itemsets

are

identified

-^

Generate

length

(k+1)

candidate

itemsets

from

length

k

frequent

itemsets

q

-^

Prune

candidate

itemsets

containing

subsets

of

length

k

that

are

infrequent

-^

Count the support of each candidate by scanning the DBCount

the

support

of

each

candidate

by

scanning

the

DB

-^

Eliminate

candidates

that

are

infrequent,

leaving

only

those

that

are

frequent

November

8,^

2007

CS^

434

  • Fall

2007

The

Apriori

Algorithm—An

Example

Database TDB

C

L

1

Tid

Items

Itemset

sup

{A}

2

{B}

3

Itemset

sup

{A}

2

Sup

min

= 2 st 1 scan

C

1

1

Tid

Items

10

A, C, D

20

B, C, E

30

A B C E

{B}

3

{C}

3

{D}

1

{E}

3

{B}

3

{C}

3

{E}

3

L

C

2

C

2

nd 2

30

A, B, C, E

40

B, E

{E}

3

Itemset

Itemset

sup

{A, B}

1

It^

t

L^2

nd 2

scan

{A, B}{A, C}{A, E}{^

C}

{^

,^

} {A, C}

2

{A, E}

1

{B, C}

2

Itemset

sup

{A, C}

2

{B, C}

2

{B E}

3

{B, C}{B, E}{C, E}

{B, E}

3

{C, E}

2

{B, E}

3

{C, E}

2

C

3

L

3

rd 3 scan

Itemset {B, C, E}

Itemset

sup

{B, C, E}

2

November

8,^

2007

CS^

434

  • Fall

2007

Important Details of AprioriImportant

Details

of

Apriori

•^

How

to

generate

candidates?

-^

Step

1:

self

‐joining

L^ k

-^

Step

2:

pruning

•^

How

to

count

supports

of

candidates?

•^

Example of Candidate generation

-^

Example

of

Candidate

‐generation

-^

L

= {

abc,

abd,

acd,

ace,

bcd

}

-^

Self

‐joining:

L^3

*L

3

-^

abcd

from

abc

and

abd

-^

acde

from

acd

and

ace

-^

Pruning:

-^

acde

is

removed

because

ade

is

not

in

L^3

-^

C^4

={

abcd

}

November

8,^

2007

CS^

434

  • Fall

2007

How

to

Generate

Candidates?

-^

Suppose

the

items

in

Lk

‐^1

are

listed

in

an

order

-^

Step

1:

self

‐joining

L

k‐^1

insert

into

C^ k

l^

i^

i^

i^

i

select

p.item

,^1 p.item

,^2 …,

p.item

k‐^1

,^ q.item

k‐^1

from

L^ k

‐^1

p,

L^ k

q‐ 1

where

p.item

=q.item 1

,^1 …,

p.item

k‐^2

=q.item

k‐^2

,^ p.item

k‐^1

<^ q.item

k‐^1

-^

Step

2:

pruning

forall

itemsets

c^

in

C

do k^

forall

(k

1)

subsets s of c

do

forall

(k

‐1)

‐subsets

s^

of

c^

do

if^

(s

is

not

in

L

k‐^1

)^ then

delete

c

from

C

k

November

8,^

2007

CS^

434

  • Fall

2007