To capture the different set of rule values for Books Dataset 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\Rtmpk9eYyC\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\Rtmpk9eYyC\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\Rtmpk9eYyC\downloaded_packages
# install.packages("rmarkdown")
# install.packages("arules")
# install.packages("arulesViz")
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
book <- read.csv(file.choose())

View(book)

rules <- apriori(as.matrix(book),parameter=list(support=0.02, confidence = 0.5,minlen=5))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.5    0.1    1 none FALSE            TRUE       5    0.02      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: 40 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[11 item(s), 2000 transaction(s)] done [0.00s].
## sorting and recoding items ... [11 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 6 done [0.00s].
## writing ... [186 rule(s)] done [0.05s].
## creating S4 object  ... done [0.00s].
# Provided the rules with 2 % Support, 50 % Confidence and Minimum to purchase 
# 5 books 
rules
## set of 186 rules
inspect(head(sort(rules, by = "lift")))  
##     lhs                                   rhs        support confidence
## [1] {CookBks,DoItYBks,ArtBks,ItalCook} => {ItalArt}  0.0250  0.6849315 
## [2] {CookBks,ArtBks,GeogBks,ItalCook}  => {ItalArt}  0.0240  0.6666667 
## [3] {ChildBks,CookBks,ArtBks,ItalCook} => {ItalArt}  0.0285  0.6263736 
## [4] {CookBks,ArtBks,GeogBks,ItalArt}   => {ItalCook} 0.0240  0.9600000 
## [5] {ChildBks,CookBks,ArtBks,ItalArt}  => {ItalCook} 0.0285  0.9500000 
## [6] {CookBks,DoItYBks,ArtBks,ItalArt}  => {ItalCook} 0.0250  0.9259259 
##     lift      count
## [1] 14.122299 50   
## [2] 13.745704 48   
## [3] 12.914920 57   
## [4]  8.458150 48   
## [5]  8.370044 57   
## [6]  8.157938 50
head(quality(rules))
##   support confidence     lift count
## 1   0.020  1.0000000 2.320186    40
## 2   0.020  0.8695652 2.055710    40
## 3   0.020  1.0000000 4.662005    40
## 4   0.020  0.8888889 7.831620    40
## 5   0.025  1.0000000 2.320186    50
## 6   0.025  0.6666667 2.364066    50
plot(rules,method = "scatterplot")
## To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter.

plot(rules,method = "grouped")

# The Art books are being sold at a larger extent along with other Cook, art, geo, child books
# Cook books are also being sold at a larger extent along with other chld, art, geo, Doit books)

plot(rules,method = "graph")
## Warning: plot: Too many rules supplied. Only plotting the best 100 rules
## using 'support' (change control parameter max if needed)