Experiment 10: Apriori Algorithm - Association Analysis

Consider dataset “Groceries” and apply apriori algorithm on it. What are the first 5 rules generated when the min support is 0.001 (0.1%) and min confidence is 0.9 (90%) .


Step 1: Import the required dataset

library(arules)
## Loading required package: Matrix
## 
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
## 
##     abbreviate, write

Step 2: Read the dataset.

For convenience, we have the dataset along with the apriori algorithm in the “arules” package.

data (Groceries)
G<-Groceries
inspect(G[1:5]) # View first 5 transactions.
##     items                     
## [1] {citrus fruit,            
##      semi-finished bread,     
##      margarine,               
##      ready soups}             
## [2] {tropical fruit,          
##      yogurt,                  
##      coffee}                  
## [3] {whole milk}              
## [4] {pip fruit,               
##      yogurt,                  
##      cream cheese ,           
##      meat spreads}            
## [5] {other vegetables,        
##      whole milk,              
##      condensed milk,          
##      long life bakery product}

Step 3: Now apply the apriori algorithm to get the frequent rules and specify support and confidence.

G_rules<- apriori(G,parameter = list(supp=0.001,conf=0.9))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.9    0.1    1 none FALSE            TRUE       5   0.001      1
##  maxlen target   ext
##      10  rules FALSE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 9 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [157 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 6 done [0.01s].
## writing ... [129 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].

Step 4: View the first 5 association rules.

G_rules<-sort(G_rules,by="confidence",decreasing = TRUE)
inspect(G_rules[1:5])
##     lhs                     rhs              support confidence     lift count
## [1] {rice,                                                                    
##      sugar}              => {whole milk} 0.001220132          1 3.913649    12
## [2] {canned fish,                                                             
##      hygiene articles}   => {whole milk} 0.001118454          1 3.913649    11
## [3] {root vegetables,                                                         
##      butter,                                                                  
##      rice}               => {whole milk} 0.001016777          1 3.913649    10
## [4] {root vegetables,                                                         
##      whipped/sour cream,                                                      
##      flour}              => {whole milk} 0.001728521          1 3.913649    17
## [5] {butter,                                                                  
##      soft cheese,                                                             
##      domestic eggs}      => {whole milk} 0.001016777          1 3.913649    10