To capture the different set of rule values for Transaction Retail datasets using apriori algorithm.

Also Observe the change in number of rules for different support,confidence values

install.packages("rmarkdown",repos = "http://cran.us.r-project.org")
## Installing package into 'C:/Users/tswaminathan/Documents/R/win-library/3.5'
## (as 'lib' is unspecified)
## package 'rmarkdown' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\tswaminathan\AppData\Local\Temp\RtmpGkj4Ij\downloaded_packages
install.packages("arules",repos = "http://cran.us.r-project.org")
## Installing package into 'C:/Users/tswaminathan/Documents/R/win-library/3.5'
## (as 'lib' is unspecified)
## package 'arules' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\tswaminathan\AppData\Local\Temp\RtmpGkj4Ij\downloaded_packages
install.packages("arulesViz",repos = "http://cran.us.r-project.org")
## Installing package into 'C:/Users/tswaminathan/Documents/R/win-library/3.5'
## (as 'lib' is unspecified)
## package 'arulesViz' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\tswaminathan\AppData\Local\Temp\RtmpGkj4Ij\downloaded_packages
library(arules)
## Loading required package: Matrix
## 
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
library(arulesViz)
## Loading required package: grid
TransRetail <- read.csv(file.choose())

View(TransRetail)

rules <- apriori(TransRetail,parameter=list(support=0.003, confidence = 0.8,minlen=5))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.8    0.1    1 none FALSE            TRUE       5   0.003      5
##  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: 1671 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[4754 item(s), 557040 transaction(s)] done [1.04s].
## sorting and recoding items ... [307 item(s)] done [0.02s].
## creating transaction tree ... done [0.41s].
## checking subsets of size 1 2 3 4 5 done [0.00s].
## writing ... [8 rule(s)] done [0.00s].
## creating S4 object  ... done [0.06s].
# Provided the rules with 0.3% Support, 80 % Confidence and Purchased a minimum of 3 items

rules
## set of 8 rules
summary(rules)
## set of 8 rules
## 
## rule length distribution (lhs + rhs):sizes
## 5 
## 8 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       5       5       5       5       5       5 
## 
## summary of quality measures:
##     support           confidence      lift           count     
##  Min.   :0.003704   Min.   :1    Min.   :26.93   Min.   :2063  
##  1st Qu.:0.003704   1st Qu.:1    1st Qu.:37.11   1st Qu.:2063  
##  Median :0.003977   Median :1    Median :62.95   Median :2216  
##  Mean   :0.003977   Mean   :1    Mean   :57.92   Mean   :2216  
##  3rd Qu.:0.004251   3rd Qu.:1    3rd Qu.:78.42   3rd Qu.:2368  
##  Max.   :0.004251   Max.   :1    Max.   :80.56   Max.   :2368  
## 
## mining info:
##         data ntransactions support confidence
##  TransRetail        557040   0.003        0.8
inspect(head(sort(rules, by = "lift")))  
##     lhs                       rhs                        support confidence     lift count
## [1] {X.HEART.='HEART',                                                                    
##      X.HOLDER.='HOLDER',                                                                  
##      X.T.LIGHT.='T-LIGHT',                                                                
##      X.WHITE.='WHITE'}     => {X.HANGING.='HANGING'} 0.004251041          1 80.55531  2368
## [2] {X.HANGING.='HANGING',                                                                
##      X.HEART.='HEART',                                                                    
##      X.HOLDER.='HOLDER',                                                                  
##      X.WHITE.='WHITE'}     => {X.T.LIGHT.='T-LIGHT'} 0.004251041          1 79.53170  2368
## [3] {X.HANGING.='72',                                                                     
##      X.HEART.='CAKE',                                                                     
##      X.HOLDER.='CASES',                                                                   
##      X.T.LIGHT.='OF'}      => {X.WHITE.='PACK'}      0.003703504          1 78.04960  2063
## [4] {X.HANGING.='HANGING',                                                                
##      X.HEART.='HEART',                                                                    
##      X.T.LIGHT.='T-LIGHT',                                                                
##      X.WHITE.='WHITE'}     => {X.HOLDER.='HOLDER'}   0.004251041          1 71.77426  2368
## [5] {X.HANGING.='72',                                                                     
##      X.HEART.='CAKE',                                                                     
##      X.T.LIGHT.='OF',                                                                     
##      X.WHITE.='PACK'}      => {X.HOLDER.='CASES'}    0.003703504          1 54.12885  2063
## [6] {X.HANGING.='72',                                                                     
##      X.HOLDER.='CASES',                                                                   
##      X.T.LIGHT.='OF',                                                                     
##      X.WHITE.='PACK'}      => {X.HEART.='CAKE'}      0.003703504          1 38.00764  2063
head(quality(rules))
##       support confidence     lift count
## 1 0.003703504          1 26.93226  2063
## 2 0.003703504          1 38.00764  2063
## 3 0.003703504          1 54.12885  2063
## 4 0.003703504          1 78.04960  2063
## 5 0.004251041          1 34.41493  2368
## 6 0.004251041          1 71.77426  2368
plot(rules,method = "scatterplot",jitter =0)

plot(rules, method = "grouped")

# It looks like people who purchase Heart, Holder, T-Light and White would definitely purchase Hanging.
# People who purchase 72, Cake,Of,Pack would purchase Cases.

plot(rules,method = "graph")