Load the necessary libraries

Intro

Dataset for the project was taken from kaggle.com website: https://www.kaggle.com/datasets/irfanasrullah/groceries

Data Analysis

groceries <- read.csv('C:/Users/1032745/OneDrive - Blue Yonder/Desktop/PRIVATE/STUDIA/UL/PROJECTS/groceries.csv', header = TRUE)
groceries_copy <- groceries

Data represents market basket. Each row is a separate basket. Each column represents iteams purchased.

dim(groceries)
## [1] 9835   32

Let us see which 5 products appear most and least frequently in the dataset:

vector_of_characters <- as.vector(t(groceries))
frequency_table <- sort(table(vector_of_characters), decreasing = TRUE)
frequency_df <- data.frame(value=names(frequency_table), count=frequency_table)
frequency_df <- frequency_df[-1,]
frequency_df <- frequency_df[order(-frequency_df$count.Freq, decreasing=FALSE),]

ggplot(frequency_df[1:10,], aes(x=reorder(value, count.Freq), y=count.Freq)) +
  geom_col(fill="#007FFF") +
  theme_classic() +
  labs(x="Value", y="Count", title="Frequency of Values") +
  scale_y_continuous(limits=c(0, max(frequency_df$count.Freq)), expand=c(0,0)) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

vector_of_characters2 <- as.vector(t(groceries))
frequency_table2 <- sort(table(vector_of_characters2), decreasing = FALSE)
head(frequency_table2)
## vector_of_characters2
##             baby food  sound storage medium preservation products 
##                     1                     1                     2 
##                  bags       kitchen utensil        baby cosmetics 
##                     4                     4                     6

Whole milk is the most frequently bought product. “Sound storage medium” and “baby food” are the least frequently bought.

Let us have a look at count of items in the basket. What is the most common number of items?

groceries_copy$num_items <- rowSums(groceries_copy != "")

groceries_copy %>%
  count(num_items) %>%
  ggplot(aes(x=num_items, y=n)) +
  geom_bar(fill = "blue", stat="identity") +
  scale_fill_gradient(low="lightblue", high="blue")

The most popular basket contains only one product. Then it regulary decreases what can be seen on the chart.

ALGORITHMS

Now having completed data analysis let us perform algorithms on the data.

ECLAT

trans1<-read.transactions("C:/Users/1032745/OneDrive - Blue Yonder/Desktop/PRIVATE/STUDIA/UL/PROJECTS/groceries.csv", format="basket", sep=",", skip=1, header=TRUE) 
round(itemFrequency(trans1),3)
##          abrasive cleaner          artif. sweetener            baby cosmetics 
##                     0.004                     0.003                     0.001 
##                 baby food                      bags             baking powder 
##                     0.000                     0.000                     0.018 
##          bathroom cleaner                      beef                   berries 
##                     0.003                     0.052                     0.033 
##                 beverages              bottled beer             bottled water 
##                     0.026                     0.081                     0.111 
##                    brandy               brown bread                    butter 
##                     0.004                     0.065                     0.055 
##               butter milk                  cake bar                   candles 
##                     0.028                     0.013                     0.009 
##                     candy               canned beer               canned fish 
##                     0.030                     0.078                     0.015 
##              canned fruit         canned vegetables                  cat food 
##                     0.003                     0.011                     0.023 
##                   cereals               chewing gum                   chicken 
##                     0.006                     0.021                     0.043 
##                 chocolate     chocolate marshmallow              citrus fruit 
##                     0.050                     0.009                     0.083 
##                   cleaner           cling film/bags              cocoa drinks 
##                     0.005                     0.011                     0.002 
##                    coffee            condensed milk         cooking chocolate 
##                     0.058                     0.010                     0.003 
##                  cookware                     cream              cream cheese 
##                     0.003                     0.001                     0.040 
##                      curd               curd cheese               decalcifier 
##                     0.053                     0.005                     0.002 
##               dental care                   dessert                 detergent 
##                     0.006                     0.037                     0.019 
##              dish cleaner                    dishes                  dog food 
##                     0.010                     0.018                     0.009 
##             domestic eggs  female sanitary products         finished products 
##                     0.063                     0.006                     0.007 
##                      fish                     flour            flower (seeds) 
##                     0.003                     0.017                     0.010 
##    flower soil/fertilizer               frankfurter            frozen chicken 
##                     0.002                     0.059                     0.001 
##            frozen dessert               frozen fish             frozen fruits 
##                     0.011                     0.012                     0.001 
##              frozen meals    frozen potato products         frozen vegetables 
##                     0.028                     0.008                     0.048 
##     fruit/vegetable juice                    grapes                hair spray 
##                     0.072                     0.022                     0.001 
##                       ham            hamburger meat               hard cheese 
##                     0.026                     0.033                     0.025 
##                     herbs                     honey    house keeping products 
##                     0.016                     0.002                     0.008 
##          hygiene articles                 ice cream            instant coffee 
##                     0.033                     0.025                     0.007 
##     Instant food products                       jam                   ketchup 
##                     0.008                     0.005                     0.004 
##            kitchen towels           kitchen utensil               light bulbs 
##                     0.006                     0.000                     0.004 
##                   liqueur                    liquor        liquor (appetizer) 
##                     0.001                     0.011                     0.008 
##                liver loaf  long life bakery product           make up remover 
##                     0.005                     0.037                     0.001 
##            male cosmetics                 margarine                mayonnaise 
##                     0.005                     0.058                     0.009 
##                      meat              meat spreads           misc. beverages 
##                     0.026                     0.004                     0.028 
##                   mustard                   napkins                newspapers 
##                     0.012                     0.052                     0.080 
##                 nut snack               nuts/prunes                       oil 
##                     0.003                     0.003                     0.028 
##                    onions          organic products           organic sausage 
##                     0.031                     0.002                     0.002 
##          other vegetables packaged fruit/vegetables                     pasta 
##                     0.194                     0.013                     0.015 
##                    pastry                  pet care                photo/film 
##                     0.089                     0.009                     0.009 
##        pickled vegetables                 pip fruit                   popcorn 
##                     0.018                     0.076                     0.007 
##                      pork           potato products             potted plants 
##                     0.058                     0.003                     0.017 
##     preservation products          processed cheese                  prosecco 
##                     0.000                     0.017                     0.002 
##            pudding powder               ready soups            red/blush wine 
##                     0.002                     0.002                     0.019 
##                      rice             roll products                rolls/buns 
##                     0.008                     0.010                     0.184 
##           root vegetables           rubbing alcohol                       rum 
##                     0.109                     0.001                     0.004 
##            salad dressing                      salt               salty snack 
##                     0.001                     0.011                     0.038 
##                    sauces                   sausage         seasonal products 
##                     0.005                     0.094                     0.014 
##       semi-finished bread             shopping bags                 skin care 
##                     0.018                     0.099                     0.004 
##             sliced cheese            snack products                      soap 
##                     0.025                     0.003                     0.003 
##                      soda               soft cheese                  softener 
##                     0.174                     0.017                     0.005 
##      sound storage medium                     soups            sparkling wine 
##                     0.000                     0.007                     0.006 
##             specialty bar          specialty cheese       specialty chocolate 
##                     0.027                     0.009                     0.030 
##             specialty fat      specialty vegetables                    spices 
##                     0.004                     0.002                     0.005 
##             spread cheese                     sugar             sweet spreads 
##                     0.011                     0.034                     0.009 
##                     syrup                       tea                   tidbits 
##                     0.003                     0.004                     0.002 
##            toilet cleaner            tropical fruit                    turkey 
##                     0.001                     0.105                     0.008 
##                  UHT-milk                   vinegar                   waffles 
##                     0.033                     0.007                     0.038 
##        whipped/sour cream                    whisky               white bread 
##                     0.072                     0.001                     0.042 
##                white wine                whole milk                    yogurt 
##                     0.019                     0.256                     0.140 
##                  zwieback 
##                     0.007
inspect(head(trans1))
##     items                      
## [1] {coffee,                   
##      tropical fruit,           
##      yogurt}                   
## [2] {whole milk}               
## [3] {cream cheese,             
##      meat spreads,             
##      pip fruit,                
##      yogurt}                   
## [4] {condensed milk,           
##      long life bakery product, 
##      other vegetables,         
##      whole milk}               
## [5] {abrasive cleaner,         
##      butter,                   
##      rice,                     
##      whole milk,               
##      yogurt}                   
## [6] {rolls/buns}
freq.items<-eclat(trans1, parameter=list(supp=0.025, maxlen=15))
## Eclat
## 
## parameter specification:
##  tidLists support minlen maxlen            target  ext
##     FALSE   0.025      1     15 frequent itemsets TRUE
## 
## algorithmic control:
##  sparse sort verbose
##       7   -2    TRUE
## 
## Absolute minimum support count: 245 
## 
## create itemset ... 
## set transactions ...[169 item(s), 9834 transaction(s)] done [0.01s].
## sorting and recoding items ... [54 item(s)] done [0.00s].
## creating sparse bit matrix ... [54 row(s), 9834 column(s)] done [0.00s].
## writing  ... [88 set(s)] done [0.02s].
## Creating S4 object  ... done [0.00s].
inspect(freq.items) 
##      items                                  support    count
## [1]  {curd, whole milk}                     0.02613382  257 
## [2]  {brown bread, whole milk}              0.02521863  248 
## [3]  {butter, whole milk}                   0.02755745  271 
## [4]  {newspapers, whole milk}               0.02735408  269 
## [5]  {domestic eggs, whole milk}            0.02999797  295 
## [6]  {fruit/vegetable juice, whole milk}    0.02664226  262 
## [7]  {whipped/sour cream, whole milk}       0.03223510  317 
## [8]  {other vegetables, whipped/sour cream} 0.02887940  284 
## [9]  {pip fruit, whole milk}                0.03009965  296 
## [10] {other vegetables, pip fruit}          0.02613382  257 
## [11] {pastry, whole milk}                   0.03325198  327 
## [12] {citrus fruit, whole milk}             0.03050641  300 
## [13] {citrus fruit, other vegetables}       0.02887940  284 
## [14] {sausage, whole milk}                  0.02989628  294 
## [15] {other vegetables, sausage}            0.02694733  265 
## [16] {rolls/buns, sausage}                  0.03060809  301 
## [17] {bottled water, whole milk}            0.03437055  338 
## [18] {bottled water, soda}                  0.02898109  285 
## [19] {tropical fruit, whole milk}           0.04230222  416 
## [20] {other vegetables, tropical fruit}     0.03589587  353 
## [21] {tropical fruit, yogurt}               0.02928615  288 
## [22] {root vegetables, whole milk}          0.04891194  481 
## [23] {other vegetables, root vegetables}    0.04738662  466 
## [24] {root vegetables, yogurt}              0.02582876  254 
## [25] {soda, whole milk}                     0.04006508  394 
## [26] {other vegetables, soda}               0.03274354  322 
## [27] {rolls/buns, soda}                     0.03833638  377 
## [28] {soda, yogurt}                         0.02735408  269 
## [29] {whole milk, yogurt}                   0.05603010  551 
## [30] {other vegetables, yogurt}             0.04342079  427 
## [31] {rolls/buns, yogurt}                   0.03437055  338 
## [32] {rolls/buns, whole milk}               0.05664023  557 
## [33] {other vegetables, rolls/buns}         0.04260728  419 
## [34] {other vegetables, whole milk}         0.07484238  736 
## [35] {whole milk}                           0.25554200 2513 
## [36] {other vegetables}                     0.19351230 1903 
## [37] {rolls/buns}                           0.18395363 1809 
## [38] {yogurt}                               0.13951597 1372 
## [39] {soda}                                 0.17439496 1715 
## [40] {root vegetables}                      0.10900956 1072 
## [41] {tropical fruit}                       0.10494204 1032 
## [42] {bottled water}                        0.11053488 1087 
## [43] {sausage}                              0.09395973  924 
## [44] {shopping bags}                        0.09853569  969 
## [45] {citrus fruit}                         0.08267236  813 
## [46] {pastry}                               0.08897702  875 
## [47] {pip fruit}                            0.07565589  744 
## [48] {whipped/sour cream}                   0.07169005  705 
## [49] {fruit/vegetable juice}                0.07230018  711 
## [50] {domestic eggs}                        0.06345333  624 
## [51] {newspapers}                           0.07982510  785 
## [52] {butter}                               0.05541997  545 
## [53] {margarine}                            0.05847061  575 
## [54] {brown bread}                          0.06487696  638 
## [55] {bottled beer}                         0.08053691  792 
## [56] {frankfurter}                          0.05897905  580 
## [57] {pork}                                 0.05765711  567 
## [58] {napkins}                              0.05236933  515 
## [59] {curd}                                 0.05328452  524 
## [60] {beef}                                 0.05247102  516 
## [61] {frozen vegetables}                    0.04809843  473 
## [62] {coffee}                               0.05806386  571 
## [63] {chocolate}                            0.04962375  488 
## [64] {white bread}                          0.04209884  414 
## [65] {chicken}                              0.04291234  422 
## [66] {cream cheese}                         0.03965833  390 
## [67] {canned beer}                          0.07768965  764 
## [68] {dessert}                              0.03711613  365 
## [69] {long life bakery product}             0.03742119  368 
## [70] {waffles}                              0.03843807  378 
## [71] {sugar}                                0.03386211  333 
## [72] {salty snack}                          0.03782794  372 
## [73] {hygiene articles}                     0.03294692  324 
## [74] {hamburger meat}                       0.03325198  327 
## [75] {berries}                              0.03325198  327 
## [76] {onions}                               0.03101485  305 
## [77] {oil}                                  0.02806589  276 
## [78] {UHT-milk}                             0.03345536  329 
## [79] {ham}                                  0.02603213  256 
## [80] {candy}                                0.02989628  294 
## [81] {butter milk}                          0.02796421  275 
## [82] {frozen meals}                         0.02837096  279 
## [83] {meat}                                 0.02582876  254 
## [84] {specialty chocolate}                  0.03040472  299 
## [85] {misc. beverages}                      0.02837096  279 
## [86] {specialty bar}                        0.02735408  269 
## [87] {ice cream}                            0.02501525  246 
## [88] {beverages}                            0.02603213  256
round(support(items(freq.items), trans1) , 2)
##  [1] 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03
## [16] 0.03 0.03 0.03 0.04 0.04 0.03 0.05 0.05 0.03 0.04 0.03 0.04 0.03 0.06 0.04
## [31] 0.03 0.06 0.04 0.07 0.26 0.19 0.18 0.14 0.17 0.11 0.10 0.11 0.09 0.10 0.08
## [46] 0.09 0.08 0.07 0.07 0.06 0.08 0.06 0.06 0.06 0.08 0.06 0.06 0.05 0.05 0.05
## [61] 0.05 0.06 0.05 0.04 0.04 0.04 0.08 0.04 0.04 0.04 0.03 0.04 0.03 0.03 0.03
## [76] 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03 0.03
freq.rules<-ruleInduction(freq.items, trans1, confidence=0.4) 
freq.rules
## set of 9 rules

Only assuming confidence at the 0.4 level, one can inspect the rules. This means that the strenght of the determined rules is between 100% and 40%. Let’s now look at the mined rules.

inspect(freq.rules)
##     lhs                     rhs                support    confidence lift    
## [1] {curd}               => {whole milk}       0.02613382 0.4904580  1.919285
## [2] {butter}             => {whole milk}       0.02755745 0.4972477  1.945855
## [3] {domestic eggs}      => {whole milk}       0.02999797 0.4727564  1.850015
## [4] {whipped/sour cream} => {whole milk}       0.03223510 0.4496454  1.759575
## [5] {whipped/sour cream} => {other vegetables} 0.02887940 0.4028369  2.081712
## [6] {tropical fruit}     => {whole milk}       0.04230222 0.4031008  1.577435
## [7] {root vegetables}    => {whole milk}       0.04891194 0.4486940  1.755852
## [8] {root vegetables}    => {other vegetables} 0.04738662 0.4347015  2.246376
## [9] {yogurt}             => {whole milk}       0.05603010 0.4016035  1.571575
##     itemset
## [1]  1     
## [2]  3     
## [3]  5     
## [4]  7     
## [5]  8     
## [6] 19     
## [7] 22     
## [8] 23     
## [9] 29
plot(freq.rules, method="matrix", measure=c("support","confidence"))
## Itemsets in Antecedent (LHS)
## [1] "{root vegetables}"    "{butter}"             "{whipped/sour cream}"
## [4] "{curd}"               "{domestic eggs}"      "{tropical fruit}"    
## [7] "{yogurt}"            
## Itemsets in Consequent (RHS)
## [1] "{whole milk}"       "{other vegetables}"

APRIORI

rules.trans1<-apriori(trans1, parameter=list(supp=0.005, conf=0.6))  
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.6    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 ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9834 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 ... [22 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
rules.by.conf<-sort(rules.trans1, by="confidence", decreasing=TRUE)
inspect(head(rules.by.conf))
##     lhs                     rhs              support confidence    coverage     lift count
## [1] {root vegetables,                                                                     
##      tropical fruit,                                                                      
##      yogurt}             => {whole milk} 0.005694529  0.7000000 0.008135042 2.739276    56
## [2] {other vegetables,                                                                    
##      pip fruit,                                                                           
##      root vegetables}    => {whole milk} 0.005491153  0.6750000 0.008135042 2.641444    54
## [3] {butter,                                                                              
##      whipped/sour cream} => {whole milk} 0.006711409  0.6600000 0.010168802 2.582746    66
## [4] {pip fruit,                                                                           
##      whipped/sour cream} => {whole milk} 0.005999593  0.6483516 0.009253610 2.537163    59
## [5] {butter,                                                                              
##      yogurt}             => {whole milk} 0.009355298  0.6388889 0.014643075 2.500133    92
## [6] {butter,                                                                              
##      root vegetables}    => {whole milk} 0.008236730  0.6377953 0.012914379 2.495853    81

Second part of the analysis

What makes people buy a yogurt? A yogurt is defined in the RHS, i.e. as a consequence of other purchases

Generating rules

rules.yogurt<-apriori(data=trans1, parameter=list(supp=0.001,conf = 0.08), 
                      appearance=list(default="lhs", rhs="yogurt"), control=list(verbose=F))

Sorting and displaying the rules

rules.yogurt.byconf<-sort(rules.yogurt, by="confidence", decreasing=TRUE)
inspect(head(rules.yogurt.byconf))
##     lhs                     rhs          support confidence    coverage     lift count
## [1] {butter,                                                                          
##      cream cheese,                                                                    
##      root vegetables}    => {yogurt} 0.001016880  0.9090909 0.001118568 6.516035    10
## [2] {butter,                                                                          
##      sliced cheese,                                                                   
##      tropical fruit,                                                                  
##      whole milk}         => {yogurt} 0.001016880  0.9090909 0.001118568 6.516035    10
## [3] {cream cheese,                                                                    
##      curd,                                                                            
##      other vegetables,                                                                
##      whipped/sour cream} => {yogurt} 0.001016880  0.9090909 0.001118568 6.516035    10
## [4] {butter,                                                                          
##      other vegetables,                                                                
##      tropical fruit,                                                                  
##      white bread}        => {yogurt} 0.001016880  0.9090909 0.001118568 6.516035    10
## [5] {pip fruit,                                                                       
##      sausage,                                                                         
##      sliced cheese}      => {yogurt} 0.001220256  0.8571429 0.001423632 6.143690    12
## [6] {butter,                                                                          
##      curd,                                                                            
##      tropical fruit,                                                                  
##      whole milk}         => {yogurt} 0.001220256  0.8571429 0.001423632 6.143690    12
What people will buy if they have a yogurt in their basket?

A yogurt is defined in the LHS as a developer of other purchases

rules.yogurt<-apriori(data=trans1, parameter=list(supp=0.001,conf = 0.08), 
                      appearance=list(default="rhs",lhs="yogurt"), control=list(verbose=F)) 
rules.yogurt.byconf<-sort(rules.yogurt, by="confidence", decreasing=TRUE)
inspect(head(rules.yogurt.byconf))
##     lhs         rhs                support    confidence coverage lift    
## [1] {yogurt} => {whole milk}       0.05603010 0.4016035  0.139516 1.571575
## [2] {yogurt} => {other vegetables} 0.04342079 0.3112245  0.139516 1.608293
## [3] {}       => {whole milk}       0.25554200 0.2555420  1.000000 1.000000
## [4] {yogurt} => {rolls/buns}       0.03437055 0.2463557  0.139516 1.339227
## [5] {yogurt} => {tropical fruit}   0.02928615 0.2099125  0.139516 2.000271
## [6] {yogurt} => {soda}             0.02735408 0.1960641  0.139516 1.124253
##     count
## [1]  551 
## [2]  427 
## [3] 2513 
## [4]  338 
## [5]  288 
## [6]  269
trans1.closed<-apriori(trans1, parameter=list(target="closed frequent itemsets", support=0.15))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##          NA    0.1    1 none FALSE            TRUE       5    0.15      1
##  maxlen                   target  ext
##      10 closed frequent itemsets TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 1475 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9834 transaction(s)] done [0.00s].
## sorting and recoding items ... [4 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 done [0.00s].
## filtering closed item sets ... done [0.00s].
## sorting transactions ... done [0.00s].
## writing ... [4 set(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
inspect(trans1.closed)
##     items              support   count
## [1] {soda}             0.1743950 1715 
## [2] {rolls/buns}       0.1839536 1809 
## [3] {other vegetables} 0.1935123 1903 
## [4] {whole milk}       0.2555420 2513
is.closed(trans1.closed)
##             {soda}       {rolls/buns} {other vegetables}       {whole milk} 
##               TRUE               TRUE               TRUE               TRUE
freq.closed<-eclat(trans1, parameter=list(supp=0.15, maxlen=15, target="closed frequent itemsets"))
## Eclat
## 
## parameter specification:
##  tidLists support minlen maxlen                   target  ext
##     FALSE    0.15      1     15 closed frequent itemsets TRUE
## 
## algorithmic control:
##  sparse sort verbose
##       7   -2    TRUE
## 
## Absolute minimum support count: 1475 
## 
## create itemset ... 
## set transactions ...[169 item(s), 9834 transaction(s)] done [0.01s].
## sorting and recoding items ... [4 item(s)] done [0.00s].
## creating bit matrix ... [4 row(s), 9834 column(s)] done [0.00s].
## writing  ... [4 set(s)] done [0.00s].
## Creating S4 object  ... done [0.00s].
inspect(freq.closed)
##     items              support   count
## [1] {whole milk}       0.2555420 2513 
## [2] {other vegetables} 0.1935123 1903 
## [3] {rolls/buns}       0.1839536 1809 
## [4] {soda}             0.1743950 1715
is.closed(freq.closed)
##       {whole milk} {other vegetables}       {rolls/buns}             {soda} 
##               TRUE               TRUE               TRUE               TRUE
freq.max<-eclat(trans1, parameter=list(supp=0.15, maxlen=15, target="maximally frequent itemsets"))
## Eclat
## 
## parameter specification:
##  tidLists support minlen maxlen                      target  ext
##     FALSE    0.15      1     15 maximally frequent itemsets TRUE
## 
## algorithmic control:
##  sparse sort verbose
##       7   -2    TRUE
## 
## Absolute minimum support count: 1475 
## 
## create itemset ... 
## set transactions ...[169 item(s), 9834 transaction(s)] done [0.00s].
## sorting and recoding items ... [4 item(s)] done [0.00s].
## creating bit matrix ... [4 row(s), 9834 column(s)] done [0.00s].
## writing  ... [4 set(s)] done [0.00s].
## Creating S4 object  ... done [0.00s].
inspect(freq.max)
##     items              support   count
## [1] {whole milk}       0.2555420 2513 
## [2] {other vegetables} 0.1935123 1903 
## [3] {rolls/buns}       0.1839536 1809 
## [4] {soda}             0.1743950 1715

Not clear output, soda is not more frequent than individual baskets

is.significant(rules.yogurt, trans1)    
##  [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [13]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
## [25]  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
## [37]  TRUE
is.maximal(rules.yogurt) 
##                 {bottled beer}                       {pastry} 
##                           TRUE                          FALSE 
##                 {citrus fruit}                {shopping bags} 
##                          FALSE                          FALSE 
##                      {sausage}                {bottled water} 
##                          FALSE                          FALSE 
##               {tropical fruit}              {root vegetables} 
##                          FALSE                          FALSE 
##                         {soda}                   {rolls/buns} 
##                          FALSE                          FALSE 
##             {other vegetables}                   {whole milk} 
##                          FALSE                          FALSE 
##          {cream cheese,yogurt}     {frozen vegetables,yogurt} 
##                           TRUE                           TRUE 
##                  {beef,yogurt}                  {curd,yogurt} 
##                           TRUE                           TRUE 
##               {napkins,yogurt}           {frankfurter,yogurt} 
##                           TRUE                           TRUE 
##           {brown bread,yogurt}             {margarine,yogurt} 
##                           TRUE                           TRUE 
##                {butter,yogurt}            {newspapers,yogurt} 
##                           TRUE                           TRUE 
##         {domestic eggs,yogurt} {fruit/vegetable juice,yogurt} 
##                           TRUE                           TRUE 
##    {whipped/sour cream,yogurt}             {pip fruit,yogurt} 
##                           TRUE                           TRUE 
##                {pastry,yogurt}          {citrus fruit,yogurt} 
##                           TRUE                           TRUE 
##         {shopping bags,yogurt}               {sausage,yogurt} 
##                           TRUE                           TRUE 
##         {bottled water,yogurt}        {tropical fruit,yogurt} 
##                           TRUE                           TRUE 
##       {root vegetables,yogurt}                  {soda,yogurt} 
##                           TRUE                           TRUE 
##            {rolls/buns,yogurt}      {other vegetables,yogurt} 
##                           TRUE                           TRUE 
##            {whole milk,yogurt} 
##                           TRUE
inspect(rules.yogurt[is.maximal(rules.yogurt)==TRUE]) 
##      lhs         rhs                     support    confidence coverage
## [1]  {}       => {bottled beer}          0.08053691 0.08053691 1.000000
## [2]  {yogurt} => {cream cheese}          0.01240594 0.08892128 0.139516
## [3]  {yogurt} => {frozen vegetables}     0.01240594 0.08892128 0.139516
## [4]  {yogurt} => {beef}                  0.01169412 0.08381924 0.139516
## [5]  {yogurt} => {curd}                  0.01728696 0.12390671 0.139516
## [6]  {yogurt} => {napkins}               0.01230425 0.08819242 0.139516
## [7]  {yogurt} => {frankfurter}           0.01118568 0.08017493 0.139516
## [8]  {yogurt} => {brown bread}           0.01454139 0.10422741 0.139516
## [9]  {yogurt} => {margarine}             0.01423632 0.10204082 0.139516
## [10] {yogurt} => {butter}                0.01464308 0.10495627 0.139516
## [11] {yogurt} => {newspapers}            0.01535489 0.11005831 0.139516
## [12] {yogurt} => {domestic eggs}         0.01433801 0.10276968 0.139516
## [13] {yogurt} => {fruit/vegetable juice} 0.01871060 0.13411079 0.139516
## [14] {yogurt} => {whipped/sour cream}    0.02074436 0.14868805 0.139516
## [15] {yogurt} => {pip fruit}             0.01799878 0.12900875 0.139516
## [16] {yogurt} => {pastry}                0.01769372 0.12682216 0.139516
## [17] {yogurt} => {citrus fruit}          0.02165955 0.15524781 0.139516
## [18] {yogurt} => {shopping bags}         0.01525320 0.10932945 0.139516
## [19] {yogurt} => {sausage}               0.01962579 0.14067055 0.139516
## [20] {yogurt} => {bottled water}         0.02298149 0.16472303 0.139516
## [21] {yogurt} => {tropical fruit}        0.02928615 0.20991254 0.139516
## [22] {yogurt} => {root vegetables}       0.02582876 0.18513120 0.139516
## [23] {yogurt} => {soda}                  0.02735408 0.19606414 0.139516
## [24] {yogurt} => {rolls/buns}            0.03437055 0.24635569 0.139516
## [25] {yogurt} => {other vegetables}      0.04342079 0.31122449 0.139516
## [26] {yogurt} => {whole milk}            0.05603010 0.40160350 0.139516
##      lift     count
## [1]  1.000000 792  
## [2]  2.242184 122  
## [3]  1.848736 122  
## [4]  1.597439 115  
## [5]  2.325379 170  
## [6]  1.684047 121  
## [7]  1.359380 110  
## [8]  1.606540 143  
## [9]  1.745164 140  
## [10] 1.893835 144  
## [11] 1.378743 151  
## [12] 1.619611 141  
## [13] 1.854916 184  
## [14] 2.074040 204  
## [15] 1.705204 177  
## [16] 1.425336 174  
## [17] 1.877868 213  
## [18] 1.109542 150  
## [19] 1.497137 193  
## [20] 1.490236 226  
## [21] 2.000271 288  
## [22] 1.698302 254  
## [23] 1.124253 269  
## [24] 1.339227 338  
## [25] 1.608293 427  
## [26] 1.571575 551
is.redundant(rules.yogurt)
##  [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
inspect(rules.yogurt[is.redundant(rules.yogurt)==FALSE])
##      lhs         rhs                     support    confidence coverage
## [1]  {}       => {bottled beer}          0.08053691 0.08053691 1.000000
## [2]  {}       => {pastry}                0.08897702 0.08897702 1.000000
## [3]  {}       => {citrus fruit}          0.08267236 0.08267236 1.000000
## [4]  {}       => {shopping bags}         0.09853569 0.09853569 1.000000
## [5]  {}       => {sausage}               0.09395973 0.09395973 1.000000
## [6]  {}       => {bottled water}         0.11053488 0.11053488 1.000000
## [7]  {}       => {tropical fruit}        0.10494204 0.10494204 1.000000
## [8]  {}       => {root vegetables}       0.10900956 0.10900956 1.000000
## [9]  {}       => {soda}                  0.17439496 0.17439496 1.000000
## [10] {}       => {rolls/buns}            0.18395363 0.18395363 1.000000
## [11] {}       => {other vegetables}      0.19351230 0.19351230 1.000000
## [12] {}       => {whole milk}            0.25554200 0.25554200 1.000000
## [13] {yogurt} => {cream cheese}          0.01240594 0.08892128 0.139516
## [14] {yogurt} => {frozen vegetables}     0.01240594 0.08892128 0.139516
## [15] {yogurt} => {beef}                  0.01169412 0.08381924 0.139516
## [16] {yogurt} => {curd}                  0.01728696 0.12390671 0.139516
## [17] {yogurt} => {napkins}               0.01230425 0.08819242 0.139516
## [18] {yogurt} => {frankfurter}           0.01118568 0.08017493 0.139516
## [19] {yogurt} => {brown bread}           0.01454139 0.10422741 0.139516
## [20] {yogurt} => {margarine}             0.01423632 0.10204082 0.139516
## [21] {yogurt} => {butter}                0.01464308 0.10495627 0.139516
## [22] {yogurt} => {newspapers}            0.01535489 0.11005831 0.139516
## [23] {yogurt} => {domestic eggs}         0.01433801 0.10276968 0.139516
## [24] {yogurt} => {fruit/vegetable juice} 0.01871060 0.13411079 0.139516
## [25] {yogurt} => {whipped/sour cream}    0.02074436 0.14868805 0.139516
## [26] {yogurt} => {pip fruit}             0.01799878 0.12900875 0.139516
## [27] {yogurt} => {pastry}                0.01769372 0.12682216 0.139516
## [28] {yogurt} => {citrus fruit}          0.02165955 0.15524781 0.139516
## [29] {yogurt} => {shopping bags}         0.01525320 0.10932945 0.139516
## [30] {yogurt} => {sausage}               0.01962579 0.14067055 0.139516
## [31] {yogurt} => {bottled water}         0.02298149 0.16472303 0.139516
## [32] {yogurt} => {tropical fruit}        0.02928615 0.20991254 0.139516
## [33] {yogurt} => {root vegetables}       0.02582876 0.18513120 0.139516
## [34] {yogurt} => {soda}                  0.02735408 0.19606414 0.139516
## [35] {yogurt} => {rolls/buns}            0.03437055 0.24635569 0.139516
## [36] {yogurt} => {other vegetables}      0.04342079 0.31122449 0.139516
## [37] {yogurt} => {whole milk}            0.05603010 0.40160350 0.139516
##      lift     count
## [1]  1.000000  792 
## [2]  1.000000  875 
## [3]  1.000000  813 
## [4]  1.000000  969 
## [5]  1.000000  924 
## [6]  1.000000 1087 
## [7]  1.000000 1032 
## [8]  1.000000 1072 
## [9]  1.000000 1715 
## [10] 1.000000 1809 
## [11] 1.000000 1903 
## [12] 1.000000 2513 
## [13] 2.242184  122 
## [14] 1.848736  122 
## [15] 1.597439  115 
## [16] 2.325379  170 
## [17] 1.684047  121 
## [18] 1.359380  110 
## [19] 1.606540  143 
## [20] 1.745164  140 
## [21] 1.893835  144 
## [22] 1.378743  151 
## [23] 1.619611  141 
## [24] 1.854916  184 
## [25] 2.074040  204 
## [26] 1.705204  177 
## [27] 1.425336  174 
## [28] 1.877868  213 
## [29] 1.109542  150 
## [30] 1.497137  193 
## [31] 1.490236  226 
## [32] 2.000271  288 
## [33] 1.698302  254 
## [34] 1.124253  269 
## [35] 1.339227  338 
## [36] 1.608293  427 
## [37] 1.571575  551

Conclusions

Based on the analysis of the store’s sales data, the following recommendations can be made to improve the overall strategy of the store and increase sales and profitability.

Promoting low-selling products: There are several products that are not selling well and may require more promotion to increase sales. These items include baby food, sound storage medium, preservation products, bags, kitchen utensils, and baby cosmetics. Store management can consider implementing various marketing strategies, such as discounts, special offers, or in-store displays to increase visibility and attract customers.

Deleting unselling products: Some items may not be selling well and may not be worth keeping in the store, considering the costs associated with storing them in the warehouse. Store managers should regularly assess the sales of each product and make informed decisions on whether to continue stocking them or remove them from the store.

Enhancing product placement: Product placement can play a significant role in increasing sales. In this case, store management should consider placing a booth with dairy products near sections that sell fruits, vegetables, baked goods, and sausages. This can increase visibility and attract customers looking for complementary items.

Continuously monitoring sales: Finally, it is essential to continuously monitor sales data and make informed decisions based on the results. This will allow store management to regularly assess the performance of different products and adjust their strategy accordingly.

In conclusion, implementing these recommendations can help the store improve its strategy and increase sales and profitability.