Data Preparing and exploring

library(arulesViz)
## Loading required package: arules
## Loading required package: Matrix
## 
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
## Loading required package: grid
library(arules)
library(readxl)
TransactionList <- read_excel("TransactionList.xlsx",sheet=1)
goodsinfo<-read_excel("TransactionList.xlsx",sheet=4)
# gather together
list<-aggregate(TransactionList, by=list(TransactionList$transaction_id), FUN=paste)

list1<-as.factor(list[,1])
list2<-list[,3]
fake<-list2
list2<-sapply(list2,function(x) paste(unlist(x),collapse=","))  
list2<-factor(list2)
list2<-unname(list2)

list3<-list[,4]
list3<-sapply(list3,function(x) x[1])
list3<-as.numeric(list3)
list3<-list3%%7
list3[list3==0]<-7

data<-data.frame(list1,list3)
data$Item<-list2
names(data)<-c("ID","day","Pattern")

weekdays<-subset(data,day<6,select=c(1,3))   #weekdays transactions
weekend<-subset(data,day>5,select=c(1,3))    #weekend transactions
weekdata<-data[,3]         #full transactions
rm(data,list,TransactionList,list1,list2,list3)
#tweekdays<-as(weekdata,"transactions")       #transfer data frame to transactions  # did not work


##########################################
#output data and read them as transactions
write.table(weekdays$Pattern, "weekdays.txt", sep = '\t', quote = FALSE, row.names = F)
write.table(weekend$Pattern, "weekend.txt", sep = '\t', quote = FALSE, row.names = F)
write.table(weekdata, "weekdata.txt", sep = '\t', quote = FALSE, row.names = F)
#read as transactions
weekdays<-read.transactions("weekdays.txt", format="basket", sep=",",skip = 1)
weekend<-read.transactions("weekend.txt", format="basket", sep=",", skip=1)
weekdata1<-read.transactions("weekdata.txt", format="basket", sep=",",skip=1)
str(weekdata1)
## Formal class 'transactions' [package "arules"] with 3 slots
##   ..@ data       :Formal class 'ngCMatrix' [package "Matrix"] with 5 slots
##   .. .. ..@ i       : int [1:371210] 12 18 34 43 58 42 62 69 89 5 ...
##   .. .. ..@ p       : int [1:64809] 0 5 9 15 17 23 29 31 37 40 ...
##   .. .. ..@ Dim     : int [1:2] 106 64808
##   .. .. ..@ Dimnames:List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : NULL
##   .. .. ..@ factors : list()
##   ..@ itemInfo   :'data.frame':  106 obs. of  1 variable:
##   .. ..$ labels: chr [1:106] "Acetominifen" "Anchovies" "Aspirin" "Auto Magazines" ...
##   ..@ itemsetInfo:'data.frame':  0 obs. of  0 variables
summary(weekdata1)
## transactions as itemMatrix in sparse format with
##  64808 rows (elements/itemsets/transactions) and
##  106 columns (items) and a density of 0.05403625 
## 
## most frequent items:
## Fresh Vegetables      Fresh Fruit           Cheese             Soup 
##            20001            12641             9380             8209 
##      Dried Fruit          (Other) 
##             8140           312839 
## 
## element (itemset/transaction) length distribution:
## sizes
##     1     2     3     4     5     6     7     8     9    10    11    12 
##  4489  8628  8522 10010  8344  9013  6075  2247   997  1024   999   672 
##    13    14    15    16    17    18    19    20    21    22    23    24 
##   436   249   235   226   149    96    80    94    91    77    85    91 
##    25    26    27    28    29    30    31    32    33    34    35    36 
##    92   123   162   207   226   216   174   152   124   115    79    63 
##    37    38    39    40    41    42    43    44 
##    62    28    26    14     8     6     1     1 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   3.000   5.000   5.728   6.000  44.000 
## 
## includes extended item information - examples:
##         labels
## 1 Acetominifen
## 2    Anchovies
## 3      Aspirin
# Run ariori algorithm and generate rules
rules <- apriori(weekdata1, parameter = list(support=0.006, confidence=0.3))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.3    0.1    1 none FALSE            TRUE       5   0.006      1
##  maxlen target   ext
##      10  rules FALSE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 388 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[106 item(s), 64808 transaction(s)] done [0.04s].
## sorting and recoding items ... [105 item(s)] done [0.01s].
## creating transaction tree ... done [0.05s].
## checking subsets of size 1 2 3 4 5 6 7 8 done [0.77s].
## writing ... [312983 rule(s)] done [0.08s].
## creating S4 object  ... done [0.18s].
inspect(head(rules,50))
##      lhs                     rhs                 support     confidence
## [1]  {}                   => {Fresh Vegetables}  0.308619306 0.3086193 
## [2]  {Ibuprofen}          => {Popsicles}         0.006156647 0.3020439 
## [3]  {Ibuprofen}          => {Soup}              0.006773855 0.3323240 
## [4]  {Acetominifen}       => {Soup}              0.007051599 0.3462121 
## [5]  {Acetominifen}       => {Sliced Bread}      0.006233798 0.3060606 
## [6]  {Acetominifen}       => {Juice}             0.006341810 0.3113636 
## [7]  {Pot Cleaners}       => {Fresh Vegetables}  0.008548327 0.3256908 
## [8]  {Screwdrivers}       => {Fresh Vegetables}  0.007792248 0.4208333 
## [9]  {Canned Fruit}       => {Fresh Vegetables}  0.014180348 0.4240886 
## [10] {Shellfish}          => {Pasta}             0.006064066 0.3096927 
## [11] {Shellfish}          => {Muffins}           0.006573263 0.3356974 
## [12] {Shellfish}          => {Chocolate Candy}   0.006557832 0.3349094 
## [13] {Shellfish}          => {Pizza}             0.006033206 0.3081166 
## [14] {Shellfish}          => {Deli Meats}        0.006588693 0.3364854 
## [15] {Shellfish}          => {Milk}              0.006496112 0.3317573 
## [16] {Shellfish}          => {Jam}               0.006280089 0.3207250 
## [17] {Shellfish}          => {Jelly}             0.006094927 0.3112687 
## [18] {Shellfish}          => {Frozen Chicken}    0.006341810 0.3238771 
## [19] {Shellfish}          => {Chips}             0.006249228 0.3191489 
## [20] {Shellfish}          => {Waffles}           0.006604123 0.3372734 
## [21] {Shellfish}          => {Paper Wipes}       0.006881866 0.3514578 
## [22] {Shellfish}          => {Canned Vegetables} 0.007067029 0.3609141 
## [23] {Shellfish}          => {Cereal}            0.006403530 0.3270292 
## [24] {Shellfish}          => {Sliced Bread}      0.006496112 0.3317573 
## [25] {Shellfish}          => {Juice}             0.006233798 0.3183609 
## [26] {Shellfish}          => {Cheese}            0.007375633 0.3766745 
## [27] {Shellfish}          => {Fresh Fruit}       0.008193433 0.4184397 
## [28] {Shellfish}          => {Fresh Vegetables}  0.009628441 0.4917258 
## [29] {Fresh Fish}         => {Fresh Fruit}       0.006742995 0.3741438 
## [30] {Fresh Fish}         => {Fresh Vegetables}  0.008301444 0.4606164 
## [31] {Home Magazines}     => {Cheese}            0.006357240 0.3322581 
## [32] {Home Magazines}     => {Fresh Fruit}       0.006959017 0.3637097 
## [33] {Home Magazines}     => {Fresh Vegetables}  0.009967905 0.5209677 
## [34] {Personal Hygiene}   => {Fresh Vegetables}  0.016926923 0.3269747 
## [35] {Spices}             => {Fresh Fruit}       0.014056907 0.3077703 
## [36] {Spices}             => {Fresh Vegetables}  0.019040859 0.4168919 
## [37] {Dried Meat}         => {Gum}               0.010569683 0.3728906 
## [38] {Dried Meat}         => {Beer}              0.009458709 0.3336962 
## [39] {Dried Meat}         => {Pizza}             0.011125170 0.3924878 
## [40] {Dried Meat}         => {Chips}             0.010801136 0.3810561 
## [41] {Aspirin}            => {Fresh Vegetables}  0.011850389 0.3221477 
## [42] {Computer Magazines} => {Mouthwash}         0.007036168 0.3037975 
## [43] {Computer Magazines} => {Batteries}         0.007113319 0.3071286 
## [44] {Computer Magazines} => {Cereal}            0.007483644 0.3231179 
## [45] {Computer Magazines} => {Sliced Bread}      0.007020738 0.3031312 
## [46] {Computer Magazines} => {Fresh Fruit}       0.007915689 0.3417722 
## [47] {Computer Magazines} => {Fresh Vegetables}  0.007823108 0.3377748 
## [48] {Pancakes}           => {Hot Dogs}          0.009875324 0.3695150 
## [49] {Pancakes}           => {Donuts}            0.009674732 0.3620092 
## [50] {Pancakes}           => {Bagels}            0.008301444 0.3106236 
##      lift    
## [1]  1.000000
## [2]  5.037278
## [3]  2.623615
## [4]  2.733258
## [5]  2.922525
## [6]  2.850523
## [7]  1.055316
## [8]  1.363600
## [9]  1.374148
## [10] 5.088885
## [11] 4.447236
## [12] 3.912186
## [13] 3.597266
## [14] 4.497205
## [15] 3.713390
## [16] 4.756418
## [17] 4.339149
## [18] 4.816389
## [19] 3.300368
## [20] 4.112515
## [21] 3.190095
## [22] 3.459054
## [23] 3.651638
## [24] 3.167898
## [25] 2.914583
## [26] 2.602508
## [27] 2.145261
## [28] 1.593309
## [29] 1.918164
## [30] 1.492507
## [31] 2.295627
## [32] 1.864670
## [33] 1.688059
## [34] 1.059476
## [35] 1.577880
## [36] 1.350829
## [37] 9.252026
## [38] 6.631765
## [39] 4.582300
## [40] 3.940559
## [41] 1.043835
## [42] 7.196091
## [43] 4.628928
## [44] 3.607965
## [45] 2.894553
## [46] 1.752201
## [47] 1.094471
## [48] 7.010401
## [49] 6.833992
## [50] 6.574426
plot(rules)

itemFrequencyPlot(weekdata1, topN=50, cex.names=0.6)

#1. Patterns related to beverages
beverages <- subset(rules, subset = items %in% c("Beer","Wine"))
inspect(head(sort(beverages, by ="lift"),10))
##      lhs                   rhs                 support confidence     lift
## [1]  {Fresh Vegetables,                                                   
##       Rice,                                                               
##       Sauces,                                                             
##       Wine}             => {Candles}       0.006835576  0.8601942 33.72502
## [2]  {Rice,                                                               
##       Sauces,                                                             
##       Wine}             => {Candles}       0.007082459  0.8515770 33.38718
## [3]  {Fresh Chicken,                                                      
##       Fresh Vegetables,                                                   
##       Sauces,                                                             
##       Wine}             => {Candles}       0.006758425  0.8390805 32.89723
## [4]  {Fresh Chicken,                                                      
##       Fresh Vegetables,                                                   
##       Rice,                                                               
##       Wine}             => {Candles}       0.006665844  0.8372093 32.82387
## [5]  {Fresh Fruit,                                                        
##       Fresh Vegetables,                                                   
##       Sauces,                                                             
##       Wine}             => {Candles}       0.006789285  0.8349146 32.73391
## [6]  {Fresh Chicken,                                                      
##       Sauces,                                                             
##       Wine}             => {Candles}       0.006974448  0.8293578 32.51604
## [7]  {Fresh Chicken,                                                      
##       Rice,                                                               
##       Wine}             => {Candles}       0.006851006  0.8237477 32.29609
## [8]  {Fresh Chicken,                                                      
##       Fresh Fruit,                                                        
##       Fresh Vegetables,                                                   
##       Wine}             => {Candles}       0.006742995  0.8214286 32.20517
## [9]  {Fresh Fruit,                                                        
##       Sauces,                                                             
##       Wine}             => {Candles}       0.006974448  0.8188406 32.10370
## [10] {Fresh Vegetables,                                                   
##       Rice,                                                               
##       Sauces,                                                             
##       Wine}             => {Fresh Chicken} 0.006573263  0.8271845 31.73959
plot(beverages)

itemFrequencyPlot(items(beverages), topN=30, cex.names=1)

plot(head(sort(beverages, by="lift"), 30),
     method="graph", control=list(cex=.9))

1. Customer do not tend to buy beer and wine together. 2. Both beer and wine are closely related to food. 3. Beer is more popular while it is usually bought together with food that can be quickly eat. 4. Wine is usually matched with raw cooking materials such as rice, oil, chicken, which a forma meal is needed.

#2 Patterns related to Canned&Fresh goods 
can.fresh <- subset(rules, subset = items %in% c("Canned Vegetables","Canned Fruit","Fresh Fruit","Fresh Vegetables","Fresh Fish","Fresh Chicken"))
inspect(head(sort(can.fresh, by ="lift"),10))
##      lhs                   rhs                   support confidence     lift
## [1]  {Fresh Fruit,                                                          
##       Shower Soap}      => {Dishwasher Soap} 0.006110357  0.6407767 42.72372
## [2]  {Dishwasher Soap,                                                      
##       Fresh Fruit}      => {Shower Soap}     0.006110357  0.6295707 42.36887
## [3]  {Fresh Chicken,                                                        
##       Fresh Vegetables,                                                     
##       Rice,                                                                 
##       Sauces}           => {Candles}         0.006804715  0.8630137 33.83557
## [4]  {Fresh Vegetables,                                                     
##       Rice,                                                                 
##       Sauces,                                                               
##       Wine}             => {Candles}         0.006835576  0.8601942 33.72502
## [5]  {Fresh Chicken,                                                        
##       Rice,                                                                 
##       Sauces}           => {Candles}         0.007036168  0.8555347 33.54234
## [6]  {Fresh Fruit,                                                          
##       Fresh Vegetables,                                                     
##       Rice,                                                                 
##       Sauces}           => {Candles}         0.006835576  0.8486590 33.27277
## [7]  {Fresh Vegetables,                                                     
##       Rice,                                                                 
##       Sauces}           => {Candles}         0.008193433  0.8401899 32.94073
## [8]  {Fresh Chicken,                                                        
##       Fresh Vegetables,                                                     
##       Sauces,                                                               
##       Wine}             => {Candles}         0.006758425  0.8390805 32.89723
## [9]  {Fresh Chicken,                                                        
##       Fresh Vegetables,                                                     
##       Rice,                                                                 
##       Wine}             => {Candles}         0.006665844  0.8372093 32.82387
## [10] {Fresh Chicken,                                                        
##       Fresh Fruit,                                                          
##       Fresh Vegetables,                                                     
##       Sauces}           => {Candles}         0.006820146  0.8371212 32.82042
plot(can.fresh)

itemFrequencyPlot(items(can.fresh), topN=30, cex.names=1)

plot(head(sort(can.fresh, by="lift"), 30),
     method="graph", control=list(cex=.9))

1. Customers who buy canned goods will also buy fresh good as Complementary, but customers who buy fresh goods mainly are not willing to buy canned goods. 2. Customer who buy canned goods are more willing to buy good that can be eat directly, such chips, pancake mix, peanut butter, etc. 3. Customer who buy fresh goods are more willing to buy raw material, cooking stuffs, such as cooking oil, rice, pots and pans, etc.

#3 Patterns related to Small&Large Transcations
small<-subset(rules,subset=size(rules)<6)
big<-subset(rules,subset=size(rules)>=6)
inspect(head(sort(small, by ="lift"),10))
##      lhs                                 rhs               support    
## [1]  {Dishwasher Soap,Frozen Chicken} => {Shower Soap}     0.006573263
## [2]  {Cleaners,Dishwasher Soap}       => {Shower Soap}     0.006465251
## [3]  {Frozen Chicken,Shower Soap}     => {Dishwasher Soap} 0.006573263
## [4]  {Batteries,Shower Soap}          => {Dishwasher Soap} 0.006449821
## [5]  {Shampoo,Shower Soap}            => {Dishwasher Soap} 0.006341810
## [6]  {Shower Soap,Sliced Bread}       => {Dishwasher Soap} 0.006604123
## [7]  {Dishwasher Soap,Sliced Bread}   => {Shower Soap}     0.006604123
## [8]  {Batteries,Dishwasher Soap}      => {Shower Soap}     0.006449821
## [9]  {Pancake Mix,Shower Soap}        => {Dishwasher Soap} 0.006172078
## [10] {Cereal,Dishwasher Soap}         => {Shower Soap}     0.006295519
##      confidence lift    
## [1]  0.6729858  45.29062
## [2]  0.6693291  45.04453
## [3]  0.6656250  44.38048
## [4]  0.6634921  44.23827
## [5]  0.6629032  44.19900
## [6]  0.6584615  43.90286
## [7]  0.6514460  43.84103
## [8]  0.6510903  43.81710
## [9]  0.6568144  43.79304
## [10] 0.6486486  43.65277
inspect(head(sort(big, by ="lift"),10))
##      lhs                    rhs          support confidence     lift
## [1]  {Cheese,                                                       
##       Chips,                                                        
##       Jam,                                                          
##       Peanut Butter,                                                
##       Sour Cream}        => {Shrimp} 0.006187508  0.8736383 28.72590
## [2]  {Cheese,                                                       
##       Jam,                                                          
##       Peanut Butter,                                                
##       Sour Cream,                                                   
##       Waffles}           => {Shrimp} 0.006141217  0.8728070 28.69857
## [3]  {Cheese,                                                       
##       Jam,                                                          
##       Jelly,                                                        
##       Peanut Butter,                                                
##       Sour Cream}        => {Shrimp} 0.006172078  0.8714597 28.65427
## [4]  {Canned Vegetables,                                            
##       Cheese,                                                       
##       Jam,                                                          
##       Peanut Butter,                                                
##       Sour Cream}        => {Shrimp} 0.006033206  0.8708241 28.63337
## [5]  {Cheese,                                                       
##       Jam,                                                          
##       Peanut Butter,                                                
##       Sliced Bread,                                                 
##       Sour Cream}        => {Shrimp} 0.006141217  0.8671024 28.51100
## [6]  {Cheese,                                                       
##       Chips,                                                        
##       Jam,                                                          
##       Peanut Butter,                                                
##       Waffles}           => {Shrimp} 0.006218368  0.8666667 28.49667
## [7]  {Cheese,                                                       
##       Jam,                                                          
##       Milk,                                                         
##       Peanut Butter,                                                
##       Sour Cream}        => {Shrimp} 0.006187508  0.8660907 28.47773
## [8]  {Cheese,                                                       
##       Jam,                                                          
##       Jelly,                                                        
##       Peanut Butter,                                                
##       Waffles}           => {Shrimp} 0.006079496  0.8659341 28.47258
## [9]  {Cheese,                                                       
##       Chips,                                                        
##       Jelly,                                                        
##       Milk,                                                         
##       Rice}              => {Shrimp} 0.006079496  0.8659341 28.47258
## [10] {Cheese,                                                       
##       Chips,                                                        
##       Jam,                                                          
##       Rice,                                                         
##       Waffles}           => {Shrimp} 0.006079496  0.8659341 28.47258
plot(small)

plot(big)

itemFrequencyPlot(items(small), topN=30, cex.names=1)

itemFrequencyPlot(items(big), topN=30, cex.names=1)

plot(head(sort(small, by="lift"), 30),
     method="graph", control=list(cex=.9))

plot(head(sort(big, by="lift"), 30),
     method="graph", control=list(cex=.9))

1. Small transactions often contain easily used-up and easily deteriorated goods with several patterns. These transactions are more likely generated by a walk in customer without a shopping list. 2. Large transactions not only contain the pattern of small transaction, but also contain goods that can be used for a long time.

#Weekdays VS Weekend Patterns

rules1 <- apriori(weekdays, parameter = list(support=0.005, confidence=0.5))   #weekday
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.5    0.1    1 none FALSE            TRUE       5   0.005      1
##  maxlen target   ext
##      10  rules FALSE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 227 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[105 item(s), 45404 transaction(s)] done [0.04s].
## sorting and recoding items ... [105 item(s)] done [0.01s].
## creating transaction tree ... done [0.05s].
## checking subsets of size 1 2 3 4 5 6 done [0.17s].
## writing ... [8467 rule(s)] done [0.01s].
## creating S4 object  ... done [0.01s].
rules2 <- apriori(weekend, parameter = list(support=0.01, confidence=0.5))   #weekend
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.5    0.1    1 none FALSE            TRUE       5    0.01      1
##  maxlen target   ext
##      10  rules FALSE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 194 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[106 item(s), 19404 transaction(s)] done [0.02s].
## sorting and recoding items ... [105 item(s)] done [0.02s].
## creating transaction tree ... done [0.02s].
## checking subsets of size 1 2 3 4 5 6
## Warning in apriori(weekend, parameter = list(support = 0.01, confidence =
## 0.5)): Mining stopped (time limit reached). Only patterns up to a length of
## 6 returned!
##  done [9.99s].
## writing ... [9962392 rule(s)] done [24.38s].
## creating S4 object  ... done [20.12s].
itemFrequencyPlot(weekdays, topN=20, cex.names=0.8)

itemFrequencyPlot(weekend, topN=20, cex.names=0.8)

inspect(head(sort(rules1, by ="lift"),50))
##      lhs                    rhs                   support confidence     lift
## [1]  {Bagels,                                                                
##       Yogurt}            => {Dishwasher Soap} 0.005197780  0.6961652 45.48012
## [2]  {Conditioner,                                                           
##       Yogurt}            => {Dishwasher Soap} 0.005462074  0.6908078 45.13013
## [3]  {Batteries,                                                             
##       Juice,                                                                 
##       Mouthwash}         => {Dishwasher Soap} 0.005065633  0.6906907 45.12247
## [4]  {Deodorizers,                                                           
##       Tools}             => {Dishwasher Soap} 0.005153731  0.6902655 45.09470
## [5]  {Conditioner,                                                           
##       Tofu}              => {Dishwasher Soap} 0.005043608  0.6876877 44.92629
## [6]  {Pancake Mix,                                                           
##       Tools}             => {Dishwasher Soap} 0.005241829  0.6839080 44.67937
## [7]  {Conditioner,                                                           
##       Frozen Chicken}    => {Dishwasher Soap} 0.005351951  0.6825843 44.59289
## [8]  {Conditioner,                                                           
##       Pancake Mix}       => {Dishwasher Soap} 0.005065633  0.6824926 44.58690
## [9]  {Fresh Vegetables,                                                      
##       Shower Soap}       => {Dishwasher Soap} 0.005682319  0.6789474 44.35529
## [10] {Ice Cream,                                                             
##       Sponges}           => {Dishwasher Soap} 0.005021584  0.6785714 44.33073
## [11] {Bagels,                                                                
##       Tools}             => {Dishwasher Soap} 0.005021584  0.6785714 44.33073
## [12] {Ice Cream,                                                             
##       Tofu}              => {Dishwasher Soap} 0.005065633  0.6784661 44.32385
## [13] {Conditioner,                                                           
##       Fashion Magazines} => {Shower Soap}     0.005131706  0.6695402 43.93035
## [14] {Deodorizers,                                                           
##       Yogurt}            => {Dishwasher Soap} 0.005043608  0.6715543 43.87230
## [15] {Conditioner,                                                           
##       Deodorizers}       => {Shower Soap}     0.005197780  0.6685552 43.86573
## [16] {Conditioner,                                                           
##       Deodorizers}       => {Dishwasher Soap} 0.005219804  0.6713881 43.86145
## [17] {Juice,                                                                 
##       Mouthwash,                                                             
##       Preserves}         => {Dishwasher Soap} 0.005021584  0.6705882 43.80919
## [18] {Fashion Magazines,                                                     
##       Tools}             => {Dishwasher Soap} 0.005087657  0.6695652 43.74236
## [19] {Conditioner,                                                           
##       Fashion Magazines} => {Dishwasher Soap} 0.005131706  0.6695402 43.74073
## [20] {Deodorizers,                                                           
##       Fashion Magazines} => {Shower Soap}     0.005131706  0.6619318 43.43114
## [21] {Cottage Cheese,                                                        
##       Tools}             => {Dishwasher Soap} 0.005109682  0.6647564 43.42820
## [22] {Fashion Magazines,                                                     
##       Mouthwash}         => {Dishwasher Soap} 0.005396000  0.6639566 43.37595
## [23] {Cleaners,                                                              
##       Dishwasher Soap}   => {Shower Soap}     0.006431151  0.6606335 43.34596
## [24] {Mouthwash,                                                             
##       Yogurt}            => {Dishwasher Soap} 0.005506123  0.6631300 43.32195
## [25] {Dishwasher Soap,                                                       
##       Frozen Chicken}    => {Shower Soap}     0.006585323  0.6585903 43.21190
## [26] {Conditioner,                                                           
##       Tools}             => {Dishwasher Soap} 0.005175755  0.6601124 43.12481
## [27] {Cottage Cheese,                                                        
##       Fashion Magazines} => {Shower Soap}     0.005087657  0.6562500 43.05835
## [28] {Bagels,                                                                
##       Deodorizers}       => {Shower Soap}     0.006937715  0.6562500 43.05835
## [29] {Cottage Cheese,                                                        
##       Fashion Magazines} => {Dishwasher Soap} 0.005109682  0.6590909 43.05808
## [30] {Dishwasher Soap,                                                       
##       Fresh Vegetables}  => {Shower Soap}     0.005682319  0.6548223 42.96467
## [31] {Conditioner,                                                           
##       Frozen Chicken}    => {Shower Soap}     0.005131706  0.6544944 42.94315
## [32] {Cleaners,                                                              
##       Conditioner}       => {Dishwasher Soap} 0.005065633  0.6571429 42.93081
## [33] {Bagels,                                                                
##       Ice Cream}         => {Dishwasher Soap} 0.005263853  0.6565934 42.89492
## [34] {Juice,                                                                 
##       Tofu}              => {Dishwasher Soap} 0.005131706  0.6544944 42.75779
## [35] {Fashion Magazines,                                                     
##       Pancake Mix}       => {Dishwasher Soap} 0.005087657  0.6543909 42.75103
## [36] {Fashion Magazines,                                                     
##       Pancake Mix}       => {Shower Soap}     0.005065633  0.6515581 42.75050
## [37] {Deodorizers,                                                           
##       Fashion Magazines} => {Dishwasher Soap} 0.005065633  0.6534091 42.68689
## [38] {Fashion Magazines,                                                     
##       Mouthwash}         => {Shower Soap}     0.005285878  0.6504065 42.67494
## [39] {Frozen Chicken,                                                        
##       Shower Soap}       => {Dishwasher Soap} 0.006585323  0.6528384 42.64961
## [40] {Batteries,                                                             
##       Tofu}              => {Dishwasher Soap} 0.005087657  0.6525424 42.63026
## [41] {Cleaners,                                                              
##       Deodorizers}       => {Shower Soap}     0.006761519  0.6490486 42.58584
## [42] {Deodorizers,                                                           
##       Dishwasher Soap}   => {Shower Soap}     0.006585323  0.6485900 42.55575
## [43] {Fashion Magazines,                                                     
##       Shampoo}           => {Dishwasher Soap} 0.005263853  0.6512262 42.54428
## [44] {Conditioner,                                                           
##       Shampoo}           => {Dishwasher Soap} 0.005263853  0.6512262 42.54428
## [45] {Juice,                                                                 
##       Shower Soap}       => {Dishwasher Soap} 0.006673421  0.6502146 42.47819
## [46] {Pancake Mix,                                                           
##       Yogurt}            => {Dishwasher Soap} 0.005153731  0.6500000 42.46417
## [47] {Batteries,                                                             
##       Shower Soap}       => {Dishwasher Soap} 0.006541274  0.6498906 42.45703
## [48] {Dishwasher Soap,                                                       
##       Preserves}         => {Shower Soap}     0.006254956  0.6469248 42.44650
## [49] {Bagels,                                                                
##       Dishwasher Soap}   => {Shower Soap}     0.006387102  0.6458797 42.37792
## [50] {Ice Cream,                                                             
##       Tools}             => {Dishwasher Soap} 0.005263853  0.6476965 42.31368
inspect(head(sort(rules2, by ="lift"),50))
##      lhs                    rhs                  support confidence     lift
## [1]  {Beer,                                                                 
##       Cheese,                                                               
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Waffles}           => {Dehydrated Soup} 0.01020408  0.9209302 41.36512
## [2]  {Frozen Chicken,                                                       
##       Rice,                                                                 
##       Sardines,                                                             
##       Soda,                                                                 
##       Tuna}              => {Dehydrated Soup} 0.01015255  0.9205607 41.34852
## [3]  {Cheese,                                                               
##       Cottage Cheese,                                                       
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Waffles}           => {Dehydrated Soup} 0.01015255  0.9205607 41.34852
## [4]  {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Oysters,                                                              
##       Sliced Bread,                                                         
##       Soda}              => {Dehydrated Soup} 0.01010101  0.9201878 41.33177
## [5]  {Cheese,                                                               
##       Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Soda}              => {Dehydrated Soup} 0.01041022  0.9181818 41.24167
## [6]  {Beer,                                                                 
##       Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Sliced Bread,                                                         
##       Soda}              => {Dehydrated Soup} 0.01035869  0.9178082 41.22489
## [7]  {Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Sardines,                                                             
##       Soda,                                                                 
##       Tuna}              => {Dehydrated Soup} 0.01030715  0.9174312 41.20795
## [8]  {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Soda,                                                                 
##       Waffles}           => {Dehydrated Soup} 0.01138940  0.9170124 41.18914
## [9]  {Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Sardines,                                                             
##       Soda,                                                                 
##       Waffles}           => {Dehydrated Soup} 0.01020408  0.9166667 41.17361
## [10] {Cottage Cheese,                                                       
##       Eggs,                                                                 
##       Frozen Chicken,                                                       
##       Oysters,                                                              
##       Soda}              => {Dehydrated Soup} 0.01020408  0.9166667 41.17361
## [11] {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Sliced Bread,                                                         
##       Soda}              => {Dehydrated Soup} 0.01015255  0.9162791 41.15620
## [12] {Cereal,                                                               
##       Cheese,                                                               
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Tuna}              => {Dehydrated Soup} 0.01061637  0.9155556 41.12370
## [13] {Sardines,                                                             
##       Sliced Bread,                                                         
##       Soda,                                                                 
##       Sugar,                                                                
##       Waffles}           => {Dehydrated Soup} 0.01004947  0.9154930 41.12089
## [14] {Beer,                                                                 
##       Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Sardines,                                                             
##       Soda}              => {Dehydrated Soup} 0.01004947  0.9154930 41.12089
## [15] {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Peanut Butter}     => {Dehydrated Soup} 0.01004947  0.9154930 41.12089
## [16] {Cheese,                                                               
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Waffles}           => {Dehydrated Soup} 0.01004947  0.9154930 41.12089
## [17] {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Soda}              => {Dehydrated Soup} 0.01164708  0.9149798 41.09784
## [18] {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Oysters,                                                              
##       Soda}              => {Dehydrated Soup} 0.01159555  0.9146341 41.08232
## [19] {Cereal,                                                               
##       Cheese,                                                               
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Waffles}           => {Dehydrated Soup} 0.01046176  0.9144144 41.07245
## [20] {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Jelly,                                                                
##       Oysters,                                                              
##       Soda}              => {Dehydrated Soup} 0.01041022  0.9140271 41.05505
## [21] {Beer,                                                                 
##       Frozen Chicken,                                                       
##       Rice,                                                                 
##       Sardines,                                                             
##       Soda}              => {Dehydrated Soup} 0.01025562  0.9128440 41.00191
## [22] {Cheese,                                                               
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Tuna}              => {Dehydrated Soup} 0.01025562  0.9128440 41.00191
## [23] {Cottage Cheese,                                                       
##       Eggs,                                                                 
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Soda}              => {Dehydrated Soup} 0.01025562  0.9128440 41.00191
## [24] {Cheese,                                                               
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Sardines,                                                             
##       Waffles}           => {Dehydrated Soup} 0.01020408  0.9124424 40.98387
## [25] {Frozen Chicken,                                                       
##       Sardines,                                                             
##       Soda,                                                                 
##       Sponges,                                                              
##       Tuna}              => {Dehydrated Soup} 0.01015255  0.9120370 40.96566
## [26] {Frozen Chicken,                                                       
##       Sardines,                                                             
##       Soda,                                                                 
##       Sour Cream,                                                           
##       Waffles}           => {Dehydrated Soup} 0.01015255  0.9120370 40.96566
## [27] {Cheese,                                                               
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Tuna,                                                                 
##       Waffles}           => {Dehydrated Soup} 0.01015255  0.9120370 40.96566
## [28] {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Pancake Mix,                                                          
##       Soda}              => {Dehydrated Soup} 0.01015255  0.9120370 40.96566
## [29] {Frozen Chicken,                                                       
##       Jelly,                                                                
##       Sliced Bread,                                                         
##       Soda,                                                                 
##       Waffles}           => {Dehydrated Soup} 0.01015255  0.9120370 40.96566
## [30] {Cereal,                                                               
##       Sardines,                                                             
##       Soda,                                                                 
##       Sugar,                                                                
##       Tuna}              => {Dehydrated Soup} 0.01010101  0.9116279 40.94729
## [31] {Bologna,                                                              
##       Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Soda}              => {Dehydrated Soup} 0.01010101  0.9116279 40.94729
## [32] {Beer,                                                                 
##       Bologna,                                                              
##       Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Soda}              => {Dehydrated Soup} 0.01010101  0.9116279 40.94729
## [33] {Cottage Cheese,                                                       
##       Flavored Drinks,                                                      
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Soda}              => {Dehydrated Soup} 0.01010101  0.9116279 40.94729
## [34] {Cheese,                                                               
##       Cottage Cheese,                                                       
##       Frozen Vegetables,                                                    
##       Jam,                                                                  
##       Waffles}           => {Dehydrated Soup} 0.01010101  0.9116279 40.94729
## [35] {Cheese,                                                               
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Rice,                                                                 
##       Waffles}           => {Dehydrated Soup} 0.01010101  0.9116279 40.94729
## [36] {Cheese,                                                               
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Sliced Bread,                                                         
##       Waffles}           => {Dehydrated Soup} 0.01010101  0.9116279 40.94729
## [37] {Jam,                                                                  
##       Sardines,                                                             
##       Soda,                                                                 
##       Sugar,                                                                
##       Waffles}           => {Dehydrated Soup} 0.01004947  0.9112150 40.92874
## [38] {Cereal,                                                               
##       Sardines,                                                             
##       Soda,                                                                 
##       Sugar,                                                                
##       Waffles}           => {Dehydrated Soup} 0.01004947  0.9112150 40.92874
## [39] {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Sardines,                                                             
##       Soda,                                                                 
##       Tuna}              => {Dehydrated Soup} 0.01004947  0.9112150 40.92874
## [40] {Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Sardines,                                                             
##       Soda}              => {Dehydrated Soup} 0.01004947  0.9112150 40.92874
## [41] {Beer,                                                                 
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Soda,                                                                 
##       Waffles}           => {Dehydrated Soup} 0.01004947  0.9112150 40.92874
## [42] {Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Sliced Bread,                                                         
##       Soda,                                                                 
##       Waffles}           => {Dehydrated Soup} 0.01004947  0.9112150 40.92874
## [43] {Cheese,                                                               
##       Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Frozen Vegetables,                                                    
##       Peanut Butter}     => {Dehydrated Soup} 0.01004947  0.9112150 40.92874
## [44] {Cottage Cheese,                                                       
##       Eggs,                                                                 
##       Flavored Drinks,                                                      
##       Frozen Chicken,                                                       
##       Waffles}           => {Dehydrated Soup} 0.01004947  0.9112150 40.92874
## [45] {Beer,                                                                 
##       Cheese,                                                               
##       Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Soda}              => {Dehydrated Soup} 0.01004947  0.9112150 40.92874
## [46] {Cheese,                                                               
##       Cottage Cheese,                                                       
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Peanut Butter}     => {Dehydrated Soup} 0.01056483  0.9111111 40.92407
## [47] {Beer,                                                                 
##       Cottage Cheese,                                                       
##       Frozen Chicken,                                                       
##       Soda}              => {Dehydrated Soup} 0.01159555  0.9109312 40.91599
## [48] {Cereal,                                                               
##       Jam,                                                                  
##       Sardines,                                                             
##       Soda,                                                                 
##       Tuna}              => {Dehydrated Soup} 0.01051330  0.9107143 40.90625
## [49] {Frozen Chicken,                                                       
##       Jelly,                                                                
##       Sardines,                                                             
##       Soda,                                                                 
##       Waffles}           => {Dehydrated Soup} 0.01051330  0.9107143 40.90625
## [50] {Cereal,                                                               
##       Cheese,                                                               
##       Frozen Vegetables,                                                    
##       Juice,                                                                
##       Peanut Butter}     => {Dehydrated Soup} 0.01102865  0.9106383 40.90284
plot(rules1)

plot(rules2)

itemFrequencyPlot(items(rules1), topN=30, cex.names=1)

itemFrequencyPlot(items(rules2), topN=30, cex.names=1)

plot(head(sort(rules1, by="lift"), 30),
     method="graph", control=list(cex=.9))

plot(head(sort(rules2, by="lift"), 30),
     method="graph", control=list(cex=.9))

1. Weekdays VS Weekend transactions are similar to the small VS large transactions. 2. Customer are more willing to make a shopping list on weekend and buy everything they need in their life. 3. In weekdays, customer just make randomly purchases, which made the transactions support low.

#5 Other Intereting pattern
all<-subset(rules, subset = items %pin% "Magazines")
goformagazine <- subset(rules, subset = rhs %pin% "Magazines")
goforother<- subset(rules, subset = lhs %pin% "Magazines")
inspect(head(goformagazine,50))
##      lhs                   rhs                     support confidence     lift
## [1]  {Tofu}             => {Fashion Magazines} 0.007082459  0.3072289 13.21227
## [2]  {Shower Soap}      => {Fashion Magazines} 0.007236761  0.4870197 20.94411
## [3]  {Dishwasher Soap}  => {Fashion Magazines} 0.007252191  0.4835391 20.79443
## [4]  {Shower Soap}      => {Sports Magazines}  0.006480681  0.4361371 18.27096
## [5]  {Dishwasher Soap}  => {Sports Magazines}  0.006326379  0.4218107 17.67079
## [6]  {Shower Soap}      => {Auto Magazines}    0.006465251  0.4350987 18.93746
## [7]  {Dishwasher Soap}  => {Auto Magazines}    0.006526972  0.4351852 18.94122
## [8]  {Conditioner,                                                            
##       Fresh Vegetables} => {Fashion Magazines} 0.006002345  0.3050980 13.12063
## [9]  {Fresh Vegetables,                                                       
##       Mouthwash}        => {Fashion Magazines} 0.006064066  0.3679775 15.82474
## [10] {Cleaners,                                                               
##       Fresh Vegetables} => {Fashion Magazines} 0.006125787  0.3155803 13.57142
inspect(head(goforother,50))
##      lhs                     rhs                 support     confidence
## [1]  {Home Magazines}     => {Cheese}            0.006357240 0.3322581 
## [2]  {Home Magazines}     => {Fresh Fruit}       0.006959017 0.3637097 
## [3]  {Home Magazines}     => {Fresh Vegetables}  0.009967905 0.5209677 
## [4]  {Computer Magazines} => {Mouthwash}         0.007036168 0.3037975 
## [5]  {Computer Magazines} => {Batteries}         0.007113319 0.3071286 
## [6]  {Computer Magazines} => {Cereal}            0.007483644 0.3231179 
## [7]  {Computer Magazines} => {Sliced Bread}      0.007020738 0.3031312 
## [8]  {Computer Magazines} => {Fresh Fruit}       0.007915689 0.3417722 
## [9]  {Computer Magazines} => {Fresh Vegetables}  0.007823108 0.3377748 
## [10] {Fashion Magazines}  => {Tofu}              0.007082459 0.3045786 
## [11] {Fashion Magazines}  => {Shower Soap}       0.007236761 0.3112143 
## [12] {Fashion Magazines}  => {Dishwasher Soap}   0.007252191 0.3118779 
## [13] {Fashion Magazines}  => {Tools}             0.007421923 0.3191772 
## [14] {Fashion Magazines}  => {Conditioner}       0.007375633 0.3171865 
## [15] {Fashion Magazines}  => {Mouthwash}         0.007653376 0.3291307 
## [16] {Fashion Magazines}  => {Lightbulbs}        0.008008271 0.3443928 
## [17] {Fashion Magazines}  => {Cleaners}          0.007900259 0.3397478 
## [18] {Fashion Magazines}  => {Yogurt}            0.007236761 0.3112143 
## [19] {Fashion Magazines}  => {Batteries}         0.008193433 0.3523557 
## [20] {Fashion Magazines}  => {Ice Cream}         0.008286014 0.3563371 
## [21] {Fashion Magazines}  => {Preserves}         0.008147142 0.3503650 
## [22] {Fashion Magazines}  => {Shampoo}           0.008023701 0.3450564 
## [23] {Fashion Magazines}  => {Bagels}            0.007144180 0.3072329 
## [24] {Fashion Magazines}  => {Deli Meats}        0.007514504 0.3231586 
## [25] {Fashion Magazines}  => {Deodorizers}       0.007637946 0.3284672 
## [26] {Fashion Magazines}  => {Cottage Cheese}    0.007653376 0.3291307 
## [27] {Fashion Magazines}  => {Frozen Chicken}    0.007977410 0.3430657 
## [28] {Fashion Magazines}  => {Pancake Mix}       0.007360202 0.3165229 
## [29] {Fashion Magazines}  => {Cereal}            0.008286014 0.3563371 
## [30] {Fashion Magazines}  => {Sliced Bread}      0.008718059 0.3749171 
## [31] {Fashion Magazines}  => {Juice}             0.008409456 0.3616457 
## [32] {Fashion Magazines}  => {Fresh Fruit}       0.010168498 0.4372926 
## [33] {Fashion Magazines}  => {Fresh Vegetables}  0.012745340 0.5481088 
## [34] {Sports Magazines}   => {TV Dinner}         0.007221331 0.3025210 
## [35] {Sports Magazines}   => {Cleaners}          0.007452784 0.3122172 
## [36] {Sports Magazines}   => {Beer}              0.007391063 0.3096315 
## [37] {Sports Magazines}   => {Preserves}         0.007576225 0.3173885 
## [38] {Sports Magazines}   => {Eggs}              0.007298482 0.3057531 
## [39] {Sports Magazines}   => {Waffles}           0.008054561 0.3374273 
## [40] {Sports Magazines}   => {Canned Vegetables} 0.008054561 0.3374273 
## [41] {Sports Magazines}   => {Sliced Bread}      0.007329342 0.3070459 
## [42] {Sports Magazines}   => {Juice}             0.007329342 0.3070459 
## [43] {Sports Magazines}   => {Cheese}            0.008069991 0.3380737 
## [44] {Sports Magazines}   => {Fresh Fruit}       0.009690162 0.4059470 
## [45] {Sports Magazines}   => {Fresh Vegetables}  0.009335267 0.3910795 
## [46] {Auto Magazines}     => {TV Dinner}         0.007298482 0.3176629 
## [47] {Auto Magazines}     => {Gum}               0.007175040 0.3122901 
## [48] {Auto Magazines}     => {Cleaners}          0.006897297 0.3002015 
## [49] {Auto Magazines}     => {Batteries}         0.007005308 0.3049026 
## [50] {Auto Magazines}     => {Beer}              0.007252191 0.3156481 
##      lift     
## [1]   2.295627
## [2]   1.864670
## [3]   1.688059
## [4]   7.196091
## [5]   4.628928
## [6]   3.607965
## [7]   2.894553
## [8]   1.752201
## [9]   1.094471
## [10] 13.212270
## [11] 20.944111
## [12] 20.794427
## [13]  8.862568
## [14] 10.557894
## [15]  7.796164
## [16]  5.334467
## [17]  6.369216
## [18]  6.647719
## [19]  5.310574
## [20]  5.822868
## [21]  4.499892
## [22]  5.675740
## [23]  6.502662
## [24]  4.319089
## [25]  7.925279
## [26]  5.938281
## [27]  5.101744
## [28]  5.870983
## [29]  3.978893
## [30]  3.580024
## [31]  3.310853
## [32]  2.241916
## [33]  1.776003
## [34]  6.051167
## [35]  5.853102
## [36]  6.153512
## [37]  4.076360
## [38]  3.374531
## [39]  4.114391
## [40]  3.233953
## [41]  2.931933
## [42]  2.810995
## [43]  2.335808
## [44]  2.081213
## [45]  1.267191
## [46]  6.354042
## [47]  7.748430
## [48]  5.627844
## [49]  4.595379
## [50]  6.273082
inspect(head(all,50))
##      lhs                     rhs                 support     confidence
## [1]  {Home Magazines}     => {Cheese}            0.006357240 0.3322581 
## [2]  {Home Magazines}     => {Fresh Fruit}       0.006959017 0.3637097 
## [3]  {Home Magazines}     => {Fresh Vegetables}  0.009967905 0.5209677 
## [4]  {Computer Magazines} => {Mouthwash}         0.007036168 0.3037975 
## [5]  {Computer Magazines} => {Batteries}         0.007113319 0.3071286 
## [6]  {Computer Magazines} => {Cereal}            0.007483644 0.3231179 
## [7]  {Computer Magazines} => {Sliced Bread}      0.007020738 0.3031312 
## [8]  {Computer Magazines} => {Fresh Fruit}       0.007915689 0.3417722 
## [9]  {Computer Magazines} => {Fresh Vegetables}  0.007823108 0.3377748 
## [10] {Tofu}               => {Fashion Magazines} 0.007082459 0.3072289 
## [11] {Fashion Magazines}  => {Tofu}              0.007082459 0.3045786 
## [12] {Fashion Magazines}  => {Shower Soap}       0.007236761 0.3112143 
## [13] {Shower Soap}        => {Fashion Magazines} 0.007236761 0.4870197 
## [14] {Fashion Magazines}  => {Dishwasher Soap}   0.007252191 0.3118779 
## [15] {Dishwasher Soap}    => {Fashion Magazines} 0.007252191 0.4835391 
## [16] {Fashion Magazines}  => {Tools}             0.007421923 0.3191772 
## [17] {Fashion Magazines}  => {Conditioner}       0.007375633 0.3171865 
## [18] {Fashion Magazines}  => {Mouthwash}         0.007653376 0.3291307 
## [19] {Fashion Magazines}  => {Lightbulbs}        0.008008271 0.3443928 
## [20] {Fashion Magazines}  => {Cleaners}          0.007900259 0.3397478 
## [21] {Fashion Magazines}  => {Yogurt}            0.007236761 0.3112143 
## [22] {Fashion Magazines}  => {Batteries}         0.008193433 0.3523557 
## [23] {Fashion Magazines}  => {Ice Cream}         0.008286014 0.3563371 
## [24] {Fashion Magazines}  => {Preserves}         0.008147142 0.3503650 
## [25] {Fashion Magazines}  => {Shampoo}           0.008023701 0.3450564 
## [26] {Fashion Magazines}  => {Bagels}            0.007144180 0.3072329 
## [27] {Fashion Magazines}  => {Deli Meats}        0.007514504 0.3231586 
## [28] {Fashion Magazines}  => {Deodorizers}       0.007637946 0.3284672 
## [29] {Fashion Magazines}  => {Cottage Cheese}    0.007653376 0.3291307 
## [30] {Fashion Magazines}  => {Frozen Chicken}    0.007977410 0.3430657 
## [31] {Fashion Magazines}  => {Pancake Mix}       0.007360202 0.3165229 
## [32] {Fashion Magazines}  => {Cereal}            0.008286014 0.3563371 
## [33] {Fashion Magazines}  => {Sliced Bread}      0.008718059 0.3749171 
## [34] {Fashion Magazines}  => {Juice}             0.008409456 0.3616457 
## [35] {Fashion Magazines}  => {Fresh Fruit}       0.010168498 0.4372926 
## [36] {Fashion Magazines}  => {Fresh Vegetables}  0.012745340 0.5481088 
## [37] {Shower Soap}        => {Sports Magazines}  0.006480681 0.4361371 
## [38] {Dishwasher Soap}    => {Sports Magazines}  0.006326379 0.4218107 
## [39] {Sports Magazines}   => {TV Dinner}         0.007221331 0.3025210 
## [40] {Sports Magazines}   => {Cleaners}          0.007452784 0.3122172 
## [41] {Sports Magazines}   => {Beer}              0.007391063 0.3096315 
## [42] {Sports Magazines}   => {Preserves}         0.007576225 0.3173885 
## [43] {Sports Magazines}   => {Eggs}              0.007298482 0.3057531 
## [44] {Sports Magazines}   => {Waffles}           0.008054561 0.3374273 
## [45] {Sports Magazines}   => {Canned Vegetables} 0.008054561 0.3374273 
## [46] {Sports Magazines}   => {Sliced Bread}      0.007329342 0.3070459 
## [47] {Sports Magazines}   => {Juice}             0.007329342 0.3070459 
## [48] {Sports Magazines}   => {Cheese}            0.008069991 0.3380737 
## [49] {Sports Magazines}   => {Fresh Fruit}       0.009690162 0.4059470 
## [50] {Sports Magazines}   => {Fresh Vegetables}  0.009335267 0.3910795 
##      lift     
## [1]   2.295627
## [2]   1.864670
## [3]   1.688059
## [4]   7.196091
## [5]   4.628928
## [6]   3.607965
## [7]   2.894553
## [8]   1.752201
## [9]   1.094471
## [10] 13.212270
## [11] 13.212270
## [12] 20.944111
## [13] 20.944111
## [14] 20.794427
## [15] 20.794427
## [16]  8.862568
## [17] 10.557894
## [18]  7.796164
## [19]  5.334467
## [20]  6.369216
## [21]  6.647719
## [22]  5.310574
## [23]  5.822868
## [24]  4.499892
## [25]  5.675740
## [26]  6.502662
## [27]  4.319089
## [28]  7.925279
## [29]  5.938281
## [30]  5.101744
## [31]  5.870983
## [32]  3.978893
## [33]  3.580024
## [34]  3.310853
## [35]  2.241916
## [36]  1.776003
## [37] 18.270958
## [38] 17.670787
## [39]  6.051167
## [40]  5.853102
## [41]  6.153512
## [42]  4.076360
## [43]  3.374531
## [44]  4.114391
## [45]  3.233953
## [46]  2.931933
## [47]  2.810995
## [48]  2.335808
## [49]  2.081213
## [50]  1.267191
itemFrequencyPlot(items(goforother), topN=30, cex.names=1)

inspect(head(sort(goforother, by ="lift"),10))
##      lhs                    rhs                   support confidence      lift
## [1]  {Fashion Magazines} => {Shower Soap}     0.007236761  0.3112143 20.944111
## [2]  {Fashion Magazines} => {Dishwasher Soap} 0.007252191  0.3118779 20.794427
## [3]  {Fashion Magazines,                                                      
##       Fresh Vegetables}  => {Conditioner}     0.006002345  0.4709443 15.675891
## [4]  {Fashion Magazines} => {Tofu}            0.007082459  0.3045786 13.212270
## [5]  {Fashion Magazines,                                                      
##       Fresh Vegetables}  => {Deodorizers}     0.006202938  0.4866828 11.742718
## [6]  {Fashion Magazines,                                                      
##       Fresh Vegetables}  => {Mouthwash}       0.006064066  0.4757869 11.270029
## [7]  {Fashion Magazines} => {Conditioner}     0.007375633  0.3171865 10.557894
## [8]  {Fashion Magazines,                                                      
##       Fresh Vegetables}  => {Cleaners}        0.006125787  0.4806295  9.010309
## [9]  {Fashion Magazines} => {Tools}           0.007421923  0.3191772  8.862568
## [10] {Fashion Magazines,                                                      
##       Fresh Vegetables}  => {Cottage Cheese}  0.006048636  0.4745763  8.562455
plot(goforother)

plot(head(sort(goforother, by="lift"), 30),
     method="graph", control=list(cex=.7))

1. Fashion magazine is closely related to daily used goods with very high frequency. This can be explained that house women likes to buy fashion magazine when they supplement their house refrigerator. Fashion magazine appears both rhs and lhs, which means they are in the shopping list. 2. Unlike fashion magazine, other kinds of magazines are not in the shopping list. The purchases are more likely happened when a man go to buy some goods their wife asked on their way back to home after work. He just sees the magazine somewhere in the market and take it.

# Output for SPMF
id<-fake
price<-fake
total<-list()
DB_utility<-list()

for (i in 1:length(fake)) {
  id[[i]]<-factor(id[[i]], levels=goodsinfo$name, labels=goodsinfo$product_id)
  price[[i]]<-factor(price[[i]], levels=goodsinfo$name, labels=goodsinfo$profit)
  price[[i]]<-as.integer(as.numeric(as.character(price[[i]]))*100)
  id[[i]]<-as.integer(as.numeric(as.character(id[[i]])))}

id <- lapply(id,function(x) replace(x,is.na(x),0))
price <- lapply(price,function(x) replace(x,is.na(x),0))

for (i in 1:length(fake)) {total[[i]]<-sum(price[[i]])}

id<-sapply(id,function(x) paste(unlist(x),collapse=" "))
price<-sapply(price,function(x) paste(unlist(x),collapse=" "))

DB_utility<-paste(id,total,price,sep=":",collapse = NULL)
head(DB_utility)
## [1] "11 90 109 61 76:642:144 133 130 131 104"        
## [2] "99 1 53 19:483:129 126 116 112"                 
## [3] "101 45 106 99 60 27:814:154 141 128 129 134 128"
## [4] "11 46:281:144 137"                              
## [5] "99 74 110 98 103 27:696:129 110 107 100 122 128"
## [6] "90 45 99 61 100 28:786:133 141 129 131 144 108"
write.table(DB_utility, "DB_utility.txt", sep = '\t', quote = FALSE,  row.names=FALSE, na="")