Market Basket Analysis

Instalar paquetes y llamar librerias

library(plyr)
library(Matrix)
library(arules)
## 
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
library(arulesViz)
library(datasets)

Importar la base de datos

bd_limpia <- read.csv("C:\\Users\\mari0\\OneDrive\\Documents\\R Studio\\Bases de datos\\abarrotes_bdlimpia.csv")

Ordenar de menor a mayor los tickets

bd_limpia <- bd_limpia[order(bd_limpia$F.Ticket),]
head(bd_limpia)
##   vcClaveTienda  DescGiro      Fecha Hora                      Marca
## 1         MX001 Abarrotes 2020-06-19    8                NUTRI LECHE
## 2         MX001 Abarrotes 2020-06-19    8                     DAN UP
## 3         MX001 Abarrotes 2020-06-19    8                      BIMBO
## 4         MX001 Abarrotes 2020-06-19    8                      PEPSI
## 5         MX001 Abarrotes 2020-06-19    8 BLANCA NIEVES (DETERGENTE)
## 6         MX001 Abarrotes 2020-06-19    8                      FLASH
##                   Fabricante                           Producto Precio
## 1                    MEXILAC                Nutri Leche 1 Litro   16.0
## 2           DANONE DE MEXICO DANUP STRAWBERRY P/BEBER 350GR NAL   14.0
## 3                GRUPO BIMBO                Rebanadas Bimbo 2Pz    5.0
## 4        PEPSI-COLA MEXICANA                   Pepsi N.R. 400Ml    8.0
## 5 FABRICA DE JABON LA CORONA      Detergente Blanca Nieves 500G   19.5
## 6                       ALEN      Flash Xtra Brisa Marina 500Ml    9.5
##   Ult.Costo Unidades F.Ticket NombreDepartamento          NombreFamilia
## 1     12.31        1        1          Abarrotes Lacteos y Refrigerados
## 2     14.00        1        2          Abarrotes Lacteos y Refrigerados
## 3      5.00        1        3          Abarrotes         Pan y Tortilla
## 4      8.00        1        3          Abarrotes                Bebidas
## 5     15.00        1        4          Abarrotes     Limpieza del Hogar
## 6      7.31        1        4          Abarrotes     Limpieza del Hogar
##             NombreCategoria     Estado Mts.2 Tipo.ubicación      Giro
## 1                     Leche Nuevo León    60        Esquina Abarrotes
## 2                    Yogurt Nuevo León    60        Esquina Abarrotes
## 3     Pan Dulce Empaquetado Nuevo León    60        Esquina Abarrotes
## 4 Refrescos Plástico (N.R.) Nuevo León    60        Esquina Abarrotes
## 5                Lavandería Nuevo León    60        Esquina Abarrotes
## 6      Limpiadores Líquidos Nuevo León    60        Esquina Abarrotes
##   Hora.inicio Hora.cierre diadelasemana subtotal
## 1       08:00       22:00             6     16.0
## 2       08:00       22:00             6     14.0
## 3       08:00       22:00             6      5.0
## 4       08:00       22:00             6      8.0
## 5       08:00       22:00             6     19.5
## 6       08:00       22:00             6      9.5
tail(bd_limpia)
##        vcClaveTienda   DescGiro      Fecha Hora          Marca
## 107247         MX004 Carnicería 2020-10-15   11         YEMINA
## 167624         MX004 Carnicería 2020-10-15   11     DEL FUERTE
## 149282         MX004 Carnicería 2020-10-15   11 COCA COLA ZERO
## 168603         MX004 Carnicería 2020-10-15   11       DIAMANTE
## 161046         MX004 Carnicería 2020-10-15   12          PEPSI
## 112823         MX004 Carnicería 2020-10-15   12      COCA COLA
##                  Fabricante                       Producto Precio Ult.Costo
## 107247               HERDEZ    PASTA SPAGHETTI YEMINA 200G      7      5.38
## 167624 ALIMENTOS DEL FUERTE PURE DE TOMATE DEL FUERTE 345G     12      9.23
## 149282            COCA COLA           COCA COLA ZERO 600ML     15     11.54
## 168603           EMPACADOS              ARROZ DIAMANTE225G     11      8.46
## 161046  PEPSI-COLA MEXICANA              PEPSI N. R. 500ML     10      7.69
## 112823            COCA COLA     COCA COLA RETORNABLE 500ML     10      7.69
##        Unidades F.Ticket NombreDepartamento        NombreFamilia
## 107247        2   450032          Abarrotes       Sopas y Pastas
## 167624        1   450032          Abarrotes Salsas y Sazonadores
## 149282        2   450034          Abarrotes              Bebidas
## 168603        1   450037          Abarrotes    Granos y Semillas
## 161046        1   450039          Abarrotes              Bebidas
## 112823        8   450040          Abarrotes              Bebidas
##                      NombreCategoria  Estado Mts.2 Tipo.ubicación      Giro
## 107247 Fideos, Spaguetti, Tallarines Sinaloa    53        Esquina Abarrotes
## 167624          Salsa para Spaguetti Sinaloa    53        Esquina Abarrotes
## 149282         Refrescos Retornables Sinaloa    53        Esquina Abarrotes
## 168603                         Arroz Sinaloa    53        Esquina Abarrotes
## 161046     Refrescos Plástico (N.R.) Sinaloa    53        Esquina Abarrotes
## 112823         Refrescos Retornables Sinaloa    53        Esquina Abarrotes
##        Hora.inicio Hora.cierre diadelasemana subtotal
## 107247       07:00       23:00             5       14
## 167624       07:00       23:00             5       12
## 149282       07:00       23:00             5       30
## 168603       07:00       23:00             5       11
## 161046       07:00       23:00             5       10
## 112823       07:00       23:00             5       80

Extraer productos por ticket

basket <- ddply(bd_limpia, c("F.Ticket"), function (bd_limpia)paste(bd_limpia$Marca,collapse = ","))

Eliminar numero de ticket

basket$F.Ticket <- NULL

Renombrar el nombre de la columna marca

colnames(basket) <- c("Marca")

Exportar basket

write.csv(basket,"basket.csv", quote = FALSE, row.names = FALSE)

Importar transacciones

tr <- read.transactions("C:\\Users\\mari0\\OneDrive\\Documents\\R Studio\\Bases de datos\\basket.csv", format= "basket", sep =",")
## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string

## Warning in scan(text = l, what = "character", sep = sep, quote = quote, : EOF
## within quoted string
## Warning in asMethod(object): removing duplicated items in transactions

Generar reglas de asociacion

reglas_asociacion <- apriori(tr, parameter = list(supp=0.001, conf=0.2, maxlen=10)) #nivel de confianza, regla de asociacion
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##         0.2    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: 115 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[604 item(s), 115031 transaction(s)] done [0.04s].
## sorting and recoding items ... [207 item(s)] done [0.00s].
## creating transaction tree ... done [0.04s].
## checking subsets of size 1 2 3 done [0.00s].
## writing ... [11 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].
summary(reglas_asociacion)
## set of 11 rules
## 
## rule length distribution (lhs + rhs):sizes
##  2 
## 11 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       2       2       2       2       2       2 
## 
## summary of quality measures:
##     support           confidence        coverage             lift       
##  Min.   :0.001017   Min.   :0.2069   Min.   :0.003564   Min.   : 1.326  
##  1st Qu.:0.001104   1st Qu.:0.2358   1st Qu.:0.004507   1st Qu.: 1.789  
##  Median :0.001417   Median :0.2442   Median :0.005807   Median : 3.972  
##  Mean   :0.001521   Mean   :0.2537   Mean   :0.006056   Mean   :17.558  
##  3rd Qu.:0.001652   3rd Qu.:0.2685   3rd Qu.:0.006894   3rd Qu.:21.808  
##  Max.   :0.002747   Max.   :0.3098   Max.   :0.010502   Max.   :65.862  
##      count      
##  Min.   :117.0  
##  1st Qu.:127.0  
##  Median :163.0  
##  Mean   :174.9  
##  3rd Qu.:190.0  
##  Max.   :316.0  
## 
## mining info:
##  data ntransactions support confidence
##    tr        115031   0.001        0.2
##                                                                         call
##  apriori(data = tr, parameter = list(supp = 0.001, conf = 0.2, maxlen = 10))
inspect(reglas_asociacion)
##      lhs                  rhs         support     confidence coverage   
## [1]  {FANTA}           => {COCA COLA} 0.001051890 0.2439516  0.004311881
## [2]  {SALVO}           => {FABULOSO}  0.001104050 0.3097561  0.003564257
## [3]  {FABULOSO}        => {SALVO}     0.001104050 0.2347505  0.004703080
## [4]  {COCA COLA ZERO}  => {COCA COLA} 0.001417009 0.2969035  0.004772627
## [5]  {SPRITE}          => {COCA COLA} 0.001347463 0.2069426  0.006511288
## [6]  {PINOL}           => {CLORALEX}  0.001017117 0.2368421  0.004294495
## [7]  {BLUE HOUSE}      => {BIMBO}     0.001712582 0.2720994  0.006293956
## [8]  {HELLMANN´S}      => {BIMBO}     0.001538716 0.2649701  0.005807130
## [9]  {REYMA}           => {CONVERMEX} 0.002095087 0.2441743  0.008580296
## [10] {FUD}             => {BIMBO}     0.001590876 0.2186380  0.007276299
## [11] {COCA COLA LIGHT} => {COCA COLA} 0.002747086 0.2615894  0.010501517
##      lift      count
## [1]   1.562646 121  
## [2]  65.862391 127  
## [3]  65.862391 127  
## [4]   1.901832 163  
## [5]   1.325583 155  
## [6]  25.063647 117  
## [7]   4.078691 197  
## [8]   3.971823 177  
## [9]  18.551922 241  
## [10]  3.277319 183  
## [11]  1.675626 316
reglas_asociacion <- sort(reglas_asociacion, by="confidence", decreasing = TRUE)
summary(reglas_asociacion)
## set of 11 rules
## 
## rule length distribution (lhs + rhs):sizes
##  2 
## 11 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       2       2       2       2       2       2 
## 
## summary of quality measures:
##     support           confidence        coverage             lift       
##  Min.   :0.001017   Min.   :0.2069   Min.   :0.003564   Min.   : 1.326  
##  1st Qu.:0.001104   1st Qu.:0.2358   1st Qu.:0.004507   1st Qu.: 1.789  
##  Median :0.001417   Median :0.2442   Median :0.005807   Median : 3.972  
##  Mean   :0.001521   Mean   :0.2537   Mean   :0.006056   Mean   :17.558  
##  3rd Qu.:0.001652   3rd Qu.:0.2685   3rd Qu.:0.006894   3rd Qu.:21.808  
##  Max.   :0.002747   Max.   :0.3098   Max.   :0.010502   Max.   :65.862  
##      count      
##  Min.   :117.0  
##  1st Qu.:127.0  
##  Median :163.0  
##  Mean   :174.9  
##  3rd Qu.:190.0  
##  Max.   :316.0  
## 
## mining info:
##  data ntransactions support confidence
##    tr        115031   0.001        0.2
##                                                                         call
##  apriori(data = tr, parameter = list(supp = 0.001, conf = 0.2, maxlen = 10))
inspect(reglas_asociacion)
##      lhs                  rhs         support     confidence coverage   
## [1]  {SALVO}           => {FABULOSO}  0.001104050 0.3097561  0.003564257
## [2]  {COCA COLA ZERO}  => {COCA COLA} 0.001417009 0.2969035  0.004772627
## [3]  {BLUE HOUSE}      => {BIMBO}     0.001712582 0.2720994  0.006293956
## [4]  {HELLMANN´S}      => {BIMBO}     0.001538716 0.2649701  0.005807130
## [5]  {COCA COLA LIGHT} => {COCA COLA} 0.002747086 0.2615894  0.010501517
## [6]  {REYMA}           => {CONVERMEX} 0.002095087 0.2441743  0.008580296
## [7]  {FANTA}           => {COCA COLA} 0.001051890 0.2439516  0.004311881
## [8]  {PINOL}           => {CLORALEX}  0.001017117 0.2368421  0.004294495
## [9]  {FABULOSO}        => {SALVO}     0.001104050 0.2347505  0.004703080
## [10] {FUD}             => {BIMBO}     0.001590876 0.2186380  0.007276299
## [11] {SPRITE}          => {COCA COLA} 0.001347463 0.2069426  0.006511288
##      lift      count
## [1]  65.862391 127  
## [2]   1.901832 163  
## [3]   4.078691 197  
## [4]   3.971823 177  
## [5]   1.675626 316  
## [6]  18.551922 241  
## [7]   1.562646 121  
## [8]  25.063647 117  
## [9]  65.862391 127  
## [10]  3.277319 183  
## [11]  1.325583 155
top10reglas <- head(reglas_asociacion, n=10, by="confidence")
plot(top10reglas, method="graph", engine="htmlwidget")

Estrategias de negocios 1.- Asignar marcas cerca en el anaquel: Salvo & Fabuloso… 2.- Aplicar promociones en marcas gancho : Reyma, Pinol, Queso/Jamon/Mayonesa, Zero/Light/Fanta. 3.- Realizar Business Case para venta de sandwiches preparados.

LS0tDQp0aXRsZTogIk1hcmtldCBCYXNrZXQgQW5hbHlzaXMgQWJhcnJvdGVzIg0KYXV0aG9yOiAiTWFyaWFuYSBSYW3DrXJleiBSYW1vcyAtIEEwMTE3NDE1NSINCm91dHB1dDogDQogIGh0bWxfZG9jdW1lbnQ6DQogICAgdG9jOiB0cnVlDQogICAgdG9jX2Zsb2F0OiB0cnVlDQogICAgY29kZV9kb3dubG9hZDogdHJ1ZQ0KLS0tDQoNCiFbXShDOlxcVXNlcnNcXG1hcmkwXFxEb3dubG9hZHNcXHRpZW5kaXRhLnBuZykNCg0KIyMgTWFya2V0IEJhc2tldCBBbmFseXNpcw0KDQoqKkluc3RhbGFyIHBhcXVldGVzIHkgbGxhbWFyIGxpYnJlcmlhcyoqDQpgYGB7cn0NCmxpYnJhcnkocGx5cikNCmxpYnJhcnkoTWF0cml4KQ0KbGlicmFyeShhcnVsZXMpDQpsaWJyYXJ5KGFydWxlc1ZpeikNCmxpYnJhcnkoZGF0YXNldHMpDQpgYGANCg0KKipJbXBvcnRhciBsYSBiYXNlIGRlIGRhdG9zKioNCg0KYGBge3J9DQpiZF9saW1waWEgPC0gcmVhZC5jc3YoIkM6XFxVc2Vyc1xcbWFyaTBcXE9uZURyaXZlXFxEb2N1bWVudHNcXFIgU3R1ZGlvXFxCYXNlcyBkZSBkYXRvc1xcYWJhcnJvdGVzX2JkbGltcGlhLmNzdiIpDQpgYGANCg0KKipPcmRlbmFyIGRlIG1lb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