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\Rtmpu21Yve\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\Rtmpu21Yve\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\Rtmpu21Yve\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
data()
data("Groceries")
summary(Groceries)
## transactions as itemMatrix in sparse format with
## 9835 rows (elements/itemsets/transactions) and
## 169 columns (items) and a density of 0.02609146
##
## most frequent items:
## whole milk other vegetables rolls/buns soda
## 2513 1903 1809 1715
## yogurt (Other)
## 1372 34055
##
## element (itemset/transaction) length distribution:
## sizes
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
## 2159 1643 1299 1005 855 645 545 438 350 246 182 117 78 77 55
## 16 17 18 19 20 21 22 23 24 26 27 28 29 32
## 46 29 14 14 9 11 4 6 1 1 1 1 3 1
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 2.000 3.000 4.409 6.000 32.000
##
## includes extended item information - examples:
## labels level2 level1
## 1 frankfurter sausage meat and sausage
## 2 sausage sausage meat and sausage
## 3 liver loaf sausage meat and sausage
rules <- apriori(Groceries,parameter=list(support=0.002, confidence = 0.5))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.5 0.1 1 none FALSE TRUE 5 0.002 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: 19
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [147 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 done [0.01s].
## writing ... [1098 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules
## set of 1098 rules
inspect(head(sort(rules, by = "lift")))
## lhs rhs support confidence lift count
## [1] {butter,
## hard cheese} => {whipped/sour cream} 0.002033554 0.5128205 7.154028 20
## [2] {beef,
## citrus fruit,
## other vegetables} => {root vegetables} 0.002135231 0.6363636 5.838280 21
## [3] {citrus fruit,
## tropical fruit,
## other vegetables,
## whole milk} => {root vegetables} 0.003152008 0.6326531 5.804238 31
## [4] {citrus fruit,
## other vegetables,
## frozen vegetables} => {root vegetables} 0.002033554 0.6250000 5.734025 20
## [5] {beef,
## tropical fruit,
## other vegetables} => {root vegetables} 0.002745297 0.6136364 5.629770 27
## [6] {root vegetables,
## yogurt,
## bottled water} => {tropical fruit} 0.002236909 0.5789474 5.517391 22
plot(rules)
## To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter.

head(quality(rules))
## support confidence lift count
## 1 0.003660397 0.6428571 2.515917 36
## 2 0.002948653 0.5471698 2.141431 29
## 3 0.004270463 0.5000000 2.584078 42
## 4 0.003965430 0.5200000 2.687441 39
## 5 0.004677173 0.6133333 2.400371 46
## 6 0.009252669 0.5229885 2.046793 91
plot(rules, method = "grouped")

plot(rules,method = "scatterplot")
## To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter.

plot(rules,method = "grouped")

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