Por que utilizar Regras de Associação?

Permite encontrar padrões em grande bancos de dados e com isso, nos permite gerar recomendaçãoes personalizadas

Adicionar a principal biblioteca = Arules

Carregar a base da dados

data("Groceries")

Visualizar a base

inspect(Groceries[1:5])
##     items                     
## [1] {citrus fruit,            
##      semi-finished bread,     
##      margarine,               
##      ready soups}             
## [2] {tropical fruit,          
##      yogurt,                  
##      coffee}                  
## [3] {whole milk}              
## [4] {pip fruit,               
##      yogurt,                  
##      cream cheese ,           
##      meat spreads}            
## [5] {other vegetables,        
##      whole milk,              
##      condensed milk,          
##      long life bakery product}

Análise descritiva para sumarizar os produtos

summary(Groceries)
## transactions as itemMatrix in sparse format with
##  9835 rows (elements/itemsets/transactions) and
##  169 columns (items) and a density of 0.02609146 
## 
## most frequent items:
##       whole milk other vegetables       rolls/buns             soda 
##             2513             1903             1809             1715 
##           yogurt          (Other) 
##             1372            34055 
## 
## element (itemset/transaction) length distribution:
## sizes
##    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
## 2159 1643 1299 1005  855  645  545  438  350  246  182  117   78   77   55   46 
##   17   18   19   20   21   22   23   24   26   27   28   29   32 
##   29   14   14    9   11    4    6    1    1    1    1    3    1 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   2.000   3.000   4.409   6.000  32.000 
## 
## includes extended item information - examples:
##        labels  level2           level1
## 1 frankfurter sausage meat and sausage
## 2     sausage sausage meat and sausage
## 3  liver loaf sausage meat and sausage

Visualizar a frequencia de forma gráfica

itemFrequencyPlot(Groceries, topN=20)

itemFrequencyPlot(Groceries, topN=20, type="absolute")

Função “apriori” no R

1) Suporte da regra: Indica a frequencia com que os itens ocorrem juntos no mesmo conjunto de dados

Suporte = Contagem da regra / Total de transações

2) Confiança da regra: Indica a probalidade de encontrar de forma conjunta 2 ou mais itens (ex. fruta, iogurte), dados que ocorreu a priori a compra de um item (ex. fruta)

Confiança = Suporte (dois itens ou mais) / Suporte (item comprado a priori)

3) Lift: Avalia a dependência e força entre as regras (Quanto maior o lift maior a força da regra)

lift = confiança / suporte

Se lift = 1, então são independentes

Se lift > 1, então são dependentes

Se lift > 1, então são dependentes

Criar as primeiras regras

regra1 <- apriori(Groceries,parameter = list(supp=0.001,conf=0.8))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.8    0.1    1 none FALSE            TRUE       5   0.001      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: 9 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [157 item(s)] done [0.01s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 5 6 done [0.04s].
## writing ... [410 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
summary(regra1)
## set of 410 rules
## 
## rule length distribution (lhs + rhs):sizes
##   3   4   5   6 
##  29 229 140  12 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.000   4.000   4.000   4.329   5.000   6.000 
## 
## summary of quality measures:
##     support           confidence        coverage             lift       
##  Min.   :0.001017   Min.   :0.8000   Min.   :0.001017   Min.   : 3.131  
##  1st Qu.:0.001017   1st Qu.:0.8333   1st Qu.:0.001220   1st Qu.: 3.312  
##  Median :0.001220   Median :0.8462   Median :0.001322   Median : 3.588  
##  Mean   :0.001247   Mean   :0.8663   Mean   :0.001449   Mean   : 3.951  
##  3rd Qu.:0.001322   3rd Qu.:0.9091   3rd Qu.:0.001627   3rd Qu.: 4.341  
##  Max.   :0.003152   Max.   :1.0000   Max.   :0.003559   Max.   :11.235  
##      count      
##  Min.   :10.00  
##  1st Qu.:10.00  
##  Median :12.00  
##  Mean   :12.27  
##  3rd Qu.:13.00  
##  Max.   :31.00  
## 
## mining info:
##       data ntransactions support confidence
##  Groceries          9835   0.001        0.8

Visualizar os itens da regra1

inspect(regra1[1:5])
##     lhs                        rhs            support     confidence
## [1] {liquor,red/blush wine} => {bottled beer} 0.001931876 0.9047619 
## [2] {curd,cereals}          => {whole milk}   0.001016777 0.9090909 
## [3] {yogurt,cereals}        => {whole milk}   0.001728521 0.8095238 
## [4] {butter,jam}            => {whole milk}   0.001016777 0.8333333 
## [5] {soups,bottled beer}    => {whole milk}   0.001118454 0.9166667 
##     coverage    lift      count
## [1] 0.002135231 11.235269 19   
## [2] 0.001118454  3.557863 10   
## [3] 0.002135231  3.168192 17   
## [4] 0.001220132  3.261374 10   
## [5] 0.001220132  3.587512 11

Criar uma regra2 (limitando a quantidade de itens dentro da regras)

regra2 <- apriori(Groceries,parameter = list(supp=0.002,conf=0.8, minlen=4, maxlen=6))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.8    0.1    1 none FALSE            TRUE       5   0.002      4
##  maxlen target  ext
##       6  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 19 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [147 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 5 done [0.02s].
## writing ... [8 rule(s)] done [0.00s].
## creating S4 object  ... done [0.01s].

Sumarizando a regra2

summary(regra2)
## set of 8 rules
## 
## rule length distribution (lhs + rhs):sizes
## 4 5 
## 3 5 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   4.000   4.000   5.000   4.625   5.000   5.000 
## 
## summary of quality measures:
##     support           confidence        coverage             lift      
##  Min.   :0.002034   Min.   :0.8000   Min.   :0.002440   Min.   :3.189  
##  1st Qu.:0.002034   1st Qu.:0.8111   1st Qu.:0.002542   1st Qu.:3.221  
##  Median :0.002237   Median :0.8225   Median :0.002694   Median :3.286  
##  Mean   :0.002364   Mean   :0.8281   Mean   :0.002847   Mean   :3.631  
##  3rd Qu.:0.002466   3rd Qu.:0.8365   3rd Qu.:0.002999   3rd Qu.:4.135  
##  Max.   :0.003152   Max.   :0.8857   Max.   :0.003559   Max.   :4.578  
##      count      
##  Min.   :20.00  
##  1st Qu.:20.00  
##  Median :22.00  
##  Mean   :23.25  
##  3rd Qu.:24.25  
##  Max.   :31.00  
## 
## mining info:
##       data ntransactions support confidence
##  Groceries          9835   0.002        0.8

Inspecionar a regra2

inspect(regra2)
##     lhs                        rhs                    support confidence    coverage     lift count
## [1] {tropical fruit,                                                                               
##      grapes,                                                                                       
##      whole milk}            => {other vegetables} 0.002033554  0.8000000 0.002541942 4.134524    20
## [2] {other vegetables,                                                                             
##      curd,                                                                                         
##      domestic eggs}         => {whole milk}       0.002846975  0.8235294 0.003457041 3.223005    28
## [3] {pork,                                                                                         
##      other vegetables,                                                                             
##      butter}                => {whole milk}       0.002236909  0.8461538 0.002643620 3.311549    22
## [4] {root vegetables,                                                                              
##      other vegetables,                                                                             
##      yogurt,                                                                                       
##      fruit/vegetable juice} => {whole milk}       0.002033554  0.8333333 0.002440264 3.261374    20
## [5] {root vegetables,                                                                              
##      whole milk,                                                                                   
##      yogurt,                                                                                       
##      fruit/vegetable juice} => {other vegetables} 0.002033554  0.8000000 0.002541942 4.134524    20
## [6] {citrus fruit,                                                                                 
##      tropical fruit,                                                                               
##      root vegetables,                                                                              
##      whole milk}            => {other vegetables} 0.003152008  0.8857143 0.003558719 4.577509    31
## [7] {citrus fruit,                                                                                 
##      root vegetables,                                                                              
##      other vegetables,                                                                             
##      yogurt}                => {whole milk}       0.002338587  0.8214286 0.002846975 3.214783    23
## [8] {tropical fruit,                                                                               
##      root vegetables,                                                                              
##      yogurt,                                                                                       
##      rolls/buns}            => {whole milk}       0.002236909  0.8148148 0.002745297 3.188899    22

Ordenar pelos maiores lifts

inspect(sort(regra2,by="lift"))
##     lhs                        rhs                    support confidence    coverage     lift count
## [1] {citrus fruit,                                                                                 
##      tropical fruit,                                                                               
##      root vegetables,                                                                              
##      whole milk}            => {other vegetables} 0.003152008  0.8857143 0.003558719 4.577509    31
## [2] {tropical fruit,                                                                               
##      grapes,                                                                                       
##      whole milk}            => {other vegetables} 0.002033554  0.8000000 0.002541942 4.134524    20
## [3] {root vegetables,                                                                              
##      whole milk,                                                                                   
##      yogurt,                                                                                       
##      fruit/vegetable juice} => {other vegetables} 0.002033554  0.8000000 0.002541942 4.134524    20
## [4] {pork,                                                                                         
##      other vegetables,                                                                             
##      butter}                => {whole milk}       0.002236909  0.8461538 0.002643620 3.311549    22
## [5] {root vegetables,                                                                              
##      other vegetables,                                                                             
##      yogurt,                                                                                       
##      fruit/vegetable juice} => {whole milk}       0.002033554  0.8333333 0.002440264 3.261374    20
## [6] {other vegetables,                                                                             
##      curd,                                                                                         
##      domestic eggs}         => {whole milk}       0.002846975  0.8235294 0.003457041 3.223005    28
## [7] {citrus fruit,                                                                                 
##      root vegetables,                                                                              
##      other vegetables,                                                                             
##      yogurt}                => {whole milk}       0.002338587  0.8214286 0.002846975 3.214783    23
## [8] {tropical fruit,                                                                               
##      root vegetables,                                                                              
##      yogurt,                                                                                       
##      rolls/buns}            => {whole milk}       0.002236909  0.8148148 0.002745297 3.188899    22

Exercício

regra_1 <- apriori(Groceries, parameter = list(supp=0.05, conf=0.30))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.3    0.1    1 none FALSE            TRUE       5    0.05      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: 491 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [28 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 done [0.00s].
## writing ... [3 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
summary(regra_1)
## set of 3 rules
## 
## rule length distribution (lhs + rhs):sizes
## 2 
## 3 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       2       2       2       2       2       2 
## 
## summary of quality measures:
##     support          confidence        coverage           lift      
##  Min.   :0.05602   Min.   :0.3079   Min.   :0.1395   Min.   :1.205  
##  1st Qu.:0.05633   1st Qu.:0.3473   1st Qu.:0.1617   1st Qu.:1.359  
##  Median :0.05663   Median :0.3868   Median :0.1839   Median :1.514  
##  Mean   :0.06250   Mean   :0.3654   Mean   :0.1723   Mean   :1.430  
##  3rd Qu.:0.06573   3rd Qu.:0.3942   3rd Qu.:0.1887   3rd Qu.:1.543  
##  Max.   :0.07483   Max.   :0.4016   Max.   :0.1935   Max.   :1.572  
##      count      
##  Min.   :551.0  
##  1st Qu.:554.0  
##  Median :557.0  
##  Mean   :614.7  
##  3rd Qu.:646.5  
##  Max.   :736.0  
## 
## mining info:
##       data ntransactions support confidence
##  Groceries          9835    0.05        0.3
inspect(regra_1)
##     lhs                   rhs          support    confidence coverage  lift    
## [1] {yogurt}           => {whole milk} 0.05602440 0.4016035  0.1395018 1.571735
## [2] {rolls/buns}       => {whole milk} 0.05663447 0.3079049  0.1839349 1.205032
## [3] {other vegetables} => {whole milk} 0.07483477 0.3867578  0.1934926 1.513634
##     count
## [1] 551  
## [2] 557  
## [3] 736

Encontrando subconjuntos de interesse: Posso está interessado em determinado item e posso selecionar somente as regras que vão levar a determinado item

regra3 <- apriori(Groceries, parameter = list(supp= 0.002, conf=0.70, minlen=2))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.7    0.1    1 none FALSE            TRUE       5   0.002      2
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 19 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [147 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 5 done [0.02s].
## writing ... [94 rule(s)] done [0.00s].
## creating S4 object  ... done [0.01s].
summary(regra3)
## set of 94 rules
## 
## rule length distribution (lhs + rhs):sizes
##  3  4  5 
## 22 59 13 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.000   4.000   4.000   3.904   4.000   5.000 
## 
## summary of quality measures:
##     support           confidence        coverage             lift      
##  Min.   :0.002034   Min.   :0.7000   Min.   :0.002440   Min.   :2.740  
##  1st Qu.:0.002135   1st Qu.:0.7143   1st Qu.:0.002847   1st Qu.:2.816  
##  Median :0.002389   Median :0.7353   Median :0.003152   Median :2.978  
##  Mean   :0.002613   Mean   :0.7472   Mean   :0.003513   Mean   :3.165  
##  3rd Qu.:0.002745   3rd Qu.:0.7714   3rd Qu.:0.003660   3rd Qu.:3.541  
##  Max.   :0.005694   Max.   :0.8857   Max.   :0.008134   Max.   :4.578  
##      count     
##  Min.   :20.0  
##  1st Qu.:21.0  
##  Median :23.5  
##  Mean   :25.7  
##  3rd Qu.:27.0  
##  Max.   :56.0  
## 
## mining info:
##       data ntransactions support confidence
##  Groceries          9835   0.002        0.7
inspect(sort(regra3 [1:20], decreasing = TRUE, by="lift"))
##      lhs                                   rhs                support    
## [1]  {whipped/sour cream,soft cheese}   => {other vegetables} 0.002236909
## [2]  {root vegetables,soft cheese}      => {other vegetables} 0.002440264
## [3]  {citrus fruit,herbs}               => {other vegetables} 0.002135231
## [4]  {root vegetables,baking powder}    => {other vegetables} 0.002541942
## [5]  {root vegetables,rice}             => {other vegetables} 0.002236909
## [6]  {tropical fruit,herbs}             => {whole milk}       0.002338587
## [7]  {hamburger meat,curd}              => {whole milk}       0.002541942
## [8]  {herbs,rolls/buns}                 => {whole milk}       0.002440264
## [9]  {root vegetables,rice}             => {whole milk}       0.002440264
## [10] {butter milk,whipped/sour cream}   => {whole milk}       0.002948653
## [11] {onions,butter}                    => {whole milk}       0.003050330
## [12] {butter,soft cheese}               => {whole milk}       0.002033554
## [13] {cream cheese ,sugar}              => {whole milk}       0.002033554
## [14] {butter,curd}                      => {whole milk}       0.004880529
## [15] {yogurt,specialty cheese}          => {whole milk}       0.002033554
## [16] {dessert,butter milk}              => {whole milk}       0.002033554
## [17] {domestic eggs,sugar}              => {whole milk}       0.003558719
## [18] {yogurt,baking powder}             => {whole milk}       0.003253686
## [19] {whipped/sour cream,sliced cheese} => {whole milk}       0.002745297
## [20] {butter,coffee}                    => {whole milk}       0.003355363
##      confidence coverage    lift     count
## [1]  0.7333333  0.003050330 3.789981 22   
## [2]  0.7272727  0.003355363 3.758659 24   
## [3]  0.7241379  0.002948653 3.742457 21   
## [4]  0.7142857  0.003558719 3.691540 25   
## [5]  0.7096774  0.003152008 3.667723 22   
## [6]  0.8214286  0.002846975 3.214783 23   
## [7]  0.8064516  0.003152008 3.156169 25   
## [8]  0.8000000  0.003050330 3.130919 24   
## [9]  0.7741935  0.003152008 3.029922 24   
## [10] 0.7631579  0.003863752 2.986732 29   
## [11] 0.7500000  0.004067107 2.935237 30   
## [12] 0.7407407  0.002745297 2.898999 20   
## [13] 0.7407407  0.002745297 2.898999 20   
## [14] 0.7164179  0.006812405 2.803808 48   
## [15] 0.7142857  0.002846975 2.795464 20   
## [16] 0.7142857  0.002846975 2.795464 20   
## [17] 0.7142857  0.004982206 2.795464 35   
## [18] 0.7111111  0.004575496 2.783039 32   
## [19] 0.7105263  0.003863752 2.780751 27   
## [20] 0.7021277  0.004778851 2.747881 33

Selecionar somente as regras que aparecem beef

regra_beef <- subset(regra3, items %in% "beef")

inspect(regra_beef)
##     lhs                   rhs                    support confidence    coverage     lift count
## [1] {beef,                                                                                    
##      other vegetables,                                                                        
##      domestic eggs}    => {whole milk}       0.002541942  0.7575758 0.003355363 2.964886    25
## [2] {beef,                                                                                    
##      tropical fruit,                                                                          
##      root vegetables}  => {other vegetables} 0.002745297  0.7297297 0.003762074 3.771357    27
## [3] {beef,                                                                                    
##      tropical fruit,                                                                          
##      rolls/buns}       => {whole milk}       0.002135231  0.7777778 0.002745297 3.043949    21

Encontrando regras de segmentação

Segmentação 1: O que os clientes compram antes de compras um determinado produto(beef)?

regra3_seg1 <- apriori(Groceries, parameter = list(supp= 0.002, conf=0.2),
                       appearance = list(default = "lhs", rhs="beef") )
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.2    0.1    1 none FALSE            TRUE       5   0.002      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: 19 
## 
## set item appearances ...[1 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [147 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 5 done [0.01s].
## writing ... [16 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
summary(regra3_seg1)
## set of 16 rules
## 
## rule length distribution (lhs + rhs):sizes
##  3  4 
##  6 10 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.000   3.000   4.000   3.625   4.000   4.000 
## 
## summary of quality measures:
##     support           confidence        coverage             lift      
##  Min.   :0.002034   Min.   :0.2015   Min.   :0.008236   Min.   :3.840  
##  1st Qu.:0.002313   1st Qu.:0.2106   1st Qu.:0.010320   1st Qu.:4.013  
##  Median :0.002745   Median :0.2236   Median :0.012252   Median :4.261  
##  Mean   :0.002847   Mean   :0.2237   Mean   :0.012894   Mean   :4.263  
##  3rd Qu.:0.002872   3rd Qu.:0.2347   3rd Qu.:0.013091   3rd Qu.:4.474  
##  Max.   :0.004982   Max.   :0.2469   Max.   :0.024301   Max.   :4.706  
##      count      
##  Min.   :20.00  
##  1st Qu.:22.75  
##  Median :27.00  
##  Mean   :28.00  
##  3rd Qu.:28.25  
##  Max.   :49.00  
## 
## mining info:
##       data ntransactions support confidence
##  Groceries          9835   0.002        0.2
inspect(regra3_seg1)
##      lhs                   rhs        support confidence    coverage     lift count
## [1]  {pork,                                                                        
##       root vegetables}  => {beef} 0.002745297  0.2014925 0.013624809 3.840463    27
## [2]  {root vegetables,                                                             
##       butter}           => {beef} 0.002948653  0.2283465 0.012913066 4.352301    29
## [3]  {root vegetables,                                                             
##       newspapers}       => {beef} 0.002745297  0.2389381 0.011489578 4.554178    27
## [4]  {citrus fruit,                                                                
##       root vegetables}  => {beef} 0.003863752  0.2183908 0.017691917 4.162546    38
## [5]  {root vegetables,                                                             
##       soda}             => {beef} 0.003965430  0.2131148 0.018607016 4.061984    39
## [6]  {root vegetables,                                                             
##       rolls/buns}       => {beef} 0.004982206  0.2050209 0.024300966 3.907715    49
## [7]  {pork,                                                                        
##       other vegetables,                                                            
##       whole milk}       => {beef} 0.002338587  0.2300000 0.010167768 4.383818    23
## [8]  {root vegetables,                                                             
##       whole milk,                                                                  
##       butter}           => {beef} 0.002033554  0.2469136 0.008235892 4.706192    20
## [9]  {other vegetables,                                                            
##       whole milk,                                                                  
##       domestic eggs}    => {beef} 0.002541942  0.2066116 0.012302999 3.938033    25
## [10] {citrus fruit,                                                                
##       root vegetables,                                                             
##       other vegetables} => {beef} 0.002135231  0.2058824 0.010371124 3.924134    21
## [11] {citrus fruit,                                                                
##       root vegetables,                                                             
##       whole milk}       => {beef} 0.002236909  0.2444444 0.009150991 4.659130    22
## [12] {tropical fruit,                                                              
##       root vegetables,                                                             
##       other vegetables} => {beef} 0.002745297  0.2231405 0.012302999 4.253075    27
## [13] {tropical fruit,                                                              
##       root vegetables,                                                             
##       whole milk}       => {beef} 0.002541942  0.2118644 0.011997966 4.038152    25
## [14] {root vegetables,                                                             
##       other vegetables,                                                            
##       soda}             => {beef} 0.002033554  0.2469136 0.008235892 4.706192    20
## [15] {root vegetables,                                                             
##       other vegetables,                                                            
##       rolls/buns}       => {beef} 0.002846975  0.2333333 0.012201322 4.447351    28
## [16] {root vegetables,                                                             
##       whole milk,                                                                  
##       rolls/buns}       => {beef} 0.002846975  0.2240000 0.012709710 4.269457    28

Segmentação 2: O que os clientes compram depois de compram um determinado produto (beef)?

regra3_seg2 <- apriori(Groceries, parameter = list(supp= 0.002, conf=0.2),
                       appearance = list(default = "rhs", lhs="beef"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.2    0.1    1 none FALSE            TRUE       5   0.002      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: 19 
## 
## set item appearances ...[1 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [147 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 done [0.00s].
## writing ... [6 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
summary(regra3_seg2)
## set of 6 rules
## 
## rule length distribution (lhs + rhs):sizes
## 1 2 
## 1 5 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   2.000   2.000   1.833   2.000   2.000 
## 
## summary of quality measures:
##     support          confidence        coverage            lift      
##  Min.   :0.01169   Min.   :0.2229   Min.   :0.05247   Min.   :1.000  
##  1st Qu.:0.01457   1st Qu.:0.2566   1st Qu.:0.05247   1st Qu.:1.455  
##  Median :0.01856   Median :0.2955   Median :0.05247   Median :1.591  
##  Mean   :0.05653   Mean   :0.3084   Mean   :0.21039   Mean   :1.763  
##  3rd Qu.:0.02087   3rd Qu.:0.3648   3rd Qu.:0.05247   3rd Qu.:1.857  
##  Max.   :0.25552   Max.   :0.4050   Max.   :1.00000   Max.   :3.040  
##      count       
##  Min.   : 115.0  
##  1st Qu.: 143.2  
##  Median : 182.5  
##  Mean   : 556.0  
##  3rd Qu.: 205.2  
##  Max.   :2513.0  
## 
## mining info:
##       data ntransactions support confidence
##  Groceries          9835   0.002        0.2
inspect(regra3_seg2)
##     lhs       rhs                support    confidence coverage   lift    
## [1] {}     => {whole milk}       0.25551601 0.2555160  1.00000000 1.000000
## [2] {beef} => {root vegetables}  0.01738688 0.3313953  0.05246568 3.040367
## [3] {beef} => {yogurt}           0.01169293 0.2228682  0.05246568 1.597601
## [4] {beef} => {rolls/buns}       0.01362481 0.2596899  0.05246568 1.411858
## [5] {beef} => {other vegetables} 0.01972547 0.3759690  0.05246568 1.943066
## [6] {beef} => {whole milk}       0.02125064 0.4050388  0.05246568 1.585180
##     count
## [1] 2513 
## [2]  171 
## [3]  115 
## [4]  134 
## [5]  194 
## [6]  209

Exercício: A rede varejista Vende Tudo, irá fazer uma liquidação de pipoca, deseja encontrar itens relacionados à pipoca para serem impulsionados juntamente com a pipoca. Você precisa encontrar regras relevantes, ou seja, com maiores lifts que contenham pipoca. Qual o comando que utilizamos para encontrar os maiores lifts e que contenham o item pipoca, dentre as regras geradas?

regra  <- apriori( Groceries, parameter = list(sup = 0.002, conf = 0.3))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.3    0.1    1 none FALSE            TRUE       5   0.002      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: 19 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [147 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 done [0.04s].
## writing ... [3119 rule(s)] done [0.00s].
## creating S4 object  ... done [0.01s].
regra_pipoca <- subset(regra, items %in% "popcorn")

summary(regra_pipoca)
## set of 2 rules
## 
## rule length distribution (lhs + rhs):sizes
## 2 
## 2 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       2       2       2       2       2       2 
## 
## summary of quality measures:
##     support           confidence        coverage             lift      
##  Min.   :0.002237   Min.   :0.3099   Min.   :0.007219   Min.   :1.433  
##  1st Qu.:0.002339   1st Qu.:0.3239   1st Qu.:0.007219   1st Qu.:3.123  
##  Median :0.002440   Median :0.3380   Median :0.007219   Median :4.813  
##  Mean   :0.002440   Mean   :0.3380   Mean   :0.007219   Mean   :4.813  
##  3rd Qu.:0.002542   3rd Qu.:0.3521   3rd Qu.:0.007219   3rd Qu.:6.502  
##  Max.   :0.002644   Max.   :0.3662   Max.   :0.007219   Max.   :8.192  
##      count   
##  Min.   :22  
##  1st Qu.:23  
##  Median :24  
##  Mean   :24  
##  3rd Qu.:25  
##  Max.   :26  
## 
## mining info:
##       data ntransactions support confidence
##  Groceries          9835   0.002        0.3
inspect(regra_pipoca)
##     lhs          rhs           support     confidence coverage    lift    
## [1] {popcorn} => {salty snack} 0.002236909 0.3098592  0.007219115 8.192110
## [2] {popcorn} => {whole milk}  0.002643620 0.3661972  0.007219115 1.433167
##     count
## [1] 22   
## [2] 26
inspect(sort(regra_pipoca, by="lift"))
##     lhs          rhs           support     confidence coverage    lift    
## [1] {popcorn} => {salty snack} 0.002236909 0.3098592  0.007219115 8.192110
## [2] {popcorn} => {whole milk}  0.002643620 0.3661972  0.007219115 1.433167
##     count
## [1] 22   
## [2] 26

Exercicio: A rede varejista Vende Tudo, tem o interesse de fazer uma promoção, oferecendo refrigerante com desconto, para quem comprar determinados produtos.Você deve por meio da análise de regras de associação determinar uma lista de produtos mais relacionados com refrigerante. Você deve descobrir quais itens que os clientes compram junto com refrigerante, ou seja, que produtos são comprados antes de refrigerante?

regra_refri1 <- apriori(Groceries, parameter = list(supp= 0.002, conf=0.08),
                       appearance = list(default = "lhs", rhs = "soda"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##        0.08    0.1    1 none FALSE            TRUE       5   0.002      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: 19 
## 
## set item appearances ...[1 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [147 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 done [0.01s].
## writing ... [408 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
summary(regra_refri1)
## set of 408 rules
## 
## rule length distribution (lhs + rhs):sizes
##   1   2   3   4 
##   1  89 271  47 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   3.000   3.000   2.892   3.000   4.000 
## 
## summary of quality measures:
##     support           confidence        coverage             lift       
##  Min.   :0.002034   Min.   :0.1107   Min.   :0.003965   Min.   :0.6348  
##  1st Qu.:0.002339   1st Qu.:0.1944   1st Qu.:0.009049   1st Qu.:1.1151  
##  Median :0.002949   Median :0.2381   Median :0.012862   Median :1.3654  
##  Mean   :0.004931   Mean   :0.2484   Mean   :0.022966   Mean   :1.4247  
##  3rd Qu.:0.004601   3rd Qu.:0.2876   3rd Qu.:0.021352   3rd Qu.:1.6494  
##  Max.   :0.174377   Max.   :0.5128   Max.   :1.000000   Max.   :2.9409  
##      count        
##  Min.   :  20.00  
##  1st Qu.:  23.00  
##  Median :  29.00  
##  Mean   :  48.50  
##  3rd Qu.:  45.25  
##  Max.   :1715.00  
## 
## mining info:
##       data ntransactions support confidence
##  Groceries          9835   0.002       0.08
inspect(regra_refri1 [1:20])
##      lhs                            rhs    support     confidence coverage   
## [1]  {}                          => {soda} 0.174377224 0.1743772  1.000000000
## [2]  {liquor (appetizer)}        => {soda} 0.002440264 0.3076923  0.007930859
## [3]  {liquor}                    => {soda} 0.002135231 0.1926606  0.011082867
## [4]  {instant coffee}            => {soda} 0.002440264 0.3287671  0.007422471
## [5]  {pet care}                  => {soda} 0.002135231 0.2258065  0.009456024
## [6]  {condensed milk}            => {soda} 0.002135231 0.2079208  0.010269446
## [7]  {chocolate marshmallow}     => {soda} 0.002440264 0.2696629  0.009049314
## [8]  {frozen potato products}    => {soda} 0.002745297 0.3253012  0.008439248
## [9]  {sweet spreads}             => {soda} 0.002541942 0.2808989  0.009049314
## [10] {spread cheese}             => {soda} 0.003152008 0.2818182  0.011184545
## [11] {dish cleaner}              => {soda} 0.002440264 0.2330097  0.010472801
## [12] {cling film/bags}           => {soda} 0.002338587 0.2053571  0.011387900
## [13] {mayonnaise}                => {soda} 0.002440264 0.2666667  0.009150991
## [14] {frozen dessert}            => {soda} 0.002541942 0.2358491  0.010777834
## [15] {white wine}                => {soda} 0.003660397 0.1925134  0.019013726
## [16] {packaged fruit/vegetables} => {soda} 0.002135231 0.1640625  0.013014743
## [17] {canned vegetables}         => {soda} 0.003050330 0.2830189  0.010777834
## [18] {cake bar}                  => {soda} 0.004473818 0.3384615  0.013218099
## [19] {seasonal products}         => {soda} 0.002643620 0.1857143  0.014234875
## [20] {dishes}                    => {soda} 0.002135231 0.1213873  0.017590239
##      lift      count
## [1]  1.0000000 1715 
## [2]  1.7645212   24 
## [3]  1.1048493   21 
## [4]  1.8853788   24 
## [5]  1.2949309   21 
## [6]  1.1923621   21 
## [7]  1.5464343   24 
## [8]  1.8655028   27 
## [9]  1.6108691   25 
## [10] 1.6161410   31 
## [11] 1.3362394   24 
## [12] 1.1776603   23 
## [13] 1.5292517   24 
## [14] 1.3525221   25 
## [15] 1.1040052   36 
## [16] 0.9408482   21 
## [17] 1.6230266   30 
## [18] 1.9409733   44 
## [19] 1.0650146   26 
## [20] 0.6961189   21
inspect(sort(regra_refri1, by = "lift"))
##       lhs                            rhs        support confidence    coverage      lift count
## [1]   {sausage,                                                                               
##        yogurt,                                                                                
##        bottled water}             => {soda} 0.002033554  0.5128205 0.003965430 2.9408687    20
## [2]   {bottled water,                                                                         
##        waffles}                   => {soda} 0.002033554  0.4761905 0.004270463 2.7308066    20
## [3]   {white bread,                                                                           
##        bottled water}             => {soda} 0.002033554  0.4651163 0.004372140 2.6672995    20
## [4]   {coffee,                                                                                
##        fruit/vegetable juice}     => {soda} 0.002643620  0.4406780 0.005998983 2.5271532    26
## [5]   {bottled water,                                                                         
##        chocolate}                 => {soda} 0.002541942  0.4385965 0.005795628 2.5152166    25
## [6]   {chocolate,                                                                             
##        napkins}                   => {soda} 0.002135231  0.4375000 0.004880529 2.5089286    21
## [7]   {white bread,                                                                           
##        pastry}                    => {soda} 0.002440264  0.4363636 0.005592272 2.5024119    24
## [8]   {pastry,                                                                                
##        salty snack}               => {soda} 0.002236909  0.4313725 0.005185562 2.4737895    22
## [9]   {rolls/buns,                                                                            
##        candy}                     => {soda} 0.003050330  0.4285714 0.007117438 2.4577259    30
## [10]  {yogurt,                                                                                
##        rolls/buns,                                                                            
##        bottled water}             => {soda} 0.003050330  0.4285714 0.007117438 2.4577259    30
## [11]  {dessert,                                                                               
##        pastry}                    => {soda} 0.002236909  0.4150943 0.005388917 2.3804390    22
## [12]  {sausage,                                                                               
##        rolls/buns,                                                                            
##        shopping bags}             => {soda} 0.002440264  0.4067797 0.005998983 2.3327568    24
## [13]  {white bread,                                                                           
##        shopping bags}             => {soda} 0.002948653  0.3972603 0.007422471 2.2781661    29
## [14]  {yogurt,                                                                                
##        canned beer}               => {soda} 0.002135231  0.3962264 0.005388917 2.2722372    21
## [15]  {dessert,                                                                               
##        shopping bags}             => {soda} 0.002440264  0.3934426 0.006202339 2.2562730    24
## [16]  {fruit/vegetable juice,                                                                 
##        bottled beer}              => {soda} 0.002745297  0.3913043 0.007015760 2.2440106    27
## [17]  {yogurt,                                                                                
##        candy}                     => {soda} 0.002135231  0.3888889 0.005490595 2.2301587    21
## [18]  {UHT-milk,                                                                              
##        bottled water}             => {soda} 0.002846975  0.3888889 0.007320793 2.2301587    28
## [19]  {sausage,                                                                               
##        canned beer}               => {soda} 0.002440264  0.3870968 0.006304016 2.2198815    24
## [20]  {rolls/buns,                                                                            
##        specialty bar}             => {soda} 0.002135231  0.3818182 0.005592272 2.1896104    21
## [21]  {sausage,                                                                               
##        dessert}                   => {soda} 0.002236909  0.3793103 0.005897306 2.1752287    22
## [22]  {whole milk,                                                                            
##        specialty bar}             => {soda} 0.002440264  0.3750000 0.006507372 2.1505102    24
## [23]  {fruit/vegetable juice,                                                                 
##        salty snack}               => {soda} 0.002236909  0.3728814 0.005998983 2.1383604    22
## [24]  {chocolate,                                                                             
##        newspapers}                => {soda} 0.002033554  0.3703704 0.005490595 2.1239607    20
## [25]  {bottled water,                                                                         
##        shopping bags}             => {soda} 0.004067107  0.3703704 0.010981190 2.1239607    40
## [26]  {white bread,                                                                           
##        fruit/vegetable juice}     => {soda} 0.002745297  0.3698630 0.007422471 2.1210512    27
## [27]  {other vegetables,                                                                      
##        candy}                     => {soda} 0.002541942  0.3676471 0.006914082 2.1083433    25
## [28]  {bottled water,                                                                         
##        canned beer}               => {soda} 0.002948653  0.3670886 0.008032537 2.1051408    29
## [29]  {bottled water,                                                                         
##        fruit/vegetable juice}     => {soda} 0.005185562  0.3642857 0.014234875 2.0890671    51
## [30]  {sausage,                                                                               
##        napkins}                   => {soda} 0.002440264  0.3636364 0.006710727 2.0853432    24
## [31]  {sausage,                                                                               
##        shopping bags}             => {soda} 0.005693950  0.3636364 0.015658363 2.0853432    56
## [32]  {whole milk,                                                                            
##        processed cheese}          => {soda} 0.002541942  0.3623188 0.007015760 2.0777876    25
## [33]  {pastry,                                                                                
##        long life bakery product}  => {soda} 0.002135231  0.3620690 0.005897306 2.0763547    21
## [34]  {domestic eggs,                                                                         
##        brown bread}               => {soda} 0.002440264  0.3582090 0.006812405 2.0542187    24
## [35]  {salty snack,                                                                           
##        shopping bags}             => {soda} 0.002135231  0.3559322 0.005998983 2.0411622    21
## [36]  {fruit/vegetable juice,                                                                 
##        napkins}                   => {soda} 0.002440264  0.3529412 0.006914082 2.0240096    24
## [37]  {sausage,                                                                               
##        white bread}               => {soda} 0.002541942  0.3521127 0.007219115 2.0192584    25
## [38]  {pastry,                                                                                
##        shopping bags}             => {soda} 0.004168785  0.3504274 0.011896289 2.0095936    41
## [39]  {domestic eggs,                                                                         
##        shopping bags}             => {soda} 0.003152008  0.3483146 0.009049314 1.9974776    31
## [40]  {pastry,                                                                                
##        napkins}                   => {soda} 0.002440264  0.3478261 0.007015760 1.9946761    24
## [41]  {whole milk,                                                                            
##        canned beer}               => {soda} 0.003050330  0.3448276 0.008845958 1.9774806    30
## [42]  {cream cheese ,                                                                         
##        bottled water}             => {soda} 0.002033554  0.3448276 0.005897306 1.9774806    20
## [43]  {rolls/buns,                                                                            
##        chocolate}                 => {soda} 0.004067107  0.3448276 0.011794611 1.9774806    40
## [44]  {tropical fruit,                                                                        
##        yogurt,                                                                                
##        bottled water}             => {soda} 0.002440264  0.3428571 0.007117438 1.9661808    24
## [45]  {sausage,                                                                               
##        bottled water}             => {soda} 0.004067107  0.3389831 0.011997966 1.9439640    40
## [46]  {cake bar}                  => {soda} 0.004473818  0.3384615 0.013218099 1.9409733    44
## [47]  {sausage,                                                                               
##        chocolate}                 => {soda} 0.002236909  0.3384615 0.006609049 1.9409733    22
## [48]  {meat,                                                                                  
##        rolls/buns}                => {soda} 0.002338587  0.3382353 0.006914082 1.9396759    23
## [49]  {coffee,                                                                                
##        bottled water}             => {soda} 0.002440264  0.3333333 0.007320793 1.9115646    24
## [50]  {tropical fruit,                                                                        
##        bottled beer}              => {soda} 0.002745297  0.3333333 0.008235892 1.9115646    27
## [51]  {brown bread,                                                                           
##        bottled water}             => {soda} 0.002745297  0.3333333 0.008235892 1.9115646    27
## [52]  {fruit/vegetable juice,                                                                 
##        shopping bags}             => {soda} 0.003558719  0.3333333 0.010676157 1.9115646    35
## [53]  {sausage,                                                                               
##        domestic eggs}             => {soda} 0.003152008  0.3297872 0.009557702 1.8912288    31
## [54]  {brown bread,                                                                           
##        shopping bags}             => {soda} 0.003050330  0.3296703 0.009252669 1.8905584    30
## [55]  {pastry,                                                                                
##        bottled water}             => {soda} 0.002948653  0.3295455 0.008947636 1.8898423    29
## [56]  {instant coffee}            => {soda} 0.002440264  0.3287671 0.007422471 1.8853788    24
## [57]  {fruit/vegetable juice,                                                                 
##        chocolate}                 => {soda} 0.002236909  0.3283582 0.006812405 1.8830338    22
## [58]  {frozen potato products}    => {soda} 0.002745297  0.3253012 0.008439248 1.8655028    27
## [59]  {citrus fruit,                                                                          
##        fruit/vegetable juice}     => {soda} 0.003355363  0.3235294 0.010371124 1.8553421    33
## [60]  {yogurt,                                                                                
##        bottled water}             => {soda} 0.007422471  0.3230088 0.022979156 1.8523569    73
## [61]  {rolls/buns,                                                                            
##        shopping bags}             => {soda} 0.006304016  0.3229167 0.019522115 1.8518282    62
## [62]  {bottled water,                                                                         
##        bottled beer}              => {soda} 0.005083884  0.3225806 0.015760041 1.8499013    50
## [63]  {frankfurter,                                                                           
##        bottled water}             => {soda} 0.002338587  0.3194444 0.007320793 1.8319161    23
## [64]  {processed cheese}          => {soda} 0.005287239  0.3190184 0.016573462 1.8294729    52
## [65]  {pastry,                                                                                
##        waffles}                   => {soda} 0.002236909  0.3188406 0.007015760 1.8284531    22
## [66]  {yogurt,                                                                                
##        chocolate}                 => {soda} 0.002948653  0.3186813 0.009252669 1.8275398    29
## [67]  {citrus fruit,                                                                          
##        chocolate}                 => {soda} 0.002033554  0.3174603 0.006405694 1.8205377    20
## [68]  {sausage,                                                                               
##        rolls/buns}                => {soda} 0.009659380  0.3156146 0.030604982 1.8099532    95
## [69]  {bottled water,                                                                         
##        newspapers}                => {soda} 0.003558719  0.3153153 0.011286223 1.8082368    35
## [70]  {whole milk,                                                                            
##        semi-finished bread}       => {soda} 0.002236909  0.3142857 0.007117438 1.8023324    22
## [71]  {canned beer,                                                                           
##        shopping bags}             => {soda} 0.003558719  0.3125000 0.011387900 1.7920918    35
## [72]  {domestic eggs,                                                                         
##        bottled water}             => {soda} 0.002846975  0.3111111 0.009150991 1.7841270    28
## [73]  {sausage,                                                                               
##        other vegetables,                                                                      
##        rolls/buns}                => {soda} 0.002745297  0.3103448 0.008845958 1.7797326    27
## [74]  {dessert,                                                                               
##        yogurt}                    => {soda} 0.003050330  0.3092784 0.009862735 1.7736167    30
## [75]  {newspapers,                                                                            
##        shopping bags}             => {soda} 0.002135231  0.3088235 0.006914082 1.7710084    21
## [76]  {whole milk,                                                                            
##        candy}                     => {soda} 0.002541942  0.3086420 0.008235892 1.7699672    25
## [77]  {liquor (appetizer)}        => {soda} 0.002440264  0.3076923 0.007930859 1.7645212    24
## [78]  {pip fruit,                                                                             
##        white bread}               => {soda} 0.002033554  0.3076923 0.006609049 1.7645212    20
## [79]  {root vegetables,                                                                       
##        white bread}               => {soda} 0.002440264  0.3076923 0.007930859 1.7645212    24
## [80]  {sliced cheese,                                                                         
##        rolls/buns}                => {soda} 0.002338587  0.3066667 0.007625826 1.7586395    23
## [81]  {other vegetables,                                                                      
##        whole milk,                                                                            
##        shopping bags}             => {soda} 0.002338587  0.3066667 0.007625826 1.7586395    23
## [82]  {whole milk,                                                                            
##        chocolate}                 => {soda} 0.005083884  0.3048780 0.016675140 1.7483823    50
## [83]  {frankfurter,                                                                           
##        pastry}                    => {soda} 0.002541942  0.3048780 0.008337570 1.7483823    25
## [84]  {other vegetables,                                                                      
##        whole milk,                                                                            
##        newspapers}                => {soda} 0.002541942  0.3048780 0.008337570 1.7483823    25
## [85]  {tropical fruit,                                                                        
##        napkins}                   => {soda} 0.003050330  0.3030303 0.010066090 1.7377860    30
## [86]  {pork,                                                                                  
##        bottled water}             => {soda} 0.002236909  0.3013699 0.007422471 1.7282639    22
## [87]  {rolls/buns,                                                                            
##        waffles}                   => {soda} 0.002745297  0.3000000 0.009150991 1.7204082    27
## [88]  {sausage,                                                                               
##        other vegetables,                                                                      
##        yogurt}                    => {soda} 0.002440264  0.3000000 0.008134215 1.7204082    24
## [89]  {dessert,                                                                               
##        rolls/buns}                => {soda} 0.002033554  0.2985075 0.006812405 1.7118489    20
## [90]  {frankfurter,                                                                           
##        shopping bags}             => {soda} 0.002440264  0.2962963 0.008235892 1.6991686    24
## [91]  {fruit/vegetable juice,                                                                 
##        newspapers}                => {soda} 0.002440264  0.2962963 0.008235892 1.6991686    24
## [92]  {rolls/buns,                                                                            
##        long life bakery product}  => {soda} 0.002338587  0.2948718 0.007930859 1.6909995    23
## [93]  {whole milk,                                                                            
##        yogurt,                                                                                
##        bottled water}             => {soda} 0.002846975  0.2947368 0.009659380 1.6902256    28
## [94]  {bottled water,                                                                         
##        napkins}                   => {soda} 0.002541942  0.2941176 0.008642603 1.6866747    25
## [95]  {sausage,                                                                               
##        fruit/vegetable juice}     => {soda} 0.002948653  0.2929293 0.010066090 1.6798598    29
## [96]  {brown bread,                                                                           
##        fruit/vegetable juice}     => {soda} 0.002440264  0.2926829 0.008337570 1.6784470    24
## [97]  {other vegetables,                                                                      
##        yogurt,                                                                                
##        rolls/buns}                => {soda} 0.003355363  0.2920354 0.011489578 1.6747336    33
## [98]  {whole milk,                                                                            
##        misc. beverages}           => {soda} 0.002033554  0.2898551 0.007015760 1.6622301    20
## [99]  {candy}                     => {soda} 0.008642603  0.2891156 0.029893238 1.6579897    85
## [100] {other vegetables,                                                                      
##        white bread}               => {soda} 0.003965430  0.2888889 0.013726487 1.6566893    39
## [101] {sausage,                                                                               
##        citrus fruit}              => {soda} 0.003253686  0.2882883 0.011286223 1.6532451    32
## [102] {other vegetables,                                                                      
##        chocolate}                 => {soda} 0.003660397  0.2880000 0.012709710 1.6515918    36
## [103] {tropical fruit,                                                                        
##        chocolate}                 => {soda} 0.002338587  0.2875000 0.008134215 1.6487245    23
## [104] {frozen vegetables,                                                                     
##        fruit/vegetable juice}     => {soda} 0.002236909  0.2857143 0.007829181 1.6384840    22
## [105] {sausage,                                                                               
##        bottled beer}              => {soda} 0.002236909  0.2857143 0.007829181 1.6384840    22
## [106] {whole milk,                                                                            
##        yogurt,                                                                                
##        brown bread}               => {soda} 0.002033554  0.2857143 0.007117438 1.6384840    20
## [107] {tropical fruit,                                                                        
##        other vegetables,                                                                      
##        rolls/buns}                => {soda} 0.002236909  0.2857143 0.007829181 1.6384840    22
## [108] {sausage,                                                                               
##        yogurt}                    => {soda} 0.005592272  0.2849741 0.019623793 1.6342392    55
## [109] {sausage,                                                                               
##        tropical fruit}            => {soda} 0.003965430  0.2846715 0.013929842 1.6325041    39
## [110] {canned vegetables}         => {soda} 0.003050330  0.2830189 0.010777834 1.6230266    30
## [111] {spread cheese}             => {soda} 0.003152008  0.2818182 0.011184545 1.6161410    31
## [112] {chicken,                                                                               
##        whipped/sour cream}        => {soda} 0.002033554  0.2816901 0.007219115 1.6154067    20
## [113] {napkins,                                                                               
##        shopping bags}             => {soda} 0.002033554  0.2816901 0.007219115 1.6154067    20
## [114] {yogurt,                                                                                
##        pastry}                    => {soda} 0.004982206  0.2816092 0.017691917 1.6149425    49
## [115] {rolls/buns,                                                                            
##        bottled water}             => {soda} 0.006812405  0.2815126 0.024199288 1.6143886    67
## [116] {sweet spreads}             => {soda} 0.002541942  0.2808989 0.009049314 1.6108691    25
## [117] {other vegetables,                                                                      
##        canned beer}               => {soda} 0.002541942  0.2808989 0.009049314 1.6108691    25
## [118] {yogurt,                                                                                
##        white bread}               => {soda} 0.002541942  0.2808989 0.009049314 1.6108691    25
## [119] {other vegetables,                                                                      
##        dessert}                   => {soda} 0.003253686  0.2807018 0.011591256 1.6097386    32
## [120] {tropical fruit,                                                                        
##        bottled water}             => {soda} 0.005185562  0.2802198 0.018505338 1.6069747    51
## [121] {yogurt,                                                                                
##        shopping bags}             => {soda} 0.004270463  0.2800000 0.015251652 1.6057143    42
## [122] {root vegetables,                                                                       
##        fruit/vegetable juice}     => {soda} 0.003355363  0.2796610 0.011997966 1.6037703    33
## [123] {tropical fruit,                                                                        
##        white bread}               => {soda} 0.002440264  0.2790698 0.008744281 1.6003797    24
## [124] {pastry,                                                                                
##        chocolate}                 => {soda} 0.002236909  0.2784810 0.008032537 1.5970034    22
## [125] {yogurt,                                                                                
##        newspapers}                => {soda} 0.004270463  0.2781457 0.015353330 1.5950804    42
## [126] {whole milk,                                                                            
##        shopping bags}             => {soda} 0.006812405  0.2780083 0.024504321 1.5942925    67
## [127] {whole milk,                                                                            
##        yogurt,                                                                                
##        pastry}                    => {soda} 0.002541942  0.2777778 0.009150991 1.5929705    25
## [128] {other vegetables,                                                                      
##        rolls/buns,                                                                            
##        bottled water}             => {soda} 0.002033554  0.2777778 0.007320793 1.5929705    20
## [129] {sausage,                                                                               
##        pastry}                    => {soda} 0.003457041  0.2764228 0.012506355 1.5851999    34
## [130] {chocolate,                                                                             
##        shopping bags}             => {soda} 0.002236909  0.2750000 0.008134215 1.5770408    22
## [131] {pastry,                                                                                
##        fruit/vegetable juice}     => {soda} 0.002338587  0.2738095 0.008540925 1.5702138    23
## [132] {sausage,                                                                               
##        pip fruit}                 => {soda} 0.002948653  0.2735849 0.010777834 1.5689257    29
## [133] {yogurt,                                                                                
##        napkins}                   => {soda} 0.003355363  0.2727273 0.012302999 1.5640074    33
## [134] {rolls/buns,                                                                            
##        fruit/vegetable juice}     => {soda} 0.003965430  0.2727273 0.014539908 1.5640074    39
## [135] {chocolate}                 => {soda} 0.013523132  0.2725410 0.049618709 1.5629391   133
## [136] {yogurt,                                                                                
##        fruit/vegetable juice}     => {soda} 0.005083884  0.2717391 0.018708693 1.5583407    50
## [137] {other vegetables,                                                                      
##        whole milk,                                                                            
##        brown bread}               => {soda} 0.002541942  0.2717391 0.009354347 1.5583407    25
## [138] {tropical fruit,                                                                        
##        shopping bags}             => {soda} 0.003660397  0.2706767 0.013523132 1.5522480    36
## [139] {pasta}                     => {soda} 0.004067107  0.2702703 0.015048297 1.5499173    40
## [140] {rolls/buns,                                                                            
##        canned beer}               => {soda} 0.003050330  0.2702703 0.011286223 1.5499173    30
## [141] {chocolate marshmallow}     => {soda} 0.002440264  0.2696629 0.009049314 1.5464343    24
## [142] {whipped/sour cream,                                                                    
##        fruit/vegetable juice}     => {soda} 0.002440264  0.2696629 0.009049314 1.5464343    24
## [143] {other vegetables,                                                                      
##        whole milk,                                                                            
##        pastry}                    => {soda} 0.002846975  0.2692308 0.010574479 1.5439560    28
## [144] {sausage,                                                                               
##        other vegetables}          => {soda} 0.007219115  0.2679245 0.026944586 1.5364652    71
## [145] {whipped/sour cream,                                                                    
##        bottled water}             => {soda} 0.002338587  0.2674419 0.008744281 1.5336972    23
## [146] {tropical fruit,                                                                        
##        yogurt,                                                                                
##        rolls/buns}                => {soda} 0.002338587  0.2674419 0.008744281 1.5336972    23
## [147] {mayonnaise}                => {soda} 0.002440264  0.2666667 0.009150991 1.5292517    24
## [148] {whole milk,                                                                            
##        dessert}                   => {soda} 0.003660397  0.2666667 0.013726487 1.5292517    36
## [149] {butter,                                                                                
##        pastry}                    => {soda} 0.002033554  0.2666667 0.007625826 1.5292517    20
## [150] {pip fruit,                                                                             
##        fruit/vegetable juice}     => {soda} 0.002541942  0.2659574 0.009557702 1.5251845    25
## [151] {sausage,                                                                               
##        newspapers}                => {soda} 0.002135231  0.2658228 0.008032537 1.5244123    21
## [152] {dessert}                   => {soda} 0.009862735  0.2657534 0.037112354 1.5240145    97
## [153] {pastry,                                                                                
##        newspapers}                => {soda} 0.002236909  0.2650602 0.008439248 1.5200393    22
## [154] {other vegetables,                                                                      
##        sugar}                     => {soda} 0.002846975  0.2641509 0.010777834 1.5148248    28
## [155] {specialty bar}             => {soda} 0.007219115  0.2639405 0.027351296 1.5136181    71
## [156] {other vegetables,                                                                      
##        yogurt,                                                                                
##        bottled water}             => {soda} 0.002135231  0.2625000 0.008134215 1.5053571    21
## [157] {bottled water}             => {soda} 0.028978139  0.2621895 0.110523640 1.5035766   285
## [158] {other vegetables,                                                                      
##        whole milk,                                                                            
##        fruit/vegetable juice}     => {soda} 0.002745297  0.2621359 0.010472801 1.5032693    27
## [159] {sausage,                                                                               
##        other vegetables,                                                                      
##        whole milk}                => {soda} 0.002643620  0.2600000 0.010167768 1.4910204    26
## [160] {tropical fruit,                                                                        
##        domestic eggs}             => {soda} 0.002948653  0.2589286 0.011387900 1.4848761    29
## [161] {sausage}                   => {soda} 0.024300966  0.2586580 0.093950178 1.4833245   239
## [162] {misc. beverages}           => {soda} 0.007320793  0.2580645 0.028368073 1.4799210    72
## [163] {other vegetables,                                                                      
##        newspapers}                => {soda} 0.004982206  0.2578947 0.019318760 1.4789474    49
## [164] {rolls/buns,                                                                            
##        pastry}                    => {soda} 0.005388917  0.2572816 0.020945602 1.4754309    53
## [165] {beef,                                                                                  
##        root vegetables,                                                                       
##        other vegetables}          => {soda} 0.002033554  0.2564103 0.007930859 1.4704343    20
## [166] {citrus fruit,                                                                          
##        newspapers}                => {soda} 0.002135231  0.2560976 0.008337570 1.4686411    21
## [167] {chewing gum}               => {soda} 0.005388917  0.2560386 0.021047280 1.4683033    53
## [168] {sausage,                                                                               
##        whole milk,                                                                            
##        yogurt}                    => {soda} 0.002236909  0.2558140 0.008744281 1.4670147    22
## [169] {pip fruit,                                                                             
##        rolls/buns}                => {soda} 0.003558719  0.2554745 0.013929842 1.4650678    35
## [170] {root vegetables,                                                                       
##        napkins}                   => {soda} 0.002541942  0.2551020 0.009964413 1.4629321    25
## [171] {fruit/vegetable juice}     => {soda} 0.018403660  0.2545710 0.072292832 1.4598869   181
## [172] {frankfurter,                                                                           
##        yogurt}                    => {soda} 0.002846975  0.2545455 0.011184545 1.4597403    28
## [173] {butter,                                                                                
##        fruit/vegetable juice}     => {soda} 0.002033554  0.2531646 0.008032537 1.4518212    20
## [174] {other vegetables,                                                                      
##        waffles}                   => {soda} 0.002541942  0.2525253 0.010066090 1.4481550    25
## [175] {rolls/buns,                                                                            
##        napkins}                   => {soda} 0.002948653  0.2521739 0.011692933 1.4461402    29
## [176] {other vegetables,                                                                      
##        bottled beer}              => {soda} 0.004067107  0.2515723 0.016166751 1.4426903    40
## [177] {yogurt,                                                                                
##        rolls/buns}                => {soda} 0.008642603  0.2514793 0.034367056 1.4421567    85
## [178] {other vegetables,                                                                      
##        UHT-milk}                  => {soda} 0.002033554  0.2500000 0.008134215 1.4336735    20
## [179] {berries,                                                                               
##        yogurt}                    => {soda} 0.002643620  0.2500000 0.010574479 1.4336735    26
## [180] {whole milk,                                                                            
##        sugar}                     => {soda} 0.003762074  0.2500000 0.015048297 1.4336735    37
## [181] {pip fruit,                                                                             
##        bottled water}             => {soda} 0.002643620  0.2500000 0.010574479 1.4336735    26
## [182] {shopping bags}             => {soda} 0.024605999  0.2497420 0.098525674 1.4321939   242
## [183] {waffles}                   => {soda} 0.009557702  0.2486772 0.038434164 1.4260879    94
## [184] {whole milk,                                                                            
##        pastry}                    => {soda} 0.008235892  0.2477064 0.033248602 1.4205205    81
## [185] {sausage,                                                                               
##        brown bread}               => {soda} 0.002643620  0.2476190 0.010676157 1.4200194    26
## [186] {salty snack}               => {soda} 0.009354347  0.2473118 0.037824098 1.4182576    92
## [187] {whole milk,                                                                            
##        yogurt,                                                                                
##        fruit/vegetable juice}     => {soda} 0.002338587  0.2473118 0.009456024 1.4182576    23
## [188] {domestic eggs,                                                                         
##        pastry}                    => {soda} 0.002236909  0.2471910 0.009049314 1.4175648    22
## [189] {root vegetables,                                                                       
##        bottled water}             => {soda} 0.003863752  0.2467532 0.015658363 1.4150543    38
## [190] {whole milk,                                                                            
##        salty snack}               => {soda} 0.002745297  0.2454545 0.011184545 1.4076067    27
## [191] {other vegetables,                                                                      
##        salty snack}               => {soda} 0.002643620  0.2452830 0.010777834 1.4066230    26
## [192] {sausage,                                                                               
##        root vegetables}           => {soda} 0.003660397  0.2448980 0.014946619 1.4044148    36
## [193] {tropical fruit,                                                                        
##        fruit/vegetable juice}     => {soda} 0.003355363  0.2444444 0.013726487 1.4018141    33
## [194] {other vegetables,                                                                      
##        whole milk,                                                                            
##        rolls/buns}                => {soda} 0.004372140  0.2443182 0.017895272 1.4010900    43
## [195] {white bread}               => {soda} 0.010269446  0.2439614 0.042094560 1.3990437   101
## [196] {ice cream}                 => {soda} 0.006100661  0.2439024 0.025012710 1.3987058    60
## [197] {other vegetables,                                                                      
##        pastry}                    => {soda} 0.005490595  0.2432432 0.022572445 1.3949255    54
## [198] {root vegetables,                                                                       
##        bottled beer}              => {soda} 0.002338587  0.2421053 0.009659380 1.3883996    23
## [199] {brown bread,                                                                           
##        pastry}                    => {soda} 0.002338587  0.2421053 0.009659380 1.3883996    23
## [200] {sausage,                                                                               
##        whole milk,                                                                            
##        rolls/buns}                => {soda} 0.002236909  0.2391304 0.009354347 1.3713398    22
## [201] {root vegetables,                                                                       
##        newspapers}                => {soda} 0.002745297  0.2389381 0.011489578 1.3702366    27
## [202] {butter,                                                                                
##        bottled water}             => {soda} 0.002135231  0.2386364 0.008947636 1.3685065    21
## [203] {tropical fruit,                                                                        
##        pastry}                    => {soda} 0.003152008  0.2384615 0.013218099 1.3675039    31
## [204] {red/blush wine}            => {soda} 0.004575496  0.2380952 0.019217082 1.3654033    45
## [205] {whole milk,                                                                            
##        white bread}               => {soda} 0.004067107  0.2380952 0.017081851 1.3654033    40
## [206] {pork,                                                                                  
##        tropical fruit}            => {soda} 0.002033554  0.2380952 0.008540925 1.3654033    20
## [207] {margarine,                                                                             
##        bottled water}             => {soda} 0.002440264  0.2376238 0.010269446 1.3626995    24
## [208] {whole milk,                                                                            
##        napkins}                   => {soda} 0.004677173  0.2371134 0.019725470 1.3597728    46
## [209] {pastry}                    => {soda} 0.021047280  0.2365714 0.088967972 1.3566647   207
## [210] {sausage,                                                                               
##        whipped/sour cream}        => {soda} 0.002135231  0.2359551 0.009049314 1.3531300    21
## [211] {frozen dessert}            => {soda} 0.002541942  0.2358491 0.010777834 1.3525221    25
## [212] {rolls/buns,                                                                            
##        brown bread}               => {soda} 0.002948653  0.2338710 0.012608033 1.3411784    29
## [213] {dish cleaner}              => {soda} 0.002440264  0.2330097 0.010472801 1.3362394    24
## [214] {other vegetables,                                                                      
##        shopping bags}             => {soda} 0.005388917  0.2324561 0.023182511 1.3330648    53
## [215] {chicken,                                                                               
##        rolls/buns}                => {soda} 0.002236909  0.2315789 0.009659380 1.3280344    22
## [216] {other vegetables,                                                                      
##        rolls/buns}                => {soda} 0.009862735  0.2315036 0.042602949 1.3276022    97
## [217] {yogurt,                                                                                
##        bottled beer}              => {soda} 0.002135231  0.2307692 0.009252669 1.3233909    21
## [218] {semi-finished bread}       => {soda} 0.004067107  0.2298851 0.017691917 1.3183204    40
## [219] {yogurt,                                                                                
##        frozen vegetables}         => {soda} 0.002846975  0.2295082 0.012404677 1.3161593    28
## [220] {other vegetables,                                                                      
##        bottled water}             => {soda} 0.005693950  0.2295082 0.024809354 1.3161593    56
## [221] {citrus fruit,                                                                          
##        shopping bags}             => {soda} 0.002236909  0.2291667 0.009761057 1.3142007    22
## [222] {napkins}                   => {soda} 0.011997966  0.2291262 0.052364006 1.3139687   118
## [223] {whole milk,                                                                            
##        fruit/vegetable juice}     => {soda} 0.006100661  0.2290076 0.026639553 1.3132887    60
## [224] {other vegetables,                                                                      
##        domestic eggs}             => {soda} 0.005083884  0.2283105 0.022267412 1.3092908    50
## [225] {beef,                                                                                  
##        root vegetables}           => {soda} 0.003965430  0.2280702 0.017386884 1.3079126    39
## [226] {UHT-milk}                  => {soda} 0.007625826  0.2279635 0.033451957 1.3073010    75
## [227] {pickled vegetables}        => {soda} 0.004067107  0.2272727 0.017895272 1.3033395    40
## [228] {pet care}                  => {soda} 0.002135231  0.2258065 0.009456024 1.2949309    21
## [229] {root vegetables,                                                                       
##        onions}                    => {soda} 0.002135231  0.2258065 0.009456024 1.2949309    21
## [230] {tropical fruit,                                                                        
##        yogurt}                    => {soda} 0.006609049  0.2256944 0.029283172 1.2942885    65
## [231] {whole milk,                                                                            
##        long life bakery product}  => {soda} 0.003050330  0.2255639 0.013523132 1.2935400    30
## [232] {root vegetables,                                                                       
##        other vegetables,                                                                      
##        rolls/buns}                => {soda} 0.002745297  0.2250000 0.012201322 1.2903061    27
## [233] {sausage,                                                                               
##        whole milk}                => {soda} 0.006710727  0.2244898 0.029893238 1.2873803    66
## [234] {other vegetables,                                                                      
##        brown bread}               => {soda} 0.004168785  0.2228261 0.018708693 1.2778394    41
## [235] {frankfurter,                                                                           
##        sausage}                   => {soda} 0.002236909  0.2222222 0.010066090 1.2743764    22
## [236] {root vegetables,                                                                       
##        pastry}                    => {soda} 0.002440264  0.2222222 0.010981190 1.2743764    24
## [237] {yogurt,                                                                                
##        cream cheese }             => {soda} 0.002745297  0.2213115 0.012404677 1.2691536    27
## [238] {domestic eggs,                                                                         
##        rolls/buns}                => {soda} 0.003457041  0.2207792 0.015658363 1.2661012    34
## [239] {berries}                   => {soda} 0.007320793  0.2201835 0.033248602 1.2626849    72
## [240] {beef,                                                                                  
##        other vegetables,                                                                      
##        whole milk}                => {soda} 0.002033554  0.2197802 0.009252669 1.2603723    20
## [241] {pip fruit,                                                                             
##        pastry}                    => {soda} 0.002338587  0.2190476 0.010676157 1.2561710    23
## [242] {tropical fruit,                                                                        
##        rolls/buns}                => {soda} 0.005388917  0.2190083 0.024605999 1.2559454    53
## [243] {whole milk,                                                                            
##        bottled water}             => {soda} 0.007524148  0.2189349 0.034367056 1.2555247    74
## [244] {frozen meals}              => {soda} 0.006202339  0.2186380 0.028368073 1.2538220    61
## [245] {tropical fruit,                                                                        
##        margarine}                 => {soda} 0.002033554  0.2173913 0.009354347 1.2466726    20
## [246] {pip fruit,                                                                             
##        shopping bags}             => {soda} 0.002033554  0.2173913 0.009354347 1.2466726    20
## [247] {yogurt,                                                                                
##        brown bread}               => {soda} 0.003152008  0.2167832 0.014539908 1.2431854    31
## [248] {whole milk,                                                                            
##        frozen meals}              => {soda} 0.002135231  0.2164948 0.009862735 1.2415317    21
## [249] {rolls/buns,                                                                            
##        bottled beer}              => {soda} 0.002948653  0.2164179 0.013624809 1.2410905    29
## [250] {sugar}                     => {soda} 0.007320793  0.2162162 0.033858668 1.2399338    72
## [251] {tropical fruit,                                                                        
##        newspapers}                => {soda} 0.002541942  0.2155172 0.011794611 1.2359254    25
## [252] {whipped/sour cream,                                                                    
##        rolls/buns}                => {soda} 0.003152008  0.2152778 0.014641586 1.2345522    31
## [253] {pip fruit,                                                                             
##        yogurt}                    => {soda} 0.003863752  0.2146893 0.017996950 1.2311772    38
## [254] {rolls/buns,                                                                            
##        margarine}                 => {soda} 0.003152008  0.2137931 0.014743264 1.2260380    31
## [255] {hygiene articles}          => {soda} 0.007015760  0.2129630 0.032943569 1.2212774    69
## [256] {pip fruit,                                                                             
##        whole milk,                                                                            
##        yogurt}                    => {soda} 0.002033554  0.2127660 0.009557702 1.2201476    20
## [257] {meat}                      => {soda} 0.005490595  0.2125984 0.025826131 1.2191869    54
## [258] {other vegetables,                                                                      
##        fruit/vegetable juice}     => {soda} 0.004473818  0.2125604 0.021047280 1.2189687    44
## [259] {other vegetables,                                                                      
##        napkins}                   => {soda} 0.003050330  0.2112676 0.014438231 1.2115550    30
## [260] {bottled beer}              => {soda} 0.016980173  0.2108586 0.080528724 1.2092094   167
## [261] {pork,                                                                                  
##        other vegetables,                                                                      
##        whole milk}                => {soda} 0.002135231  0.2100000 0.010167768 1.2042857    21
## [262] {pork,                                                                                  
##        root vegetables}           => {soda} 0.002846975  0.2089552 0.013624809 1.1982942    28
## [263] {rolls/buns}                => {soda} 0.038332486  0.2084024 0.183934926 1.1951242   377
## [264] {yogurt,                                                                                
##        coffee}                    => {soda} 0.002033554  0.2083333 0.009761057 1.1947279    20
## [265] {citrus fruit,                                                                          
##        pastry}                    => {soda} 0.002033554  0.2083333 0.009761057 1.1947279    20
## [266] {tropical fruit,                                                                        
##        whole milk,                                                                            
##        yogurt}                    => {soda} 0.003152008  0.2080537 0.015149975 1.1931242    31
## [267] {whole milk,                                                                            
##        waffles}                   => {soda} 0.002643620  0.2080000 0.012709710 1.1928163    26
## [268] {condensed milk}            => {soda} 0.002135231  0.2079208 0.010269446 1.1923621    21
## [269] {whole milk,                                                                            
##        sliced cheese}             => {soda} 0.002236909  0.2075472 0.010777834 1.1902195    22
## [270] {sliced cheese}             => {soda} 0.005083884  0.2074689 0.024504321 1.1897705    50
## [271] {specialty chocolate}       => {soda} 0.006304016  0.2073579 0.030401627 1.1891338    62
## [272] {pork,                                                                                  
##        rolls/buns}                => {soda} 0.002338587  0.2072072 0.011286223 1.1882699    23
## [273] {other vegetables,                                                                      
##        whole milk,                                                                            
##        domestic eggs}             => {soda} 0.002541942  0.2066116 0.012302999 1.1848541    25
## [274] {pork}                      => {soda} 0.011896289  0.2063492 0.057651246 1.1833495   117
## [275] {rolls/buns,                                                                            
##        newspapers}                => {soda} 0.004067107  0.2061856 0.019725470 1.1824111    40
## [276] {citrus fruit,                                                                          
##        root vegetables,                                                                       
##        other vegetables}          => {soda} 0.002135231  0.2058824 0.010371124 1.1806723    21
## [277] {cling film/bags}           => {soda} 0.002338587  0.2053571 0.011387900 1.1776603    23
## [278] {meat,                                                                                  
##        other vegetables}          => {soda} 0.002033554  0.2040816 0.009964413 1.1703457    20
## [279] {cream cheese ,                                                                         
##        rolls/buns}                => {soda} 0.002033554  0.2040816 0.009964413 1.1703457    20
## [280] {long life bakery product}  => {soda} 0.007625826  0.2038043 0.037417387 1.1687555    75
## [281] {ham,                                                                                   
##        whole milk}                => {soda} 0.002338587  0.2035398 0.011489578 1.1672386    23
## [282] {citrus fruit,                                                                          
##        bottled water}             => {soda} 0.002745297  0.2030075 0.013523132 1.1641860    27
## [283] {chicken,                                                                               
##        whole milk}                => {soda} 0.003558719  0.2023121 0.017590239 1.1601982    35
## [284] {root vegetables,                                                                       
##        margarine}                 => {soda} 0.002236909  0.2018349 0.011082867 1.1574611    22
## [285] {whole milk,                                                                            
##        brown bread}               => {soda} 0.005083884  0.2016129 0.025216065 1.1561883    50
## [286] {tropical fruit,                                                                        
##        other vegetables}          => {soda} 0.007219115  0.2011331 0.035892222 1.1534370    71
## [287] {frankfurter,                                                                           
##        rolls/buns}                => {soda} 0.003863752  0.2010582 0.019217082 1.1530072    38
## [288] {root vegetables,                                                                       
##        rolls/buns}                => {soda} 0.004880529  0.2008368 0.024300966 1.1517377    48
## [289] {yogurt,                                                                                
##        margarine}                 => {soda} 0.002846975  0.2000000 0.014234875 1.1469388    28
## [290] {citrus fruit,                                                                          
##        rolls/buns}                => {soda} 0.003355363  0.2000000 0.016776817 1.1469388    33
## [291] {other vegetables,                                                                      
##        yogurt,                                                                                
##        whipped/sour cream}        => {soda} 0.002033554  0.2000000 0.010167768 1.1469388    20
## [292] {tropical fruit}            => {soda} 0.020843925  0.1986434 0.104931368 1.1391592   205
## [293] {tropical fruit,                                                                        
##        whipped/sour cream}        => {soda} 0.002745297  0.1985294 0.013828165 1.1385054    27
## [294] {other vegetables,                                                                      
##        whole milk,                                                                            
##        bottled water}             => {soda} 0.002135231  0.1981132 0.010777834 1.1361186    21
## [295] {berries,                                                                               
##        other vegetables}          => {soda} 0.002033554  0.1980198 0.010269446 1.1355829    20
## [296] {frankfurter,                                                                           
##        other vegetables}          => {soda} 0.003253686  0.1975309 0.016471784 1.1327790    32
## [297] {other vegetables,                                                                      
##        coffee}                    => {soda} 0.002643620  0.1969697 0.013421454 1.1295609    26
## [298] {cat food}                  => {soda} 0.004575496  0.1965066 0.023284189 1.1269049    45
## [299] {other vegetables,                                                                      
##        whole milk,                                                                            
##        yogurt}                    => {soda} 0.004372140  0.1963470 0.022267412 1.1259901    43
## [300] {yogurt,                                                                                
##        whipped/sour cream}        => {soda} 0.004067107  0.1960784 0.020742247 1.1244498    40
## [301] {yogurt}                    => {soda} 0.027351296  0.1960641 0.139501779 1.1243678   269
## [302] {canned fish}               => {soda} 0.002948653  0.1959459 0.015048297 1.1236900    29
## [303] {domestic eggs}             => {soda} 0.012404677  0.1955128 0.063446873 1.1212062   122
## [304] {mustard}                   => {soda} 0.002338587  0.1949153 0.011997966 1.1177793    23
## [305] {rolls/buns,                                                                            
##        coffee}                    => {soda} 0.002135231  0.1944444 0.010981190 1.1150794    21
## [306] {other vegetables,                                                                      
##        whole milk,                                                                            
##        whipped/sour cream}        => {soda} 0.002846975  0.1944444 0.014641586 1.1150794    28
## [307] {tropical fruit,                                                                        
##        whole milk,                                                                            
##        rolls/buns}                => {soda} 0.002135231  0.1944444 0.010981190 1.1150794    21
## [308] {brown bread}               => {soda} 0.012608033  0.1943574 0.064870361 1.1145800   124
## [309] {chicken}                   => {soda} 0.008337570  0.1943128 0.042907982 1.1143244    82
## [310] {root vegetables,                                                                       
##        other vegetables,                                                                      
##        whole milk}                => {soda} 0.004473818  0.1929825 0.023182511 1.1066953    44
## [311] {liquor}                    => {soda} 0.002135231  0.1926606 0.011082867 1.1048493    21
## [312] {pork,                                                                                  
##        whole milk}                => {soda} 0.004270463  0.1926606 0.022165735 1.1048493    42
## [313] {white wine}                => {soda} 0.003660397  0.1925134 0.019013726 1.1040052    36
## [314] {citrus fruit,                                                                          
##        yogurt}                    => {soda} 0.004168785  0.1924883 0.021657346 1.1038613    41
## [315] {other vegetables,                                                                      
##        yogurt}                    => {soda} 0.008337570  0.1920375 0.043416370 1.1012761    82
## [316] {root vegetables,                                                                       
##        whole milk,                                                                            
##        rolls/buns}                => {soda} 0.002440264  0.1920000 0.012709710 1.1010612    24
## [317] {root vegetables,                                                                       
##        domestic eggs}             => {soda} 0.002745297  0.1914894 0.014336553 1.0981329    27
## [318] {ham}                       => {soda} 0.004982206  0.1914062 0.026029487 1.0976562    49
## [319] {frankfurter}               => {soda} 0.011286223  0.1913793 0.058973055 1.0975018   111
## [320] {tropical fruit,                                                                        
##        brown bread}               => {soda} 0.002033554  0.1904762 0.010676157 1.0923226    20
## [321] {root vegetables,                                                                       
##        shopping bags}             => {soda} 0.002440264  0.1904762 0.012811388 1.0923226    24
## [322] {tropical fruit,                                                                        
##        root vegetables,                                                                       
##        other vegetables}          => {soda} 0.002338587  0.1900826 0.012302999 1.0900658    23
## [323] {butter,                                                                                
##        rolls/buns}                => {soda} 0.002541942  0.1893939 0.013421454 1.0861163    25
## [324] {tropical fruit,                                                                        
##        pip fruit}                 => {soda} 0.003863752  0.1890547 0.020437214 1.0841710    38
## [325] {root vegetables,                                                                       
##        other vegetables,                                                                      
##        yogurt}                    => {soda} 0.002440264  0.1889764 0.012913066 1.0837217    24
## [326] {pip fruit,                                                                             
##        other vegetables,                                                                      
##        whole milk}                => {soda} 0.002541942  0.1879699 0.013523132 1.0779500    25
## [327] {whole milk,                                                                            
##        yogurt}                    => {soda} 0.010472801  0.1869328 0.056024403 1.0720027   103
## [328] {other vegetables,                                                                      
##        whole milk}                => {soda} 0.013929842  0.1861413 0.074834774 1.0674634   137
## [329] {seasonal products}         => {soda} 0.002643620  0.1857143 0.014234875 1.0650146    26
## [330] {tropical fruit,                                                                        
##        whole milk}                => {soda} 0.007829181  0.1850962 0.042297916 1.0614698    77
## [331] {root vegetables,                                                                       
##        yogurt}                    => {soda} 0.004778851  0.1850394 0.025826131 1.0611441    47
## [332] {beverages}                 => {soda} 0.004778851  0.1835938 0.026029487 1.0528540    47
## [333] {newspapers}                => {soda} 0.014641586  0.1834395 0.079816980 1.0519693   144
## [334] {pip fruit,                                                                             
##        root vegetables}           => {soda} 0.002846975  0.1830065 0.015556685 1.0494865    28
## [335] {whole milk,                                                                            
##        yogurt,                                                                                
##        rolls/buns}                => {soda} 0.002846975  0.1830065 0.015556685 1.0494865    28
## [336] {other vegetables,                                                                      
##        frozen vegetables}         => {soda} 0.003253686  0.1828571 0.017793594 1.0486297    32
## [337] {whole milk,                                                                            
##        hygiene articles}          => {soda} 0.002338587  0.1825397 0.012811388 1.0468092    23
## [338] {grapes}                    => {soda} 0.004067107  0.1818182 0.022369090 1.0426716    40
## [339] {berries,                                                                               
##        whole milk}                => {soda} 0.002135231  0.1810345 0.011794611 1.0381773    21
## [340] {beef,                                                                                  
##        other vegetables}          => {soda} 0.003558719  0.1804124 0.019725470 1.0346097    35
## [341] {detergent}                 => {soda} 0.003457041  0.1798942 0.019217082 1.0316381    34
## [342] {frozen vegetables}         => {soda} 0.008642603  0.1797040 0.048093543 1.0305475    85
## [343] {whole milk,                                                                            
##        bottled beer}              => {soda} 0.003660397  0.1791045 0.020437214 1.0271094    36
## [344] {pip fruit,                                                                             
##        other vegetables}          => {soda} 0.004677173  0.1789883 0.026131164 1.0264433    46
## [345] {tropical fruit,                                                                        
##        root vegetables}           => {soda} 0.003762074  0.1787440 0.021047280 1.0250419    37
## [346] {onions,                                                                                
##        other vegetables}          => {soda} 0.002541942  0.1785714 0.014234875 1.0240525    25
## [347] {tropical fruit,                                                                        
##        other vegetables,                                                                      
##        whole milk}                => {soda} 0.003050330  0.1785714 0.017081851 1.0240525    30
## [348] {pork,                                                                                  
##        other vegetables}          => {soda} 0.003863752  0.1784038 0.021657346 1.0230909    38
## [349] {canned beer}               => {soda} 0.013828165  0.1780105 0.077681749 1.0208356   136
## [350] {other vegetables,                                                                      
##        cream cheese }             => {soda} 0.002440264  0.1777778 0.013726487 1.0195011    24
## [351] {other vegetables,                                                                      
##        butter}                    => {soda} 0.003558719  0.1776650 0.020030503 1.0188542    35
## [352] {yogurt,                                                                                
##        domestic eggs}             => {soda} 0.002541942  0.1773050 0.014336553 1.0167897    25
## [353] {onions,                                                                                
##        whole milk}                => {soda} 0.002135231  0.1764706 0.012099644 1.0120048    21
## [354] {pip fruit}                 => {soda} 0.013319776  0.1760753 0.075648195 1.0097378   131
## [355] {whole milk,                                                                            
##        newspapers}                => {soda} 0.004778851  0.1747212 0.027351296 1.0019725    47
## [356] {}                          => {soda} 0.174377224  0.1743772 1.000000000 1.0000000  1715
## [357] {hamburger meat}            => {soda} 0.005795628  0.1743119 0.033248602 0.9996255    57
## [358] {whole milk,                                                                            
##        coffee}                    => {soda} 0.003253686  0.1739130 0.018708693 0.9973381    32
## [359] {root vegetables,                                                                       
##        other vegetables}          => {soda} 0.008235892  0.1738197 0.047381800 0.9968030    81
## [360] {margarine}                 => {soda} 0.010167768  0.1736111 0.058566345 0.9956066   100
## [361] {citrus fruit,                                                                          
##        tropical fruit}            => {soda} 0.003457041  0.1734694 0.019928826 0.9947938    34
## [362] {whole milk,                                                                            
##        domestic eggs}             => {soda} 0.005185562  0.1728814 0.029994916 0.9914217    51
## [363] {citrus fruit,                                                                          
##        root vegetables}           => {soda} 0.003050330  0.1724138 0.017691917 0.9887403    30
## [364] {cream cheese }             => {soda} 0.006812405  0.1717949 0.039654296 0.9851910    67
## [365] {coffee}                    => {soda} 0.009964413  0.1716287 0.058057956 0.9842382    98
## [366] {root vegetables}           => {soda} 0.018607016  0.1707090 0.108998475 0.9789636   183
## [367] {onions}                    => {soda} 0.005287239  0.1704918 0.031011693 0.9777183    52
## [368] {chicken,                                                                               
##        other vegetables}          => {soda} 0.003050330  0.1704545 0.017895272 0.9775046    30
## [369] {whole milk,                                                                            
##        whipped/sour cream}        => {soda} 0.005490595  0.1703470 0.032231825 0.9768879    54
## [370] {other vegetables}          => {soda} 0.032740214  0.1692065 0.193492628 0.9703476   322
## [371] {other vegetables,                                                                      
##        whipped/sour cream}        => {soda} 0.004880529  0.1690141 0.028876462 0.9692440    48
## [372] {root vegetables,                                                                       
##        whole milk,                                                                            
##        yogurt}                    => {soda} 0.002440264  0.1678322 0.014539908 0.9624661    24
## [373] {oil}                       => {soda} 0.004677173  0.1666667 0.028063040 0.9557823    46
## [374] {root vegetables,                                                                       
##        whole milk}                => {soda} 0.008134215  0.1663202 0.048906965 0.9537952    80
## [375] {hard cheese}               => {soda} 0.004067107  0.1659751 0.024504321 0.9518164    40
## [376] {pip fruit,                                                                             
##        whole milk}                => {soda} 0.004982206  0.1655405 0.030096594 0.9493243    49
## [377] {root vegetables,                                                                       
##        butter}                    => {soda} 0.002135231  0.1653543 0.012913066 0.9482565    21
## [378] {tropical fruit,                                                                        
##        other vegetables,                                                                      
##        yogurt}                    => {soda} 0.002033554  0.1652893 0.012302999 0.9478833    20
## [379] {packaged fruit/vegetables} => {soda} 0.002135231  0.1640625 0.013014743 0.9408482    21
## [380] {citrus fruit,                                                                          
##        other vegetables,                                                                      
##        whole milk}                => {soda} 0.002135231  0.1640625 0.013014743 0.9408482    21
## [381] {flour}                     => {soda} 0.002846975  0.1637427 0.017386884 0.9390142    28
## [382] {butter milk}               => {soda} 0.004575496  0.1636364 0.027961362 0.9384045    45
## [383] {frankfurter,                                                                           
##        whole milk}                => {soda} 0.003355363  0.1633663 0.020538892 0.9368559    33
## [384] {beef,                                                                                  
##        whole milk}                => {soda} 0.003457041  0.1626794 0.021250635 0.9329167    34
## [385] {whipped/sour cream}        => {soda} 0.011591256  0.1617021 0.071682766 0.9273122   114
## [386] {soft cheese}               => {soda} 0.002745297  0.1607143 0.017081851 0.9216472    27
## [387] {butter,                                                                                
##        yogurt}                    => {soda} 0.002338587  0.1597222 0.014641586 0.9159580    23
## [388] {butter}                    => {soda} 0.008845958  0.1596330 0.055414337 0.9154465    87
## [389] {pot plants}                => {soda} 0.002745297  0.1588235 0.017285206 0.9108043    27
## [390] {whole milk}                => {soda} 0.040061007  0.1567847 0.255516014 0.8991124   394
## [391] {beef,                                                                                  
##        rolls/buns}                => {soda} 0.002135231  0.1567164 0.013624809 0.8987207    21
## [392] {whole milk,                                                                            
##        rolls/buns}                => {soda} 0.008845958  0.1561939 0.056634469 0.8957242    87
## [393] {whole milk,                                                                            
##        margarine}                 => {soda} 0.003762074  0.1554622 0.024199288 0.8915280    37
## [394] {beef}                      => {soda} 0.008134215  0.1550388 0.052465684 0.8890998    80
## [395] {citrus fruit}              => {soda} 0.012811388  0.1547912 0.082765633 0.8876799   126
## [396] {curd}                      => {soda} 0.008134215  0.1526718 0.053279105 0.8755258    80
## [397] {root vegetables,                                                                       
##        whipped/sour cream}        => {soda} 0.002541942  0.1488095 0.017081851 0.8533771    25
## [398] {citrus fruit,                                                                          
##        whole milk}                => {soda} 0.004473818  0.1466667 0.030503305 0.8410884    44
## [399] {citrus fruit,                                                                          
##        other vegetables}          => {soda} 0.004168785  0.1443662 0.028876462 0.8278959    41
## [400] {whole milk,                                                                            
##        frozen vegetables}         => {soda} 0.002948653  0.1442786 0.020437214 0.8273936    29
## [401] {whole milk,                                                                            
##        cream cheese }             => {soda} 0.002338587  0.1419753 0.016471784 0.8141849    23
## [402] {hamburger meat,                                                                        
##        whole milk}                => {soda} 0.002033554  0.1379310 0.014743264 0.7909923    20
## [403] {whole milk,                                                                            
##        curd}                      => {soda} 0.003558719  0.1361868 0.026131164 0.7809894    35
## [404] {other vegetables,                                                                      
##        margarine}                 => {soda} 0.002643620  0.1340206 0.019725470 0.7685672    26
## [405] {baking powder}             => {soda} 0.002338587  0.1321839 0.017691917 0.7580342    23
## [406] {dishes}                    => {soda} 0.002135231  0.1213873 0.017590239 0.6961189    21
## [407] {other vegetables,                                                                      
##        curd}                      => {soda} 0.002033554  0.1183432 0.017183528 0.6786620    20
## [408] {whole milk,                                                                            
##        butter}                    => {soda} 0.003050330  0.1107011 0.027554652 0.6348370    30

Você deve descobrir quais itens que os clientes compram junto com refrigerante, ou seja, que produtos são comprados depois de refrigerante?

regra_refri2 <- apriori(Groceries, parameter = list(supp= 0.002, conf=0.08),
                       appearance = list(default = "rhs", lhs = "soda"))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##        0.08    0.1    1 none FALSE            TRUE       5   0.002      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: 19 
## 
## set item appearances ...[1 item(s)] done [0.00s].
## set transactions ...[169 item(s), 9835 transaction(s)] done [0.01s].
## sorting and recoding items ... [147 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 done [0.01s].
## writing ... [25 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
inspect(regra_refri2)
##      lhs       rhs                     support    confidence coverage 
## [1]  {}     => {bottled beer}          0.08052872 0.08052872 1.0000000
## [2]  {}     => {pastry}                0.08896797 0.08896797 1.0000000
## [3]  {}     => {citrus fruit}          0.08276563 0.08276563 1.0000000
## [4]  {}     => {shopping bags}         0.09852567 0.09852567 1.0000000
## [5]  {}     => {sausage}               0.09395018 0.09395018 1.0000000
## [6]  {}     => {bottled water}         0.11052364 0.11052364 1.0000000
## [7]  {}     => {tropical fruit}        0.10493137 0.10493137 1.0000000
## [8]  {}     => {root vegetables}       0.10899847 0.10899847 1.0000000
## [9]  {}     => {yogurt}                0.13950178 0.13950178 1.0000000
## [10] {}     => {rolls/buns}            0.18393493 0.18393493 1.0000000
## [11] {}     => {other vegetables}      0.19349263 0.19349263 1.0000000
## [12] {}     => {whole milk}            0.25551601 0.25551601 1.0000000
## [13] {soda} => {bottled beer}          0.01698017 0.09737609 0.1743772
## [14] {soda} => {newspapers}            0.01464159 0.08396501 0.1743772
## [15] {soda} => {fruit/vegetable juice} 0.01840366 0.10553936 0.1743772
## [16] {soda} => {pastry}                0.02104728 0.12069971 0.1743772
## [17] {soda} => {shopping bags}         0.02460600 0.14110787 0.1743772
## [18] {soda} => {sausage}               0.02430097 0.13935860 0.1743772
## [19] {soda} => {bottled water}         0.02897814 0.16618076 0.1743772
## [20] {soda} => {tropical fruit}        0.02084392 0.11953353 0.1743772
## [21] {soda} => {root vegetables}       0.01860702 0.10670554 0.1743772
## [22] {soda} => {yogurt}                0.02735130 0.15685131 0.1743772
## [23] {soda} => {rolls/buns}            0.03833249 0.21982507 0.1743772
## [24] {soda} => {other vegetables}      0.03274021 0.18775510 0.1743772
## [25] {soda} => {whole milk}            0.04006101 0.22973761 0.1743772
##      lift      count
## [1]  1.0000000  792 
## [2]  1.0000000  875 
## [3]  1.0000000  814 
## [4]  1.0000000  969 
## [5]  1.0000000  924 
## [6]  1.0000000 1087 
## [7]  1.0000000 1032 
## [8]  1.0000000 1072 
## [9]  1.0000000 1372 
## [10] 1.0000000 1809 
## [11] 1.0000000 1903 
## [12] 1.0000000 2513 
## [13] 1.2092094  167 
## [14] 1.0519693  144 
## [15] 1.4598869  181 
## [16] 1.3566647  207 
## [17] 1.4321939  242 
## [18] 1.4833245  239 
## [19] 1.5035766  285 
## [20] 1.1391592  205 
## [21] 0.9789636  183 
## [22] 1.1243678  269 
## [23] 1.1951242  377 
## [24] 0.9703476  322 
## [25] 0.8991124  394
inspect(sort(regra_refri2, by = "lift"))
##      lhs       rhs                     support    confidence coverage 
## [1]  {soda} => {bottled water}         0.02897814 0.16618076 0.1743772
## [2]  {soda} => {sausage}               0.02430097 0.13935860 0.1743772
## [3]  {soda} => {fruit/vegetable juice} 0.01840366 0.10553936 0.1743772
## [4]  {soda} => {shopping bags}         0.02460600 0.14110787 0.1743772
## [5]  {soda} => {pastry}                0.02104728 0.12069971 0.1743772
## [6]  {soda} => {bottled beer}          0.01698017 0.09737609 0.1743772
## [7]  {soda} => {rolls/buns}            0.03833249 0.21982507 0.1743772
## [8]  {soda} => {tropical fruit}        0.02084392 0.11953353 0.1743772
## [9]  {soda} => {yogurt}                0.02735130 0.15685131 0.1743772
## [10] {soda} => {newspapers}            0.01464159 0.08396501 0.1743772
## [11] {}     => {yogurt}                0.13950178 0.13950178 1.0000000
## [12] {}     => {rolls/buns}            0.18393493 0.18393493 1.0000000
## [13] {}     => {bottled beer}          0.08052872 0.08052872 1.0000000
## [14] {}     => {pastry}                0.08896797 0.08896797 1.0000000
## [15] {}     => {citrus fruit}          0.08276563 0.08276563 1.0000000
## [16] {}     => {shopping bags}         0.09852567 0.09852567 1.0000000
## [17] {}     => {sausage}               0.09395018 0.09395018 1.0000000
## [18] {}     => {bottled water}         0.11052364 0.11052364 1.0000000
## [19] {}     => {tropical fruit}        0.10493137 0.10493137 1.0000000
## [20] {}     => {root vegetables}       0.10899847 0.10899847 1.0000000
## [21] {}     => {other vegetables}      0.19349263 0.19349263 1.0000000
## [22] {}     => {whole milk}            0.25551601 0.25551601 1.0000000
## [23] {soda} => {root vegetables}       0.01860702 0.10670554 0.1743772
## [24] {soda} => {other vegetables}      0.03274021 0.18775510 0.1743772
## [25] {soda} => {whole milk}            0.04006101 0.22973761 0.1743772
##      lift      count
## [1]  1.5035766  285 
## [2]  1.4833245  239 
## [3]  1.4598869  181 
## [4]  1.4321939  242 
## [5]  1.3566647  207 
## [6]  1.2092094  167 
## [7]  1.1951242  377 
## [8]  1.1391592  205 
## [9]  1.1243678  269 
## [10] 1.0519693  144 
## [11] 1.0000000 1372 
## [12] 1.0000000 1809 
## [13] 1.0000000  792 
## [14] 1.0000000  875 
## [15] 1.0000000  814 
## [16] 1.0000000  969 
## [17] 1.0000000  924 
## [18] 1.0000000 1087 
## [19] 1.0000000 1032 
## [20] 1.0000000 1072 
## [21] 1.0000000 1903 
## [22] 1.0000000 2513 
## [23] 0.9789636  183 
## [24] 0.9703476  322 
## [25] 0.8991124  394

Visualização gráfica das regras criadas

library(arulesViz)
## Warning: package 'arulesViz' was built under R version 4.0.5
plot(regra3_seg1, method = "graph")

plot(regra3_seg2, method = "graph")

Exercício: Agora que sabemos como gerar regras, a rede varejista Vende Tudo deseja segmentar alguns produtos(usando a base Groceries). Ela quer saber o que os clientes compram depois de comprar beef. Você encontrará algumas regras com um suporte de 0.001 e com confiança de 0.19, e deve mostrar os resultados da regras geradas de forma gráfica.

Regras <-apriori(data=Groceries, parameter=list(supp=0.001,conf = 0.19,minlen=2),
               appearance = list(default="rhs",lhs="beef"),
               control = list(verbose=F))
summary(Regras)
## set of 5 rules
## 
## rule length distribution (lhs + rhs):sizes
## 2 
## 5 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       2       2       2       2       2       2 
## 
## summary of quality measures:
##     support          confidence        coverage            lift      
##  Min.   :0.01169   Min.   :0.2229   Min.   :0.05247   Min.   :1.412  
##  1st Qu.:0.01362   1st Qu.:0.2597   1st Qu.:0.05247   1st Qu.:1.585  
##  Median :0.01739   Median :0.3314   Median :0.05247   Median :1.598  
##  Mean   :0.01674   Mean   :0.3190   Mean   :0.05247   Mean   :1.916  
##  3rd Qu.:0.01973   3rd Qu.:0.3760   3rd Qu.:0.05247   3rd Qu.:1.943  
##  Max.   :0.02125   Max.   :0.4050   Max.   :0.05247   Max.   :3.040  
##      count      
##  Min.   :115.0  
##  1st Qu.:134.0  
##  Median :171.0  
##  Mean   :164.6  
##  3rd Qu.:194.0  
##  Max.   :209.0  
## 
## mining info:
##       data ntransactions support confidence
##  Groceries          9835   0.001       0.19
inspect(Regras [1:5])
##     lhs       rhs                support    confidence coverage   lift    
## [1] {beef} => {root vegetables}  0.01738688 0.3313953  0.05246568 3.040367
## [2] {beef} => {yogurt}           0.01169293 0.2228682  0.05246568 1.597601
## [3] {beef} => {rolls/buns}       0.01362481 0.2596899  0.05246568 1.411858
## [4] {beef} => {other vegetables} 0.01972547 0.3759690  0.05246568 1.943066
## [5] {beef} => {whole milk}       0.02125064 0.4050388  0.05246568 1.585180
##     count
## [1] 171  
## [2] 115  
## [3] 134  
## [4] 194  
## [5] 209
plot(Regras, method = "graph")