여정의 기록

apriori 본문

공부/Algorithm

apriori

Chelsey 2021. 9. 16. 16:39
728x90

pruming 가지치기 ( 상관없는 데이터가 포함되는 경우의 수를 제외시킨다)

 

datarules <- apriori(data, parameter = list(support=0.006, confidence=0.25, minlen=2))

최소 support와 최소 confidence 를 지정해줌으로써 데이터를 추려낸다.

더보기

Apriori Parameter specification:  confidence minval smax arem  aval originalSupport maxtime

support         0.8    0.1    1 none FALSE            TRUE       5     0.1  minlen maxlen target  ext       1     10  rules TRUE Algorithmic control:  filter tree heap memopt load sort verbose     

0.1 TRUE TRUE  FALSE TRUE    2    TRUE Absolute minimum support count: 983  set item appearances ...[0 item(s)] done [0.00s].

set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].

sorting and recoding items ... [8 item(s)] done [0.00s]. creating transaction tree ... done [0.00s].

checking subsets of size 1 2 done [0.00s]. writing ... [0 rule(s)] done [0.00s]. creating S4 object  ... done [0.00s].

set of 0 rules 

 

Apriori Parameter specification:  confidence minval smax arem  aval originalSupport maxtime 

support        0.25    0.1    1 none FALSE            TRUE       5   0.006  minlen maxlen target  ext       2     10  rules TRUE Algorithmic control:  filter tree heap memopt load sort verbose     

0.1 TRUE TRUE  FALSE TRUE    2    TRUE Absolute minimum support count: 59  set item appearances ...[0 item(s)] done [0.00s].

set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s]. sorting and recoding items ... [109 item(s)] done [0.00s]. creating transaction tree ... done [0.00s]. checking subsets of size 1 2 3 4 done [0.01s]. writing ... [463 rule(s)] done [0.00s]. creating S4 object  ... done [0.00s].

 

if lhs then rhs 

inspect(data)

lift 에서 1보다 큰 애들을 봐야함 

 

근데 데이터를 보면 lhs에서 공집합인 경우가 있다. (before 공집합인 경우 after 뭔가 했을 확률을 배제하고자한다면)

apriori 에서 minlen을 정해준다.

공집합을 제거함으로 써 464개 -> 463개로 감소 

 

summary(data)

set of 463 rules : 463개의 rule로 구성

rule length ... sizes : 한 건당 구매한 총 상품수 (해당 행의 총합)

 

lift max 값은?

정렬을 해보자

inspect(sort(data, by="lift")[1:30]) # lift열 기준 정렬

 

특정 데이터에 대한 연관규칙을 검색

beefrules <- subset(data, items %in% "beef")
inspect(beefrules)

inspect(sort(beefrules, by="lift")[1:5])

 

728x90