Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- > library(datasets)
- > library(Matrix)
- > library(arules)
- > data(Groceries)
- > Groceries
- transactions in sparse format with
- 9835 transactions (rows) and
- 169 items (columns)
- > 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 yogurt (Other)
- 2513 1903 1809 1715 1372 34055
- element (itemset/transaction) length distribution:
- sizes
- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 28 29 32
- 2159 1643 1299 1005 855 645 545 438 350 246 182 117 78 77 55 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
- > itemFrequencyPlot(Groceries,topN=20,type="absolute")
- > rules <- apriori(Groceries, parameter = list(supp = 0.001, conf = 1))
- Apriori
- Parameter specification:
- confidence minval smax arem aval originalSupport maxtime support minlen maxlen target ext
- 1 0.1 1 none FALSE TRUE 5 0.001 1 10 rules FALSE
- Algorithmic control:
- filter tree heap memopt load sort verbose
- 0.1 TRUE TRUE FALSE TRUE 2 TRUE
- Absolute minimum support count: 9
- set item appearances ...[0 item(s)] done [0.00s].
- set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
- sorting and recoding items ... [157 item(s)] done [0.00s].
- creating transaction tree ... done [0.00s].
- checking subsets of size 1 2 3 4 5 6 done [0.01s].
- writing ... [28 rule(s)] done [0.00s].
- creating S4 object ... done [0.00s].
- > rules<-sort(rules, by="confidence", decreasing=TRUE)
- > rules
- set of 28 rules
- > subset.matrix <- is.subset(rules, rules)
- > subset.matrix[lower.tri(subset.matrix, diag=T)] <- NA
- > redundant <- colSums(subset.matrix, na.rm=T) >= 1
- > rules.pruned <- rules[!redundant]
- > rules<-rules.pruned
- > inspect(rules)
- lhs rhs support confidence lift
- [1] {rice,sugar} => {whole milk} 0.001220132 1 3.913649
- [2] {canned fish,hygiene articles} => {whole milk} 0.001118454 1 3.913649
- [3] {root vegetables,butter,rice} => {whole milk} 0.001016777 1 3.913649
- [4] {root vegetables,whipped/sour cream,flour} => {whole milk} 0.001728521 1 3.913649
- [5] {butter,soft cheese,domestic eggs} => {whole milk} 0.001016777 1 3.913649
- [6] {citrus fruit,root vegetables,soft cheese} => {other vegetables} 0.001016777 1 5.168156
- [7] {pip fruit,butter,hygiene articles} => {whole milk} 0.001016777 1 3.913649
- [8] {root vegetables,whipped/sour cream,hygiene articles} => {whole milk} 0.001016777 1 3.913649
- [9] {pip fruit,root vegetables,hygiene articles} => {whole milk} 0.001016777 1 3.913649
- [10] {cream cheese ,domestic eggs,sugar} => {whole milk} 0.001118454 1 3.913649
- [11] {curd,domestic eggs,sugar} => {whole milk} 0.001016777 1 3.913649
- [12] {cream cheese ,domestic eggs,napkins} => {whole milk} 0.001118454 1 3.913649
- [13] {pip fruit,whipped/sour cream,brown bread} => {other vegetables} 0.001118454 1 5.168156
- [14] {tropical fruit,grapes,whole milk,yogurt} => {other vegetables} 0.001016777 1 5.168156
- [15] {ham,tropical fruit,pip fruit,yogurt} => {other vegetables} 0.001016777 1 5.168156
- [16] {ham,tropical fruit,pip fruit,whole milk} => {other vegetables} 0.001118454 1 5.168156
- [17] {tropical fruit,root vegetables,yogurt,oil} => {whole milk} 0.001118454 1 3.913649
- [18] {root vegetables,other vegetables,yogurt,oil} => {whole milk} 0.001423488 1 3.913649
- [19] {root vegetables,other vegetables,butter,white bread} => {whole milk} 0.001016777 1 3.913649
- [20] {pork,other vegetables,butter,whipped/sour cream} => {whole milk} 0.001016777 1 3.913649
- [21] {other vegetables,butter,whipped/sour cream,domestic eggs} => {whole milk} 0.001220132 1 3.913649
- [22] {tropical fruit,butter,whipped/sour cream,fruit/vegetable juice} => {other vegetables} 0.001016777 1 5.168156
- [23] {whole milk,rolls/buns,soda,newspapers} => {other vegetables} 0.001016777 1 5.168156
- [24] {citrus fruit,whipped/sour cream,rolls/buns,pastry} => {whole milk} 0.001016777 1 3.913649
- [25] {citrus fruit,tropical fruit,root vegetables,whipped/sour cream} => {other vegetables} 0.001220132 1 5.168156
- [26] {pip fruit,root vegetables,other vegetables,bottled water} => {whole milk} 0.001118454 1 3.913649
- [27] {sausage,tropical fruit,root vegetables,rolls/buns} => {whole milk} 0.001016777 1 3.913649
- > rules<-apriori(data=Groceries, parameter=list(supp=0.001,conf = 0.15,minlen=2),
- + appearance = list(default="rhs",lhs="whole milk"),
- + control = list(verbose=F))
- > rules<-sort(rules, decreasing=TRUE,by="confidence")
- > inspect(rules)
- lhs rhs support confidence lift
- [1] {whole milk} => {other vegetables} 0.07483477 0.2928770 1.5136341
- [2] {whole milk} => {rolls/buns} 0.05663447 0.2216474 1.2050318
- [3] {whole milk} => {yogurt} 0.05602440 0.2192598 1.5717351
- [4] {whole milk} => {root vegetables} 0.04890696 0.1914047 1.7560310
- [5] {whole milk} => {tropical fruit} 0.04229792 0.1655392 1.5775950
- [6] {whole milk} => {soda} 0.04006101 0.1567847 0.8991124
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement