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()
# Loading the data from r sample source
data("Groceries")
# Ploting the frequency plot N is 15
itemFrequencyPlot(Groceries,topN=15)

# Creating Associate Rules with 0.2% support and 50% confidence level
Groceries_rules <- apriori(Groceries, parameter = list(supp=0.002, confidence=0.5,minlen=2, maxlen=5))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.5 0.1 1 none FALSE TRUE 5 0.002 2
## maxlen target ext
## 5 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.02s].
## checking subsets of size 1 2 3 4 5
## Warning in apriori(Groceries, parameter = list(supp = 0.002, confidence =
## 0.5, : Mining stopped (maxlen reached). Only patterns up to a length of 5
## returned!
## done [0.00s].
## writing ... [1098 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
Groceries_rules
## set of 1098 rules
inspect(head(sort(Groceries_rules),n=15))
## lhs rhs support confidence lift count
## [1] {other vegetables,
## yogurt} => {whole milk} 0.02226741 0.5128806 2.007235 219
## [2] {tropical fruit,
## yogurt} => {whole milk} 0.01514997 0.5173611 2.024770 149
## [3] {other vegetables,
## whipped/sour cream} => {whole milk} 0.01464159 0.5070423 1.984385 144
## [4] {root vegetables,
## yogurt} => {whole milk} 0.01453991 0.5629921 2.203354 143
## [5] {pip fruit,
## other vegetables} => {whole milk} 0.01352313 0.5175097 2.025351 133
## [6] {root vegetables,
## yogurt} => {other vegetables} 0.01291307 0.5000000 2.584078 127
## [7] {root vegetables,
## rolls/buns} => {whole milk} 0.01270971 0.5230126 2.046888 125
## [8] {other vegetables,
## domestic eggs} => {whole milk} 0.01230300 0.5525114 2.162336 121
## [9] {tropical fruit,
## root vegetables} => {other vegetables} 0.01230300 0.5845411 3.020999 121
## [10] {root vegetables,
## rolls/buns} => {other vegetables} 0.01220132 0.5020921 2.594890 120
## [11] {tropical fruit,
## root vegetables} => {whole milk} 0.01199797 0.5700483 2.230969 118
## [12] {other vegetables,
## butter} => {whole milk} 0.01148958 0.5736041 2.244885 113
## [13] {yogurt,
## whipped/sour cream} => {whole milk} 0.01087951 0.5245098 2.052747 107
## [14] {citrus fruit,
## root vegetables} => {other vegetables} 0.01037112 0.5862069 3.029608 102
## [15] {curd,
## yogurt} => {whole milk} 0.01006609 0.5823529 2.279125 99
inspect(tail(sort(Groceries_rules),n=15))
## lhs rhs support confidence lift count
## [1] {citrus fruit,
## rolls/buns,
## pastry} => {whole milk} 0.002033554 0.6666667 2.609099 20
## [2] {citrus fruit,
## root vegetables,
## bottled water} => {whole milk} 0.002033554 0.6060606 2.371909 20
## [3] {sausage,
## bottled water,
## soda} => {yogurt} 0.002033554 0.5000000 3.584184 20
## [4] {sausage,
## yogurt,
## bottled water} => {soda} 0.002033554 0.5128205 2.940869 20
## [5] {root vegetables,
## yogurt,
## bottled water} => {other vegetables} 0.002033554 0.5263158 2.720082 20
## [6] {root vegetables,
## other vegetables,
## yogurt,
## fruit/vegetable juice} => {whole milk} 0.002033554 0.8333333 3.261374 20
## [7] {root vegetables,
## whole milk,
## yogurt,
## fruit/vegetable juice} => {other vegetables} 0.002033554 0.8000000 4.134524 20
## [8] {root vegetables,
## other vegetables,
## whole milk,
## fruit/vegetable juice} => {yogurt} 0.002033554 0.5128205 3.676086 20
## [9] {tropical fruit,
## other vegetables,
## yogurt,
## bottled water} => {whole milk} 0.002033554 0.6666667 2.609099 20
## [10] {tropical fruit,
## whole milk,
## yogurt,
## bottled water} => {other vegetables} 0.002033554 0.5555556 2.871198 20
## [11] {tropical fruit,
## other vegetables,
## whole milk,
## bottled water} => {yogurt} 0.002033554 0.5714286 4.096210 20
## [12] {other vegetables,
## whole milk,
## yogurt,
## bottled water} => {tropical fruit} 0.002033554 0.5128205 4.887199 20
## [13] {tropical fruit,
## root vegetables,
## other vegetables,
## rolls/buns} => {whole milk} 0.002033554 0.5714286 2.236371 20
## [14] {tropical fruit,
## root vegetables,
## whole milk,
## rolls/buns} => {other vegetables} 0.002033554 0.5405405 2.793598 20
## [15] {tropical fruit,
## other vegetables,
## whole milk,
## rolls/buns} => {root vegetables} 0.002033554 0.5000000 4.587220 20
plot(head(sort(Groceries_rules, by="lift"),n=15), method = "graph", control = list(cex=0.92))

plot(Groceries_rules)
## To reduce overplotting, jitter is added! Use jitter = 0 to prevent jitter.

plot(head(sort(Groceries_rules, by="lift"),n=15), method = "grouped")
