groceries<-read.csv("D:/SOBAT KARIER/PORTOFOLIO/Association Rules/groceries.csv", header=F, sep=",")
head(groceries)
## V1 V2 V3 V4
## 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
## 6 whole milk butter yogurt rice
#install.packages("arules")
library(arules)
## Warning: package 'arules' was built under R version 4.2.3
## Loading required package: Matrix
##
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
##
## abbreviate, write
groceries<-read.transactions("D:/SOBAT KARIER/PORTOFOLIO/Association Rules/groceries.csv", sep=",")
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 16
## 2159 1643 1299 1005 855 645 545 438 350 246 182 117 78 77 55 46
## 17 18 19 20 21 22 23 24 26 27 28 29 32
## 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
## 1 abrasive cleaner
## 2 artif. sweetener
## 3 baby cosmetics
nrow(groceries)
## [1] 9835
itemFrequencyPlot(groceries, support=0.1, cex.names=0.8)
itemFrequencyPlot(groceries, support=0.05, cex.names=0.8)
itemFrequencyPlot(groceries, topN=20)
freq.itemsets <- eclat(groceries, parameter=list(supp=0.075, maxlen=15))
## Eclat
##
## parameter specification:
## tidLists support minlen maxlen target ext
## FALSE 0.075 1 15 frequent itemsets TRUE
##
## algorithmic control:
## sparse sort verbose
## 7 -2 TRUE
##
## Absolute minimum support count: 737
##
## create itemset ...
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [16 item(s)] done [0.00s].
## creating sparse bit matrix ... [16 row(s), 9835 column(s)] done [0.00s].
## writing ... [16 set(s)] done [0.00s].
## Creating S4 object ... done [0.00s].
inspect(freq.itemsets)
## items support count
## [1] {whole milk} 0.25551601 2513
## [2] {other vegetables} 0.19349263 1903
## [3] {rolls/buns} 0.18393493 1809
## [4] {yogurt} 0.13950178 1372
## [5] {soda} 0.17437722 1715
## [6] {root vegetables} 0.10899847 1072
## [7] {tropical fruit} 0.10493137 1032
## [8] {bottled water} 0.11052364 1087
## [9] {sausage} 0.09395018 924
## [10] {shopping bags} 0.09852567 969
## [11] {citrus fruit} 0.08276563 814
## [12] {pastry} 0.08896797 875
## [13] {pip fruit} 0.07564820 744
## [14] {newspapers} 0.07981698 785
## [15] {bottled beer} 0.08052872 792
## [16] {canned beer} 0.07768175 764
rules <- apriori(groceries, parameter = list(support = 0.009, confidence = 0.25, minlen = 2))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.25 0.1 1 none FALSE TRUE 5 0.009 2
## maxlen target ext
## 10 rules TRUE
##
## Algorithmic control:
## filter tree heap memopt load sort verbose
## 0.1 TRUE TRUE FALSE TRUE 2 TRUE
##
## Absolute minimum support count: 88
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [93 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 done [0.00s].
## writing ... [224 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
summary(rules)
## set of 224 rules
##
## rule length distribution (lhs + rhs):sizes
## 2 3
## 111 113
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.000 2.000 3.000 2.504 3.000 3.000
##
## summary of quality measures:
## support confidence coverage lift
## Min. :0.009049 Min. :0.2513 Min. :0.01464 Min. :0.9932
## 1st Qu.:0.010066 1st Qu.:0.2974 1st Qu.:0.02725 1st Qu.:1.5767
## Median :0.012303 Median :0.3603 Median :0.03711 Median :1.8592
## Mean :0.016111 Mean :0.3730 Mean :0.04574 Mean :1.9402
## 3rd Qu.:0.018480 3rd Qu.:0.4349 3rd Qu.:0.05541 3rd Qu.:2.2038
## Max. :0.074835 Max. :0.6389 Max. :0.25552 Max. :3.7969
## count
## Min. : 89.0
## 1st Qu.: 99.0
## Median :121.0
## Mean :158.5
## 3rd Qu.:181.8
## Max. :736.0
##
## mining info:
## data ntransactions support confidence
## groceries 9835 0.009 0.25
## call
## apriori(data = groceries, parameter = list(support = 0.009, confidence = 0.25, minlen = 2))
inspect(head(sort(rules, by ="lift"),5))
## lhs rhs support
## [1] {berries} => {whipped/sour cream} 0.009049314
## [2] {other vegetables, tropical fruit} => {pip fruit} 0.009456024
## [3] {other vegetables, pip fruit} => {tropical fruit} 0.009456024
## [4] {citrus fruit, other vegetables} => {root vegetables} 0.010371124
## [5] {other vegetables, tropical fruit} => {root vegetables} 0.012302999
## confidence coverage lift count
## [1] 0.2721713 0.03324860 3.796886 89
## [2] 0.2634561 0.03589222 3.482649 93
## [3] 0.3618677 0.02613116 3.448613 93
## [4] 0.3591549 0.02887646 3.295045 102
## [5] 0.3427762 0.03589222 3.144780 121
inspect(sort(sort(rules, by ="support"),by ="confidence")[1:5])
## lhs rhs support
## [1] {butter, yogurt} => {whole milk} 0.009354347
## [2] {citrus fruit, root vegetables} => {other vegetables} 0.010371124
## [3] {root vegetables, tropical fruit} => {other vegetables} 0.012302999
## [4] {curd, yogurt} => {whole milk} 0.010066090
## [5] {curd, other vegetables} => {whole milk} 0.009862735
## confidence coverage lift count
## [1] 0.6388889 0.01464159 2.500387 92
## [2] 0.5862069 0.01769192 3.029608 102
## [3] 0.5845411 0.02104728 3.020999 121
## [4] 0.5823529 0.01728521 2.279125 99
## [5] 0.5739645 0.01718353 2.246296 97
milk.rules <- sort(subset(rules, subset = rhs %in% "whole milk"), by = "confidence")
summary(milk.rules)
## set of 85 rules
##
## rule length distribution (lhs + rhs):sizes
## 2 3
## 46 39
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.000 2.000 2.000 2.459 3.000 3.000
##
## summary of quality measures:
## support confidence coverage lift
## Min. :0.009049 Min. :0.2538 Min. :0.01464 Min. :0.9932
## 1st Qu.:0.010269 1st Qu.:0.3845 1st Qu.:0.02257 1st Qu.:1.5047
## Median :0.013523 Median :0.4344 Median :0.03274 Median :1.7002
## Mean :0.018057 Mean :0.4374 Mean :0.04429 Mean :1.7116
## 3rd Qu.:0.021251 3rd Qu.:0.4976 3rd Qu.:0.05328 3rd Qu.:1.9474
## Max. :0.074835 Max. :0.6389 Max. :0.19349 Max. :2.5004
## count
## Min. : 89.0
## 1st Qu.:101.0
## Median :133.0
## Mean :177.6
## 3rd Qu.:209.0
## Max. :736.0
##
## mining info:
## data ntransactions support confidence
## groceries 9835 0.009 0.25
## call
## apriori(data = groceries, parameter = list(support = 0.009, confidence = 0.25, minlen = 2))
inspect(milk.rules)
## lhs rhs support confidence coverage lift count
## [1] {butter,
## yogurt} => {whole milk} 0.009354347 0.6388889 0.01464159 2.5003869 92
## [2] {curd,
## yogurt} => {whole milk} 0.010066090 0.5823529 0.01728521 2.2791250 99
## [3] {curd,
## other vegetables} => {whole milk} 0.009862735 0.5739645 0.01718353 2.2462956 97
## [4] {butter,
## other vegetables} => {whole milk} 0.011489578 0.5736041 0.02003050 2.2448850 113
## [5] {root vegetables,
## tropical fruit} => {whole milk} 0.011997966 0.5700483 0.02104728 2.2309690 118
## [6] {root vegetables,
## yogurt} => {whole milk} 0.014539908 0.5629921 0.02582613 2.2033536 143
## [7] {root vegetables,
## whipped/sour cream} => {whole milk} 0.009456024 0.5535714 0.01708185 2.1664843 93
## [8] {domestic eggs,
## other vegetables} => {whole milk} 0.012302999 0.5525114 0.02226741 2.1623358 121
## [9] {frozen vegetables,
## other vegetables} => {whole milk} 0.009659380 0.5428571 0.01779359 2.1245523 95
## [10] {pip fruit,
## yogurt} => {whole milk} 0.009557702 0.5310734 0.01799695 2.0784351 94
## [11] {whipped/sour cream,
## yogurt} => {whole milk} 0.010879512 0.5245098 0.02074225 2.0527473 107
## [12] {rolls/buns,
## root vegetables} => {whole milk} 0.012709710 0.5230126 0.02430097 2.0468876 125
## [13] {baking powder} => {whole milk} 0.009252669 0.5229885 0.01769192 2.0467935 91
## [14] {other vegetables,
## pip fruit} => {whole milk} 0.013523132 0.5175097 0.02613116 2.0253514 133
## [15] {tropical fruit,
## yogurt} => {whole milk} 0.015149975 0.5173611 0.02928317 2.0247698 149
## [16] {pastry,
## yogurt} => {whole milk} 0.009150991 0.5172414 0.01769192 2.0243012 90
## [17] {citrus fruit,
## root vegetables} => {whole milk} 0.009150991 0.5172414 0.01769192 2.0243012 90
## [18] {other vegetables,
## yogurt} => {whole milk} 0.022267412 0.5128806 0.04341637 2.0072345 219
## [19] {other vegetables,
## whipped/sour cream} => {whole milk} 0.014641586 0.5070423 0.02887646 1.9843854 144
## [20] {fruit/vegetable juice,
## yogurt} => {whole milk} 0.009456024 0.5054348 0.01870869 1.9780943 93
## [21] {brown bread,
## other vegetables} => {whole milk} 0.009354347 0.5000000 0.01870869 1.9568245 92
## [22] {fruit/vegetable juice,
## other vegetables} => {whole milk} 0.010472801 0.4975845 0.02104728 1.9473713 103
## [23] {butter} => {whole milk} 0.027554652 0.4972477 0.05541434 1.9460530 271
## [24] {curd} => {whole milk} 0.026131164 0.4904580 0.05327911 1.9194805 257
## [25] {other vegetables,
## root vegetables} => {whole milk} 0.023182511 0.4892704 0.04738180 1.9148326 228
## [26] {other vegetables,
## tropical fruit} => {whole milk} 0.017081851 0.4759207 0.03589222 1.8625865 168
## [27] {citrus fruit,
## yogurt} => {whole milk} 0.010269446 0.4741784 0.02165735 1.8557678 101
## [28] {domestic eggs} => {whole milk} 0.029994916 0.4727564 0.06344687 1.8502027 295
## [29] {other vegetables,
## pork} => {whole milk} 0.010167768 0.4694836 0.02165735 1.8373939 100
## [30] {beef,
## other vegetables} => {whole milk} 0.009252669 0.4690722 0.01972547 1.8357838 91
## [31] {margarine,
## other vegetables} => {whole milk} 0.009252669 0.4690722 0.01972547 1.8357838 91
## [32] {other vegetables,
## pastry} => {whole milk} 0.010574479 0.4684685 0.02257245 1.8334212 104
## [33] {citrus fruit,
## tropical fruit} => {whole milk} 0.009049314 0.4540816 0.01992883 1.7771161 89
## [34] {rolls/buns,
## yogurt} => {whole milk} 0.015556685 0.4526627 0.03436706 1.7715630 153
## [35] {citrus fruit,
## other vegetables} => {whole milk} 0.013014743 0.4507042 0.02887646 1.7638982 128
## [36] {whipped/sour cream} => {whole milk} 0.032231825 0.4496454 0.07168277 1.7597542 317
## [37] {root vegetables} => {whole milk} 0.048906965 0.4486940 0.10899847 1.7560310 481
## [38] {rolls/buns,
## tropical fruit} => {whole milk} 0.010981190 0.4462810 0.02460600 1.7465872 108
## [39] {sugar} => {whole milk} 0.015048297 0.4444444 0.03385867 1.7393996 148
## [40] {hamburger meat} => {whole milk} 0.014743264 0.4434251 0.03324860 1.7354101 145
## [41] {ham} => {whole milk} 0.011489578 0.4414062 0.02602949 1.7275091 113
## [42] {sliced cheese} => {whole milk} 0.010777834 0.4398340 0.02450432 1.7213560 106
## [43] {bottled water,
## other vegetables} => {whole milk} 0.010777834 0.4344262 0.02480935 1.7001918 106
## [44] {other vegetables,
## soda} => {whole milk} 0.013929842 0.4254658 0.03274021 1.6651240 137
## [45] {frozen vegetables} => {whole milk} 0.020437214 0.4249471 0.04809354 1.6630940 201
## [46] {bottled water,
## yogurt} => {whole milk} 0.009659380 0.4203540 0.02297916 1.6451180 95
## [47] {other vegetables,
## rolls/buns} => {whole milk} 0.017895272 0.4200477 0.04260295 1.6439194 176
## [48] {cream cheese} => {whole milk} 0.016471784 0.4153846 0.03965430 1.6256696 162
## [49] {butter milk} => {whole milk} 0.011591256 0.4145455 0.02796136 1.6223854 114
## [50] {margarine} => {whole milk} 0.024199288 0.4131944 0.05856634 1.6170980 238
## [51] {hard cheese} => {whole milk} 0.010066090 0.4107884 0.02450432 1.6076815 99
## [52] {chicken} => {whole milk} 0.017590239 0.4099526 0.04290798 1.6044106 173
## [53] {white bread} => {whole milk} 0.017081851 0.4057971 0.04209456 1.5881474 168
## [54] {beef} => {whole milk} 0.021250635 0.4050388 0.05246568 1.5851795 209
## [55] {tropical fruit} => {whole milk} 0.042297916 0.4031008 0.10493137 1.5775950 416
## [56] {oil} => {whole milk} 0.011286223 0.4021739 0.02806304 1.5739675 111
## [57] {yogurt} => {whole milk} 0.056024403 0.4016035 0.13950178 1.5717351 551
## [58] {pip fruit} => {whole milk} 0.030096594 0.3978495 0.07564820 1.5570432 296
## [59] {onions} => {whole milk} 0.012099644 0.3901639 0.03101169 1.5269647 119
## [60] {hygiene articles} => {whole milk} 0.012811388 0.3888889 0.03294357 1.5219746 126
## [61] {brown bread} => {whole milk} 0.025216065 0.3887147 0.06487036 1.5212930 248
## [62] {other vegetables} => {whole milk} 0.074834774 0.3867578 0.19349263 1.5136341 736
## [63] {meat} => {whole milk} 0.009964413 0.3858268 0.02582613 1.5099906 98
## [64] {pork} => {whole milk} 0.022165735 0.3844797 0.05765125 1.5047187 218
## [65] {soda,
## yogurt} => {whole milk} 0.010472801 0.3828996 0.02735130 1.4985348 103
## [66] {other vegetables,
## sausage} => {whole milk} 0.010167768 0.3773585 0.02694459 1.4768487 100
## [67] {napkins} => {whole milk} 0.019725470 0.3766990 0.05236401 1.4742678 194
## [68] {pastry} => {whole milk} 0.033248602 0.3737143 0.08896797 1.4625865 327
## [69] {dessert} => {whole milk} 0.013726487 0.3698630 0.03711235 1.4475140 135
## [70] {citrus fruit} => {whole milk} 0.030503305 0.3685504 0.08276563 1.4423768 300
## [71] {fruit/vegetable juice} => {whole milk} 0.026639553 0.3684951 0.07229283 1.4421604 262
## [72] {long life bakery product} => {whole milk} 0.013523132 0.3614130 0.03741739 1.4144438 133
## [73] {berries} => {whole milk} 0.011794611 0.3547401 0.03324860 1.3883281 116
## [74] {frankfurter} => {whole milk} 0.020538892 0.3482759 0.05897306 1.3630295 202
## [75] {frozen meals} => {whole milk} 0.009862735 0.3476703 0.02836807 1.3606593 97
## [76] {newspapers} => {whole milk} 0.027351296 0.3426752 0.07981698 1.3411103 269
## [77] {chocolate} => {whole milk} 0.016675140 0.3360656 0.04961871 1.3152427 164
## [78] {waffles} => {whole milk} 0.012709710 0.3306878 0.03843416 1.2941961 125
## [79] {coffee} => {whole milk} 0.018708693 0.3222417 0.05805796 1.2611408 184
## [80] {sausage} => {whole milk} 0.029893238 0.3181818 0.09395018 1.2452520 294
## [81] {bottled water} => {whole milk} 0.034367056 0.3109476 0.11052364 1.2169396 338
## [82] {rolls/buns} => {whole milk} 0.056634469 0.3079049 0.18393493 1.2050318 557
## [83] {rolls/buns,
## sausage} => {whole milk} 0.009354347 0.3056478 0.03060498 1.1961984 92
## [84] {salty snack} => {whole milk} 0.011184545 0.2956989 0.03782410 1.1572618 110
## [85] {bottled beer} => {whole milk} 0.020437214 0.2537879 0.08052872 0.9932367 201
is.significant(milk.rules, groceries)
## [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [37] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [49] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [73] TRUE TRUE FALSE TRUE TRUE FALSE FALSE TRUE TRUE TRUE FALSE FALSE
## [85] FALSE
is.maximal(milk.rules)
## {butter,whole milk,yogurt}
## TRUE
## {curd,whole milk,yogurt}
## TRUE
## {curd,other vegetables,whole milk}
## TRUE
## {butter,other vegetables,whole milk}
## TRUE
## {root vegetables,tropical fruit,whole milk}
## TRUE
## {root vegetables,whole milk,yogurt}
## TRUE
## {root vegetables,whipped/sour cream,whole milk}
## TRUE
## {domestic eggs,other vegetables,whole milk}
## TRUE
## {frozen vegetables,other vegetables,whole milk}
## TRUE
## {pip fruit,whole milk,yogurt}
## TRUE
## {whipped/sour cream,whole milk,yogurt}
## TRUE
## {rolls/buns,root vegetables,whole milk}
## TRUE
## {baking powder,whole milk}
## TRUE
## {other vegetables,pip fruit,whole milk}
## TRUE
## {tropical fruit,whole milk,yogurt}
## TRUE
## {pastry,whole milk,yogurt}
## TRUE
## {citrus fruit,root vegetables,whole milk}
## TRUE
## {other vegetables,whole milk,yogurt}
## TRUE
## {other vegetables,whipped/sour cream,whole milk}
## TRUE
## {fruit/vegetable juice,whole milk,yogurt}
## TRUE
## {brown bread,other vegetables,whole milk}
## TRUE
## {fruit/vegetable juice,other vegetables,whole milk}
## TRUE
## {butter,whole milk}
## FALSE
## {curd,whole milk}
## FALSE
## {other vegetables,root vegetables,whole milk}
## TRUE
## {other vegetables,tropical fruit,whole milk}
## TRUE
## {citrus fruit,whole milk,yogurt}
## TRUE
## {domestic eggs,whole milk}
## FALSE
## {other vegetables,pork,whole milk}
## TRUE
## {beef,other vegetables,whole milk}
## TRUE
## {margarine,other vegetables,whole milk}
## TRUE
## {other vegetables,pastry,whole milk}
## TRUE
## {citrus fruit,tropical fruit,whole milk}
## TRUE
## {rolls/buns,whole milk,yogurt}
## TRUE
## {citrus fruit,other vegetables,whole milk}
## TRUE
## {whipped/sour cream,whole milk}
## FALSE
## {root vegetables,whole milk}
## FALSE
## {rolls/buns,tropical fruit,whole milk}
## TRUE
## {sugar,whole milk}
## TRUE
## {hamburger meat,whole milk}
## TRUE
## {ham,whole milk}
## TRUE
## {sliced cheese,whole milk}
## TRUE
## {bottled water,other vegetables,whole milk}
## TRUE
## {other vegetables,soda,whole milk}
## TRUE
## {frozen vegetables,whole milk}
## FALSE
## {bottled water,whole milk,yogurt}
## TRUE
## {other vegetables,rolls/buns,whole milk}
## TRUE
## {cream cheese,whole milk}
## TRUE
## {butter milk,whole milk}
## TRUE
## {margarine,whole milk}
## FALSE
## {hard cheese,whole milk}
## TRUE
## {chicken,whole milk}
## TRUE
## {white bread,whole milk}
## TRUE
## {beef,whole milk}
## FALSE
## {tropical fruit,whole milk}
## FALSE
## {oil,whole milk}
## TRUE
## {whole milk,yogurt}
## FALSE
## {pip fruit,whole milk}
## FALSE
## {onions,whole milk}
## TRUE
## {hygiene articles,whole milk}
## TRUE
## {brown bread,whole milk}
## FALSE
## {other vegetables,whole milk}
## FALSE
## {meat,whole milk}
## TRUE
## {pork,whole milk}
## FALSE
## {soda,whole milk,yogurt}
## TRUE
## {other vegetables,sausage,whole milk}
## TRUE
## {napkins,whole milk}
## TRUE
## {pastry,whole milk}
## FALSE
## {dessert,whole milk}
## TRUE
## {citrus fruit,whole milk}
## FALSE
## {fruit/vegetable juice,whole milk}
## FALSE
## {long life bakery product,whole milk}
## TRUE
## {berries,whole milk}
## TRUE
## {frankfurter,whole milk}
## TRUE
## {frozen meals,whole milk}
## TRUE
## {newspapers,whole milk}
## TRUE
## {chocolate,whole milk}
## TRUE
## {waffles,whole milk}
## TRUE
## {coffee,whole milk}
## TRUE
## {sausage,whole milk}
## FALSE
## {bottled water,whole milk}
## FALSE
## {rolls/buns,whole milk}
## FALSE
## {rolls/buns,sausage,whole milk}
## TRUE
## {salty snack,whole milk}
## TRUE
## {bottled beer,whole milk}
## TRUE
is.redundant(milk.rules)
## [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [61] FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
## [73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE
## [85] FALSE
coke.rules <- sort(subset(rules, subset = rhs %in% "soda"), by = "confidence")
summary(coke.rules)
## set of 6 rules
##
## rule length distribution (lhs + rhs):sizes
## 2 3
## 5 1
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.000 2.000 2.000 2.167 2.000 3.000
##
## summary of quality measures:
## support confidence coverage lift
## Min. :0.009659 Min. :0.2546 Min. :0.03060 Min. :1.460
## 1st Qu.:0.010778 1st Qu.:0.2595 1st Qu.:0.04024 1st Qu.:1.488
## Median :0.015963 Median :0.2640 Median :0.06096 Median :1.514
## Mean :0.017455 Mean :0.2716 Mean :0.06568 Mean :1.557
## 3rd Qu.:0.022827 3rd Qu.:0.2708 3rd Qu.:0.08854 3rd Qu.:1.553
## Max. :0.028978 Max. :0.3156 Max. :0.11052 Max. :1.810
## count
## Min. : 95.0
## 1st Qu.:106.0
## Median :157.0
## Mean :171.7
## 3rd Qu.:224.5
## Max. :285.0
##
## mining info:
## data ntransactions support confidence
## groceries 9835 0.009 0.25
## call
## apriori(data = groceries, parameter = list(support = 0.009, confidence = 0.25, minlen = 2))
inspect(coke.rules)
## lhs rhs support confidence coverage
## [1] {rolls/buns, sausage} => {soda} 0.009659380 0.3156146 0.03060498
## [2] {chocolate} => {soda} 0.013523132 0.2725410 0.04961871
## [3] {dessert} => {soda} 0.009862735 0.2657534 0.03711235
## [4] {bottled water} => {soda} 0.028978139 0.2621895 0.11052364
## [5] {sausage} => {soda} 0.024300966 0.2586580 0.09395018
## [6] {fruit/vegetable juice} => {soda} 0.018403660 0.2545710 0.07229283
## lift count
## [1] 1.809953 95
## [2] 1.562939 133
## [3] 1.524015 97
## [4] 1.503577 285
## [5] 1.483324 239
## [6] 1.459887 181
is.significant(coke.rules, groceries)
## [1] TRUE TRUE TRUE TRUE TRUE TRUE
meat.rules <- sort(subset(rules, subset = lhs %in% "beef"|lhs %in% "sausage" |lhs %in% "chicken"), by = "confidence")
summary(meat.rules)
## set of 19 rules
##
## rule length distribution (lhs + rhs):sizes
## 2 3
## 11 8
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.000 2.000 2.000 2.421 3.000 3.000
##
## summary of quality measures:
## support confidence coverage lift
## Min. :0.009253 Min. :0.2536 Min. :0.01973 Min. :1.196
## 1st Qu.:0.009659 1st Qu.:0.3093 1st Qu.:0.02989 1st Qu.:1.483
## Median :0.013625 Median :0.3314 Median :0.04291 Median :1.758
## Mean :0.016156 Mean :0.3471 Mean :0.04882 Mean :1.802
## 3rd Qu.:0.020488 3rd Qu.:0.4013 3rd Qu.:0.05247 3rd Qu.:2.049
## Max. :0.030605 Max. :0.4691 Max. :0.09395 Max. :3.040
## count
## Min. : 91.0
## 1st Qu.: 95.0
## Median :134.0
## Mean :158.9
## 3rd Qu.:201.5
## Max. :301.0
##
## mining info:
## data ntransactions support confidence
## groceries 9835 0.009 0.25
## call
## apriori(data = groceries, parameter = list(support = 0.009, confidence = 0.25, minlen = 2))
inspect(meat.rules)
## lhs rhs support confidence
## [1] {beef, other vegetables} => {whole milk} 0.009252669 0.4690722
## [2] {beef, whole milk} => {other vegetables} 0.009252669 0.4354067
## [3] {chicken} => {other vegetables} 0.017895272 0.4170616
## [4] {chicken} => {whole milk} 0.017590239 0.4099526
## [5] {beef} => {whole milk} 0.021250635 0.4050388
## [6] {sausage, soda} => {rolls/buns} 0.009659380 0.3974895
## [7] {other vegetables, sausage} => {whole milk} 0.010167768 0.3773585
## [8] {beef} => {other vegetables} 0.019725470 0.3759690
## [9] {sausage, whole milk} => {other vegetables} 0.010167768 0.3401361
## [10] {beef} => {root vegetables} 0.017386884 0.3313953
## [11] {sausage} => {rolls/buns} 0.030604982 0.3257576
## [12] {sausage} => {whole milk} 0.029893238 0.3181818
## [13] {rolls/buns, sausage} => {soda} 0.009659380 0.3156146
## [14] {sausage, whole milk} => {rolls/buns} 0.009354347 0.3129252
## [15] {rolls/buns, sausage} => {whole milk} 0.009354347 0.3056478
## [16] {sausage} => {other vegetables} 0.026944586 0.2867965
## [17] {beef} => {rolls/buns} 0.013624809 0.2596899
## [18] {sausage} => {soda} 0.024300966 0.2586580
## [19] {chicken} => {root vegetables} 0.010879512 0.2535545
## coverage lift count
## [1] 0.01972547 1.835784 91
## [2] 0.02125064 2.250250 91
## [3] 0.04290798 2.155439 176
## [4] 0.04290798 1.604411 173
## [5] 0.05246568 1.585180 209
## [6] 0.02430097 2.161034 95
## [7] 0.02694459 1.476849 100
## [8] 0.05246568 1.943066 194
## [9] 0.02989324 1.757876 100
## [10] 0.05246568 3.040367 171
## [11] 0.09395018 1.771048 301
## [12] 0.09395018 1.245252 294
## [13] 0.03060498 1.809953 95
## [14] 0.02989324 1.701282 92
## [15] 0.03060498 1.196198 92
## [16] 0.09395018 1.482209 265
## [17] 0.05246568 1.411858 134
## [18] 0.09395018 1.483324 239
## [19] 0.04290798 2.326221 107
is.significant(meat.rules, groceries)
## [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [13] TRUE TRUE FALSE TRUE TRUE TRUE TRUE
yog.rules <- sort(subset(rules, subset = lhs %in% "yogurt"), by = "confidence")
summary(yog.rules)
## set of 26 rules
##
## rule length distribution (lhs + rhs):sizes
## 2 3
## 2 24
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.000 3.000 3.000 2.923 3.000 3.000
##
## summary of quality measures:
## support confidence coverage lift
## Min. :0.009151 Min. :0.2595 Min. :0.01464 Min. :1.439
## 1st Qu.:0.010193 1st Qu.:0.3170 1st Qu.:0.02097 1st Qu.:1.739
## Median :0.012303 Median :0.4365 Median :0.02928 Median :2.039
## Mean :0.015651 Mean :0.4281 Mean :0.04060 Mean :2.058
## 3rd Qu.:0.015150 3rd Qu.:0.5162 3rd Qu.:0.04342 3rd Qu.:2.356
## Max. :0.056024 Max. :0.6389 Max. :0.13950 Max. :2.729
## count
## Min. : 90.0
## 1st Qu.:100.2
## Median :121.0
## Mean :153.9
## 3rd Qu.:149.0
## Max. :551.0
##
## mining info:
## data ntransactions support confidence
## groceries 9835 0.009 0.25
## call
## apriori(data = groceries, parameter = list(support = 0.009, confidence = 0.25, minlen = 2))
inspect(yog.rules)
## lhs rhs support
## [1] {butter, yogurt} => {whole milk} 0.009354347
## [2] {curd, yogurt} => {whole milk} 0.010066090
## [3] {root vegetables, yogurt} => {whole milk} 0.014539908
## [4] {pip fruit, yogurt} => {whole milk} 0.009557702
## [5] {whipped/sour cream, yogurt} => {whole milk} 0.010879512
## [6] {tropical fruit, yogurt} => {whole milk} 0.015149975
## [7] {pastry, yogurt} => {whole milk} 0.009150991
## [8] {other vegetables, yogurt} => {whole milk} 0.022267412
## [9] {fruit/vegetable juice, yogurt} => {whole milk} 0.009456024
## [10] {root vegetables, yogurt} => {other vegetables} 0.012913066
## [11] {whipped/sour cream, yogurt} => {other vegetables} 0.010167768
## [12] {citrus fruit, yogurt} => {whole milk} 0.010269446
## [13] {rolls/buns, yogurt} => {whole milk} 0.015556685
## [14] {bottled water, yogurt} => {whole milk} 0.009659380
## [15] {tropical fruit, yogurt} => {other vegetables} 0.012302999
## [16] {yogurt} => {whole milk} 0.056024403
## [17] {whole milk, yogurt} => {other vegetables} 0.022267412
## [18] {soda, yogurt} => {whole milk} 0.010472801
## [19] {rolls/buns, yogurt} => {other vegetables} 0.011489578
## [20] {yogurt} => {other vegetables} 0.043416370
## [21] {other vegetables, yogurt} => {root vegetables} 0.012913066
## [22] {other vegetables, yogurt} => {tropical fruit} 0.012302999
## [23] {whole milk, yogurt} => {rolls/buns} 0.015556685
## [24] {whole milk, yogurt} => {tropical fruit} 0.015149975
## [25] {other vegetables, yogurt} => {rolls/buns} 0.011489578
## [26] {whole milk, yogurt} => {root vegetables} 0.014539908
## confidence coverage lift count
## [1] 0.6388889 0.01464159 2.500387 92
## [2] 0.5823529 0.01728521 2.279125 99
## [3] 0.5629921 0.02582613 2.203354 143
## [4] 0.5310734 0.01799695 2.078435 94
## [5] 0.5245098 0.02074225 2.052747 107
## [6] 0.5173611 0.02928317 2.024770 149
## [7] 0.5172414 0.01769192 2.024301 90
## [8] 0.5128806 0.04341637 2.007235 219
## [9] 0.5054348 0.01870869 1.978094 93
## [10] 0.5000000 0.02582613 2.584078 127
## [11] 0.4901961 0.02074225 2.533410 100
## [12] 0.4741784 0.02165735 1.855768 101
## [13] 0.4526627 0.03436706 1.771563 153
## [14] 0.4203540 0.02297916 1.645118 95
## [15] 0.4201389 0.02928317 2.171343 121
## [16] 0.4016035 0.13950178 1.571735 551
## [17] 0.3974592 0.05602440 2.054131 219
## [18] 0.3828996 0.02735130 1.498535 103
## [19] 0.3343195 0.03436706 1.727815 113
## [20] 0.3112245 0.13950178 1.608457 427
## [21] 0.2974239 0.04341637 2.728698 127
## [22] 0.2833724 0.04341637 2.700550 121
## [23] 0.2776770 0.05602440 1.509648 153
## [24] 0.2704174 0.05602440 2.577089 149
## [25] 0.2646370 0.04341637 1.438753 113
## [26] 0.2595281 0.05602440 2.381025 143
is.significant(yog.rules, groceries)
## [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
trans.sel<-groceries[,itemFrequency(groceries)>0.1] # selected transactions
dissimilarity(trans.sel, which="items")
## bottled water other vegetables rolls/buns root vegetables
## other vegetables 0.9111435
## rolls/buns 0.9104590 0.8727604
## root vegetables 0.9231920 0.8142686 0.9095382
## soda 0.8867700 0.9023058 0.8802034 0.9297235
## tropical fruit 0.9060403 0.8632843 0.9068873 0.8908803
## whole milk 0.8963826 0.8000000 0.8520584 0.8450387
## yogurt 0.8987909 0.8500702 0.8811115 0.8840183
## soda tropical fruit whole milk
## other vegetables
## rolls/buns
## root vegetables
## soda
## tropical fruit 0.9193548
## whole milk 0.8972353 0.8670502
## yogurt 0.9045422 0.8638941 0.8347331
inspect(tail(sort(rules, by = "lift")))
## lhs rhs support confidence coverage
## [1] {sausage} => {whole milk} 0.029893238 0.3181818 0.09395018
## [2] {bottled water} => {whole milk} 0.034367056 0.3109476 0.11052364
## [3] {rolls/buns} => {whole milk} 0.056634469 0.3079049 0.18393493
## [4] {rolls/buns, sausage} => {whole milk} 0.009354347 0.3056478 0.03060498
## [5] {salty snack} => {whole milk} 0.011184545 0.2956989 0.03782410
## [6] {bottled beer} => {whole milk} 0.020437214 0.2537879 0.08052872
## lift count
## [1] 1.2452520 294
## [2] 1.2169396 338
## [3] 1.2050318 557
## [4] 1.1961984 92
## [5] 1.1572618 110
## [6] 0.9932367 201
There is only one item in our rules set, that has lift less than 1. It is a connection between whole milk and bottled beer. It means that we are less likely to buy milk than any other product in dataset, while already having beer in basket. Maybe that’s a hint that beeroholics don’t drink milk? :)