library(arules)
library(arulesViz)
library(datasets)
library(knitr)
Za pomocą analizy koszykowej zidentyfikować reguły pozwalające na zarządzanie przestrzenią w sklepie wielkopowierzchniowym.
Dokonać przeglądu produktów na podstawie obiektu data frame „baza”. Wydzielić grupy produktów spożywczych, nabiałowych, pieczywa, mięsa, serów, warzyw, środków higieny i czystości. Opisać je, tak jak zostało to przedstawione na przykładzie “środki czystości”.
setwd("C:/Users/majal/OneDrive - Politechnika Gdańska/Pulpit/PG/AG2 SEM3/big data")
baza1<- read.csv("C:/Users/majal/OneDrive - Politechnika Gdańska/Pulpit/PG/AG2 SEM3/big data/groceries.csv", sep=",",header = FALSE)
groceries <- read.transactions("groceries.csv", sep = ",")
Najczęściej występujące produkty:
itemFrequencyPlot(groceries, topN = 30)
Grupy produktów na podstawie analizy unikalnych wartości:
categories_names <- c("Nabial","Pieczywo","Mieso","Warzywa i owoce","Srodki czystosci","Alkohol","Napoje","Przekaski")
categories <- list(
"Nabial" = c("whole milk", "yogurt", "butter", "cheese","whipped/sour cream","
UHT-milk"),
"Pieczywo" = c("bread", "rolls/buns", "pastry","brown bread","waffles"),
"Mieso" = c("chicken", "beef", "pork","sausage","frankfurter"),
"Warzywa i owoce" = c("root vegetables", "other vegetables", "potatoes","pip fruit","tropical fruit","citrus fruit"),
"Srodki czystosci" = c("detergent", "cleaner"),
"Alkohol"= c("canned beer","bottled beer","white wine"),
"Napoje"=c("soda","bottled water","coffee","misc. beverages","beverages","
fruit/vegetable juice"),
"Przekaski"=c("chocolate","ice cream","salty snack","specialty chocolate","specialty bar")
)
kable(categories, format = "html", caption="Nabial, Pieczywo, Mieso, Warzywa i owoce, Srodki czystosci, Alkohol, Napoje, Przekaski", col.names=NULL)
|
|
|
|
|
|
|
|
Dokonać przeglądu składu koszyków na podstawie obiektu data frame „baza”. Zaproponować wstępne reguły lub wstępną listę produktów po lewej lub prawej stronie reguły asocjacyjnej.
Przykładowe transakcje:
kable(head(baza1, 50), format = "markdown")
V1 | V2 | V3 | V4 |
---|---|---|---|
citrus fruit | semi-finished bread | margarine | ready soups |
tropical fruit | yogurt | coffee | |
whole milk | |||
pip fruit | yogurt | cream cheese | meat spreads |
other vegetables | whole milk | condensed milk | long life bakery product |
whole milk | butter | yogurt | rice |
abrasive cleaner | |||
rolls/buns | |||
other vegetables | UHT-milk | rolls/buns | bottled beer |
liquor (appetizer) | |||
potted plants | |||
whole milk | cereals | ||
tropical fruit | other vegetables | white bread | bottled water |
chocolate | |||
citrus fruit | tropical fruit | whole milk | butter |
curd | yogurt | flour | bottled water |
dishes | |||
beef | |||
frankfurter | rolls/buns | soda | |
chicken | tropical fruit | ||
butter | sugar | fruit/vegetable juice | newspapers |
fruit/vegetable juice | |||
packaged fruit/vegetables | |||
chocolate | |||
specialty bar | |||
other vegetables | |||
butter milk | pastry | ||
whole milk | |||
tropical fruit | cream cheese | processed cheese | detergent |
newspapers | |||
tropical fruit | root vegetables | other vegetables | frozen dessert |
rolls/buns | flour | sweet spreads | salty snack |
waffles | candy | bathroom cleaner | |
bottled water | canned beer | ||
yogurt | |||
sausage | rolls/buns | soda | chocolate |
other vegetables | |||
brown bread | soda | fruit/vegetable juice | canned beer |
newspapers | shopping bags | ||
yogurt | beverages | bottled water | specialty bar |
hamburger meat | other vegetables | rolls/buns | spices |
bottled water | hygiene articles | napkins | |
root vegetables | other vegetables | whole milk | beverages |
sugar | |||
pork | berries | other vegetables | whole milk |
whipped/sour cream | artif. sweetener | soda | abrasive cleaner |
beef | grapes | detergent | |
pastry | soda | ||
fruit/vegetable juice | |||
canned beer |
Wstępne reguły:
rules_initial <- list(
"(whole milk) => (other vegetables, yogurt)",
"(bread) => (butter, jam)",
"(soda) => (pastry,rolls/buns)"
)
rules_initial
## [[1]]
## [1] "(whole milk) => (other vegetables, yogurt)"
##
## [[2]]
## [1] "(bread) => (butter, jam)"
##
## [[3]]
## [1] "(soda) => (pastry,rolls/buns)"
Obliczyć wstępnie wszystkie sensowne reguły i je posortować po poziomie ufności:
Reguły posortowane po poziomie ufności:
rules <- apriori(groceries, parameter = list(support = 0.006, 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.006 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: 59
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [109 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 done [0.00s].
## writing ... [463 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules <- sort(rules, by = "confidence", decreasing = TRUE)
inscpect1<-DATAFRAME(rules[1:10])
kable(inscpect1, format = 'markdown')
LHS | RHS | support | confidence | coverage | lift | count | |
---|---|---|---|---|---|---|---|
221 | {butter,whipped/sour cream} | {whole milk} | 0.0067107 | 0.6600000 | 0.0101678 | 2.583008 | 66 |
229 | {butter,yogurt} | {whole milk} | 0.0093543 | 0.6388889 | 0.0146416 | 2.500387 | 92 |
225 | {butter,root vegetables} | {whole milk} | 0.0082359 | 0.6377953 | 0.0129131 | 2.496107 | 81 |
183 | {curd,tropical fruit} | {whole milk} | 0.0065074 | 0.6336634 | 0.0102694 | 2.479936 | 64 |
222 | {butter,tropical fruit} | {whole milk} | 0.0062023 | 0.6224490 | 0.0099644 | 2.436047 | 61 |
452 | {other vegetables,tropical fruit,yogurt} | {whole milk} | 0.0076258 | 0.6198347 | 0.0123030 | 2.425816 | 75 |
239 | {domestic eggs,tropical fruit} | {whole milk} | 0.0069141 | 0.6071429 | 0.0113879 | 2.376144 | 68 |
456 | {other vegetables,root vegetables,yogurt} | {whole milk} | 0.0078292 | 0.6062992 | 0.0129131 | 2.372842 | 77 |
242 | {domestic eggs,root vegetables} | {whole milk} | 0.0085409 | 0.5957447 | 0.0143366 | 2.331536 | 84 |
318 | {citrus fruit,root vegetables} | {other vegetables} | 0.0103711 | 0.5862069 | 0.0176919 | 3.029608 | 102 |
“Wsparcie, , support” to prawdopodobieństwo wystąpienia produktu lub zestawu produktów (mleko i chleb), liczebność wybranych transakcji (mleko i chleb) do liczebności wszystkich transakcji.
“Poziom ufności, confidence” to prawdopodobieństwo warunkowe, liczebność występowania wybranych transakcji (mleko i chleb) do liczebności (mleko).
“Coverage” - wsparcie dla lewej strony, badanie częstości występowania artykułów.
Usunięcie regół powtarzających się:
rules_redundant <- rules[!is.redundant(rules)]
rules_redundant_top50 <- head(rules_redundant, n=50, by="confidence", decreasing=TRUE)
inscpect1.1<-DATAFRAME(rules_redundant_top50)
kable(inscpect1.1,format="markdown")
LHS | RHS | support | confidence | coverage | lift | count | |
---|---|---|---|---|---|---|---|
221 | {butter,whipped/sour cream} | {whole milk} | 0.0067107 | 0.6600000 | 0.0101678 | 2.583008 | 66 |
229 | {butter,yogurt} | {whole milk} | 0.0093543 | 0.6388889 | 0.0146416 | 2.500387 | 92 |
225 | {butter,root vegetables} | {whole milk} | 0.0082359 | 0.6377953 | 0.0129131 | 2.496107 | 81 |
183 | {curd,tropical fruit} | {whole milk} | 0.0065074 | 0.6336634 | 0.0102694 | 2.479936 | 64 |
222 | {butter,tropical fruit} | {whole milk} | 0.0062023 | 0.6224490 | 0.0099644 | 2.436047 | 61 |
452 | {other vegetables,tropical fruit,yogurt} | {whole milk} | 0.0076258 | 0.6198347 | 0.0123030 | 2.425816 | 75 |
239 | {domestic eggs,tropical fruit} | {whole milk} | 0.0069141 | 0.6071429 | 0.0113879 | 2.376144 | 68 |
456 | {other vegetables,root vegetables,yogurt} | {whole milk} | 0.0078292 | 0.6062992 | 0.0129131 | 2.372842 | 77 |
242 | {domestic eggs,root vegetables} | {whole milk} | 0.0085409 | 0.5957447 | 0.0143366 | 2.331536 | 84 |
318 | {citrus fruit,root vegetables} | {other vegetables} | 0.0103711 | 0.5862069 | 0.0176919 | 3.029608 | 102 |
155 | {other vegetables,sugar} | {whole milk} | 0.0063040 | 0.5849057 | 0.0107778 | 2.289115 | 62 |
449 | {root vegetables,tropical fruit,whole milk} | {other vegetables} | 0.0070158 | 0.5847458 | 0.0119980 | 3.022057 | 69 |
386 | {root vegetables,tropical fruit} | {other vegetables} | 0.0123030 | 0.5845411 | 0.0210473 | 3.020999 | 121 |
187 | {curd,yogurt} | {whole milk} | 0.0100661 | 0.5823529 | 0.0172852 | 2.279125 | 99 |
261 | {citrus fruit,whipped/sour cream} | {whole milk} | 0.0063040 | 0.5794393 | 0.0108795 | 2.267722 | 62 |
290 | {pip fruit,root vegetables} | {whole milk} | 0.0089476 | 0.5751634 | 0.0155567 | 2.250988 | 88 |
189 | {curd,other vegetables} | {whole milk} | 0.0098627 | 0.5739645 | 0.0171835 | 2.246296 | 97 |
232 | {butter,other vegetables} | {whole milk} | 0.0114896 | 0.5736041 | 0.0200305 | 2.244885 | 113 |
266 | {tropical fruit,whipped/sour cream} | {whole milk} | 0.0079309 | 0.5735294 | 0.0138282 | 2.244593 | 78 |
448 | {other vegetables,root vegetables,tropical fruit} | {whole milk} | 0.0070158 | 0.5702479 | 0.0123030 | 2.231750 | 69 |
184 | {curd,root vegetables} | {whole milk} | 0.0062023 | 0.5700935 | 0.0108795 | 2.231146 | 61 |
389 | {root vegetables,tropical fruit} | {whole milk} | 0.0119980 | 0.5700483 | 0.0210473 | 2.230969 | 118 |
264 | {tropical fruit,whipped/sour cream} | {other vegetables} | 0.0078292 | 0.5661765 | 0.0138282 | 2.926088 | 77 |
416 | {root vegetables,yogurt} | {whole milk} | 0.0145399 | 0.5629921 | 0.0258261 | 2.203354 | 143 |
203 | {frankfurter,yogurt} | {whole milk} | 0.0062023 | 0.5545455 | 0.0111845 | 2.170296 | 61 |
271 | {root vegetables,whipped/sour cream} | {whole milk} | 0.0094560 | 0.5535714 | 0.0170819 | 2.166484 | 93 |
247 | {domestic eggs,other vegetables} | {whole milk} | 0.0123030 | 0.5525114 | 0.0222674 | 2.162336 | 121 |
251 | {fruit/vegetable juice,root vegetables} | {other vegetables} | 0.0066090 | 0.5508475 | 0.0119980 | 2.846865 | 65 |
199 | {pork,rolls/buns} | {whole milk} | 0.0062023 | 0.5495495 | 0.0112862 | 2.150744 | 61 |
152 | {onions,whole milk} | {other vegetables} | 0.0066090 | 0.5462185 | 0.0120996 | 2.822942 | 65 |
171 | {frozen vegetables,other vegetables} | {whole milk} | 0.0096594 | 0.5428571 | 0.0177936 | 2.124552 | 95 |
253 | {fruit/vegetable juice,root vegetables} | {whole milk} | 0.0065074 | 0.5423729 | 0.0119980 | 2.122657 | 64 |
244 | {domestic eggs,yogurt} | {whole milk} | 0.0077275 | 0.5390071 | 0.0143366 | 2.109485 | 76 |
457 | {root vegetables,whole milk,yogurt} | {other vegetables} | 0.0078292 | 0.5384615 | 0.0145399 | 2.782853 | 77 |
217 | {margarine,rolls/buns} | {whole milk} | 0.0079309 | 0.5379310 | 0.0147433 | 2.105273 | 78 |
167 | {frozen vegetables,root vegetables} | {whole milk} | 0.0062023 | 0.5350877 | 0.0115913 | 2.094146 | 61 |
278 | {rolls/buns,whipped/sour cream} | {whole milk} | 0.0078292 | 0.5347222 | 0.0146416 | 2.092715 | 77 |
157 | {cream cheese,yogurt} | {whole milk} | 0.0066090 | 0.5327869 | 0.0124047 | 2.085141 | 65 |
294 | {pip fruit,yogurt} | {whole milk} | 0.0095577 | 0.5310734 | 0.0179969 | 2.078435 | 94 |
165 | {frozen vegetables,root vegetables} | {other vegetables} | 0.0061007 | 0.5263158 | 0.0115913 | 2.720082 | 60 |
275 | {whipped/sour cream,yogurt} | {whole milk} | 0.0108795 | 0.5245098 | 0.0207422 | 2.052747 | 107 |
422 | {rolls/buns,root vegetables} | {whole milk} | 0.0127097 | 0.5230126 | 0.0243010 | 2.046888 | 125 |
14 | {baking powder} | {whole milk} | 0.0092527 | 0.5229885 | 0.0176919 | 2.046794 | 91 |
288 | {pip fruit,root vegetables} | {other vegetables} | 0.0081342 | 0.5228758 | 0.0155567 | 2.702304 | 80 |
177 | {beef,yogurt} | {whole milk} | 0.0061007 | 0.5217391 | 0.0116929 | 2.041904 | 60 |
337 | {sausage,tropical fruit} | {whole milk} | 0.0072191 | 0.5182482 | 0.0139298 | 2.028242 | 71 |
297 | {other vegetables,pip fruit} | {whole milk} | 0.0135231 | 0.5175097 | 0.0261312 | 2.025351 | 133 |
400 | {tropical fruit,yogurt} | {whole milk} | 0.0151500 | 0.5173611 | 0.0292832 | 2.024770 | 149 |
303 | {pastry,yogurt} | {whole milk} | 0.0091510 | 0.5172414 | 0.0176919 | 2.024301 | 90 |
320 | {citrus fruit,root vegetables} | {whole milk} | 0.0091510 | 0.5172414 | 0.0176919 | 2.024301 | 90 |
Zobaczyć, które produkty występują najczęściej i skonfrontować to z regułami z polecenia 3. Znaleźć nowe reguły lub potwierdzić stare, gdzie produkty najczęściej występujące w koszyku są po prawej stronie (tutaj założyć w procedurze apriori odpowiednie produkty po prawej stronie), zaproponować do praktycznego wdrożenia reguły odwrotne. Można również zaproponować wybrane produkty po lewej stronie lub po obydwu stronach.
Najczęściej występujące produkty:
itemFrequencyPlot(groceries, topN = 30)
Generowanie reguł z konkretnymi produktami prawej stronie:
rules_rhs <- apriori(groceries, parameter = list(supp = 0.005, conf = 0.01),
appearance = list(rhs = "canned beer", default = "lhs"))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.01 0.1 1 none FALSE TRUE 5 0.005 1
## 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: 49
##
## set item appearances ...[1 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [120 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 done [0.00s].
## writing ... [9 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules_rhs <- sort(rules_rhs, by = "confidence", decreasing = TRUE)
inscpect2<-DATAFRAME(rules_rhs[1:5])
kable(inscpect2,format="markdown")
LHS | RHS | support | confidence | coverage | lift | count | |
---|---|---|---|---|---|---|---|
2 | {shopping bags} | {canned beer} | 0.0113879 | 0.1155831 | 0.0985257 | 1.4879052 | 112 |
5 | {soda} | {canned beer} | 0.0138282 | 0.0793003 | 0.1743772 | 1.0208356 | 136 |
1 | {} | {canned beer} | 0.0776817 | 0.0776817 | 1.0000000 | 1.0000000 | 764 |
4 | {bottled water} | {canned beer} | 0.0080325 | 0.0726771 | 0.1105236 | 0.9355749 | 79 |
3 | {sausage} | {canned beer} | 0.0063040 | 0.0670996 | 0.0939502 | 0.8637752 | 62 |
rules_rhs1 <- apriori(groceries, parameter = list(supp = 0.005, conf = 0.25),
appearance = list(rhs = "rolls/buns", default = "lhs"))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.25 0.1 1 none FALSE TRUE 5 0.005 1
## 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: 49
##
## set item appearances ...[1 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [120 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 done [0.00s].
## writing ... [55 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules_rhs1 <- sort(rules_rhs1, by = "confidence", decreasing = TRUE)
inscpect3<-DATAFRAME(rules_rhs1[1:5])
kable(inscpect3,format="markdown")
LHS | RHS | support | confidence | coverage | lift | count | |
---|---|---|---|---|---|---|---|
35 | {sausage,soda} | {rolls/buns} | 0.0096594 | 0.3974895 | 0.0243010 | 2.161033 | 95 |
33 | {sausage,shopping bags} | {rolls/buns} | 0.0059990 | 0.3831169 | 0.0156584 | 2.082894 | 59 |
18 | {frankfurter,other vegetables} | {rolls/buns} | 0.0055923 | 0.3395062 | 0.0164718 | 1.845795 | 55 |
24 | {newspapers,yogurt} | {rolls/buns} | 0.0050839 | 0.3311258 | 0.0153533 | 1.800234 | 50 |
37 | {other vegetables,sausage} | {rolls/buns} | 0.0088460 | 0.3283019 | 0.0269446 | 1.784881 | 87 |
rules_rhs2 <- apriori(groceries, parameter = list(supp = 0.005, conf = 0.25),
appearance = list(rhs = "other vegetables", default = "lhs"))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.25 0.1 1 none FALSE TRUE 5 0.005 1
## 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: 49
##
## set item appearances ...[1 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [120 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 done [0.00s].
## writing ... [178 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules_rhs2 <- sort(rules_rhs2, by = "confidence", decreasing = TRUE)
inscpect4<-DATAFRAME(rules_rhs2[1:5])
kable(inscpect4,format="markdown")
LHS | RHS | support | confidence | coverage | lift | count | |
---|---|---|---|---|---|---|---|
173 | {citrus fruit,root vegetables,whole milk} | {other vegetables} | 0.0057956 | 0.6333333 | 0.0091510 | 3.273165 | 57 |
171 | {pip fruit,root vegetables,whole milk} | {other vegetables} | 0.0054906 | 0.6136364 | 0.0089476 | 3.171368 | 54 |
111 | {pip fruit,whipped/sour cream} | {other vegetables} | 0.0055923 | 0.6043956 | 0.0092527 | 3.123610 | 55 |
54 | {onions,root vegetables} | {other vegetables} | 0.0056940 | 0.6021505 | 0.0094560 | 3.112008 | 56 |
132 | {citrus fruit,root vegetables} | {other vegetables} | 0.0103711 | 0.5862069 | 0.0176919 | 3.029608 | 102 |
rules_rhs3 <- apriori(groceries, parameter = list(supp = 0.005, conf = 0.25),
appearance = list(rhs = "whole milk", default = "lhs"))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.25 0.1 1 none FALSE TRUE 5 0.005 1
## 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: 49
##
## set item appearances ...[1 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
## sorting and recoding items ... [120 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 done [0.00s].
## writing ... [222 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules_rhs3 <- sort(rules_rhs3, by = "confidence", decreasing = TRUE)
inscpect5<-DATAFRAME(rules_rhs3[1:5])
kable(inscpect5,format="markdown")
LHS | RHS | support | confidence | coverage | lift | count | |
---|---|---|---|---|---|---|---|
217 | {root vegetables,tropical fruit,yogurt} | {whole milk} | 0.0056940 | 0.7000000 | 0.0081342 | 2.739554 | 56 |
214 | {other vegetables,pip fruit,root vegetables} | {whole milk} | 0.0054906 | 0.6750000 | 0.0081342 | 2.641713 | 54 |
121 | {butter,whipped/sour cream} | {whole milk} | 0.0067107 | 0.6600000 | 0.0101678 | 2.583008 | 66 |
150 | {pip fruit,whipped/sour cream} | {whole milk} | 0.0059990 | 0.6483516 | 0.0092527 | 2.537421 | 59 |
126 | {butter,yogurt} | {whole milk} | 0.0093543 | 0.6388889 | 0.0146416 | 2.500387 | 92 |
Generowanie reguł z konkretnymi produktami lewej stronie:
rules_lhs<-apriori(data=groceries, parameter=list(supp=0.001,conf = 0.15,minlen=2), appearance = list(default="rhs",lhs="yogurt"))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.15 0.1 1 none FALSE TRUE 5 0.001 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: 9
##
## set item appearances ...[1 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 done [0.00s].
## writing ... [8 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules_lhs<-sort(rules_lhs, decreasing=TRUE,by="confidence")
inscpect6<-DATAFRAME(rules_lhs[1:5])
kable(inscpect6,format="markdown")
LHS | RHS | support | confidence | coverage | lift | count | |
---|---|---|---|---|---|---|---|
8 | {yogurt} | {whole milk} | 0.0560244 | 0.4016035 | 0.1395018 | 1.571735 | 551 |
7 | {yogurt} | {other vegetables} | 0.0434164 | 0.3112245 | 0.1395018 | 1.608457 | 427 |
6 | {yogurt} | {rolls/buns} | 0.0343671 | 0.2463557 | 0.1395018 | 1.339363 | 338 |
3 | {yogurt} | {tropical fruit} | 0.0292832 | 0.2099125 | 0.1395018 | 2.000475 | 288 |
5 | {yogurt} | {soda} | 0.0273513 | 0.1960641 | 0.1395018 | 1.124368 | 269 |
rules_lhs1<-apriori(data=groceries, parameter=list(supp=0.001,conf = 0.15,minlen=2), appearance = list(default="rhs",lhs="bottled water"))
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.15 0.1 1 none FALSE TRUE 5 0.001 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: 9
##
## set item appearances ...[1 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 done [0.00s].
## writing ... [6 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
rules_lhs1<-sort(rules_lhs1, decreasing=TRUE,by="confidence")
inscpect7<-DATAFRAME(rules_lhs1[1:5])
kable(inscpect7,format="markdown")
LHS | RHS | support | confidence | coverage | lift | count | |
---|---|---|---|---|---|---|---|
6 | {bottled water} | {whole milk} | 0.0343671 | 0.3109476 | 0.1105236 | 1.216940 | 338 |
2 | {bottled water} | {soda} | 0.0289781 | 0.2621895 | 0.1105236 | 1.503577 | 285 |
5 | {bottled water} | {other vegetables} | 0.0248094 | 0.2244710 | 0.1105236 | 1.160101 | 244 |
4 | {bottled water} | {rolls/buns} | 0.0241993 | 0.2189512 | 0.1105236 | 1.190373 | 238 |
3 | {bottled water} | {yogurt} | 0.0229792 | 0.2079117 | 0.1105236 | 1.490387 | 226 |
Reguły przygotowane do wykorzystania przy zarządzaniu przestrzenią w sklepie:
{butter, whipped/sour cream} | => | {whole milk} |
{other vegetables, pip fruit, root vegetables} | => | {whole milk} |
Whole milk jest produktem, po który klienci siegają najczęściej. Z reguł wynika, że są jest ono kupowane głównie w towarzystwie warzyw i owoców oraz innych produktów nabiałowych.
{sausage, soda} | => | {rolls/buns} |
{frankfurter, other vegetables} | => | {rolls/buns} |
Rolls/buns najczęściej kupowane są produktami odzwięrzęcymi (po niecałe 100 wystąpień każdej reguły).
{citrus fruit, root vegetables} | => | {other vegetables} |
Wybór other vegetables, może sugerować, że klient zakupi więcej, niż jedno warzywo/owoc.
{bottled water} | => | {whole milk} |
{bottled water} | => | {soda} |
Stawiając bottled water po lewej stronie, z reguł wychodzi, że najczęściej kupowane są razem z mlekiem lub sodą, czyli pozostałymi napojami.
{} | => | {canned beer} |
Aż 764 razy, klient, który kupował canned beer, wyszedł ze sklepu tylko z tym produktem.
Rekomendacje dla sklepu:
Celem analizy jest znalezienie produktów, które klienci najczęściej kupują razem. Powyżej przedstawione zostały reguły, które odzwierciedliły wybory klientów w bazie danych. Na tej podstawie powstała mapa sklepu, z rozmieszczeniem produktów, w taki sposób, aby produkty wspólnie kupowane były na przeciwległych końcach, co zmusza konsumenta do obejścia całego sklepu.