Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. > library(datasets)
  2. > library(Matrix)
  3. > library(arules)
  4. > data(Groceries)
  5. > Groceries
  6. transactions in sparse format with
  7. 9835 transactions (rows) and
  8. 169 items (columns)
  9. > summary(Groceries)
  10. transactions as itemMatrix in sparse format with
  11. 9835 rows (elements/itemsets/transactions) and
  12. 169 columns (items) and a density of 0.02609146
  13.  
  14. most frequent items:
  15. whole milk other vegetables rolls/buns soda yogurt (Other)
  16. 2513 1903 1809 1715 1372 34055
  17.  
  18. element (itemset/transaction) length distribution:
  19. sizes
  20. 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
  21. 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
  22.  
  23. Min. 1st Qu. Median Mean 3rd Qu. Max.
  24. 1.000 2.000 3.000 4.409 6.000 32.000
  25.  
  26. includes extended item information - examples:
  27. labels level2 level1
  28. 1 frankfurter sausage meat and sausage
  29. 2 sausage sausage meat and sausage
  30. 3 liver loaf sausage meat and sausage
  31. > itemFrequencyPlot(Groceries,topN=20,type="absolute")
  32. > rules <- apriori(Groceries, parameter = list(supp = 0.001, conf = 1))
  33. Apriori
  34.  
  35. Parameter specification:
  36. confidence minval smax arem aval originalSupport maxtime support minlen maxlen target ext
  37. 1 0.1 1 none FALSE TRUE 5 0.001 1 10 rules FALSE
  38.  
  39. Algorithmic control:
  40. filter tree heap memopt load sort verbose
  41. 0.1 TRUE TRUE FALSE TRUE 2 TRUE
  42.  
  43. Absolute minimum support count: 9
  44.  
  45. set item appearances ...[0 item(s)] done [0.00s].
  46. set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
  47. sorting and recoding items ... [157 item(s)] done [0.00s].
  48. creating transaction tree ... done [0.00s].
  49. checking subsets of size 1 2 3 4 5 6 done [0.01s].
  50. writing ... [28 rule(s)] done [0.00s].
  51. creating S4 object ... done [0.00s].
  52. > rules<-sort(rules, by="confidence", decreasing=TRUE)
  53. > rules
  54. set of 28 rules
  55. > subset.matrix <- is.subset(rules, rules)
  56. > subset.matrix[lower.tri(subset.matrix, diag=T)] <- NA
  57. > redundant <- colSums(subset.matrix, na.rm=T) >= 1
  58. > rules.pruned <- rules[!redundant]
  59. > rules<-rules.pruned
  60. > inspect(rules)
  61. lhs rhs support confidence lift
  62. [1] {rice,sugar} => {whole milk} 0.001220132 1 3.913649
  63. [2] {canned fish,hygiene articles} => {whole milk} 0.001118454 1 3.913649
  64. [3] {root vegetables,butter,rice} => {whole milk} 0.001016777 1 3.913649
  65. [4] {root vegetables,whipped/sour cream,flour} => {whole milk} 0.001728521 1 3.913649
  66. [5] {butter,soft cheese,domestic eggs} => {whole milk} 0.001016777 1 3.913649
  67. [6] {citrus fruit,root vegetables,soft cheese} => {other vegetables} 0.001016777 1 5.168156
  68. [7] {pip fruit,butter,hygiene articles} => {whole milk} 0.001016777 1 3.913649
  69. [8] {root vegetables,whipped/sour cream,hygiene articles} => {whole milk} 0.001016777 1 3.913649
  70. [9] {pip fruit,root vegetables,hygiene articles} => {whole milk} 0.001016777 1 3.913649
  71. [10] {cream cheese ,domestic eggs,sugar} => {whole milk} 0.001118454 1 3.913649
  72. [11] {curd,domestic eggs,sugar} => {whole milk} 0.001016777 1 3.913649
  73. [12] {cream cheese ,domestic eggs,napkins} => {whole milk} 0.001118454 1 3.913649
  74. [13] {pip fruit,whipped/sour cream,brown bread} => {other vegetables} 0.001118454 1 5.168156
  75. [14] {tropical fruit,grapes,whole milk,yogurt} => {other vegetables} 0.001016777 1 5.168156
  76. [15] {ham,tropical fruit,pip fruit,yogurt} => {other vegetables} 0.001016777 1 5.168156
  77. [16] {ham,tropical fruit,pip fruit,whole milk} => {other vegetables} 0.001118454 1 5.168156
  78. [17] {tropical fruit,root vegetables,yogurt,oil} => {whole milk} 0.001118454 1 3.913649
  79. [18] {root vegetables,other vegetables,yogurt,oil} => {whole milk} 0.001423488 1 3.913649
  80. [19] {root vegetables,other vegetables,butter,white bread} => {whole milk} 0.001016777 1 3.913649
  81. [20] {pork,other vegetables,butter,whipped/sour cream} => {whole milk} 0.001016777 1 3.913649
  82. [21] {other vegetables,butter,whipped/sour cream,domestic eggs} => {whole milk} 0.001220132 1 3.913649
  83. [22] {tropical fruit,butter,whipped/sour cream,fruit/vegetable juice} => {other vegetables} 0.001016777 1 5.168156
  84. [23] {whole milk,rolls/buns,soda,newspapers} => {other vegetables} 0.001016777 1 5.168156
  85. [24] {citrus fruit,whipped/sour cream,rolls/buns,pastry} => {whole milk} 0.001016777 1 3.913649
  86. [25] {citrus fruit,tropical fruit,root vegetables,whipped/sour cream} => {other vegetables} 0.001220132 1 5.168156
  87. [26] {pip fruit,root vegetables,other vegetables,bottled water} => {whole milk} 0.001118454 1 3.913649
  88. [27] {sausage,tropical fruit,root vegetables,rolls/buns} => {whole milk} 0.001016777 1 3.913649
  89. > rules<-apriori(data=Groceries, parameter=list(supp=0.001,conf = 0.15,minlen=2),
  90. + appearance = list(default="rhs",lhs="whole milk"),
  91. + control = list(verbose=F))
  92. > rules<-sort(rules, decreasing=TRUE,by="confidence")
  93. > inspect(rules)
  94. lhs rhs support confidence lift
  95. [1] {whole milk} => {other vegetables} 0.07483477 0.2928770 1.5136341
  96. [2] {whole milk} => {rolls/buns} 0.05663447 0.2216474 1.2050318
  97. [3] {whole milk} => {yogurt} 0.05602440 0.2192598 1.5717351
  98. [4] {whole milk} => {root vegetables} 0.04890696 0.1914047 1.7560310
  99. [5] {whole milk} => {tropical fruit} 0.04229792 0.1655392 1.5775950
  100. [6] {whole milk} => {soda} 0.04006101 0.1567847 0.8991124
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement