Teoría

El Market Basket Analysis es una tecnica en el ambito de analisis y mineria de datos en el campo del comercio. Su objetivo principal es descubrir patrones de asociación entre productos que suelen ser comprados juntos por los clientes.

Las 3 métricas principales para evaluar reglas de asosiación son:

  • Confidence(Confianza): Probabilidad de comprar B sabiendo que se compró A. Ej. Pan –> Mantequilla 0.8 De cada 100 clientes que compraron pan, 80 compraron mantequilla también.
  • Lift (Elevación): Cuánto más probable es comprar B cuando se compra A en comparación de la probabilidad de comprar B sin saber si se compró A. Ej. Lift > 1 Compra A impulsa B. Lift = 1 No tienen relación de compra. Lift < 1 A reduce la compra de B.
  • Support (Soporte): Popularidad del producto dentro de las transacciones. Ej. Pan y Mantequilla 0.05 El 5% de todas las transacciones compraron estos dos productos juntos.

Una cadena de tiendas de conveniencia tiene 5 tiendas ubicadas en distintas ciudades de México. La base de datos “abarrotes” contiene 1 mes de transacciones, pero presenta errores de calidad que impiden realizar análisis confiables. El objetivo es limpiar la base de datos de forma estratégica y posteriormente aplicar MBA para descubrir patrones de venta y diseñar promociones que aumenten las ventas.

Instalar paquetes y llamar librerías

# install.packages("tidyverse") # Paquete global para manipulación y análisis de datos
library(tidyverse)
# install.packages("janitor") # Examinar y limpiar bases de datos sucias
library(janitor)
# install.packages("Matrix") # Para trabajar con matrices
library(Matrix)
#install.packages("arules") # Genera reglas de asociación
library(arules)
#install.packages("arulesViz") # Visualizar reglas de asociación
library(arulesViz)

Importar la base de datos

# file.choose()
df <- read.csv("Desktop/abarrotes.csv")

Entender la base de datos

summary(df)
##     ClaveTienda          DescGiro      Codigo.Barras            PLU        
##  Length   :200625   Length   :200625   Min.   :8.347e+05   Min.   : 1.000  
##  N.unique :     5   N.unique :     3   1st Qu.:7.501e+12   1st Qu.: 1.000  
##  N.blank  :     0   N.blank  :     0   Median :7.501e+12   Median : 1.000  
##  Min.nchar:     5   Min.nchar:     8   Mean   :5.950e+12   Mean   : 2.112  
##  Max.nchar:     5   Max.nchar:    10   3rd Qu.:7.501e+12   3rd Qu.: 1.000  
##                                        Max.   :1.750e+13   Max.   :30.000  
##                                                            NAs    :199188  
##        Fecha               Hora              Marca            Fabricante    
##  Length   :200625   Length   :200625   Length   :200625   Length   :200625  
##  N.unique :   195   N.unique : 52145   N.unique :   540   N.unique :   241  
##  N.blank  :     0   N.blank  :     0   N.blank  :     0   N.blank  :     0  
##  Min.nchar:    10   Min.nchar:     8   Min.nchar:     3   Min.nchar:     3  
##  Max.nchar:    10   Max.nchar:     8   Max.nchar:    30   Max.nchar:    40  
##                                                                             
##                                                                             
##       Producto          Precio          Ult.Costo         Unidades     
##  Length   :200625   Min.   :-147.00   Min.   :  0.38   Min.   : 0.200  
##  N.unique :  3406   1st Qu.:  11.00   1st Qu.:  8.46   1st Qu.: 1.000  
##  N.blank  :     0   Median :  16.00   Median : 12.31   Median : 1.000  
##  Min.nchar:     4   Mean   :  19.42   Mean   : 15.31   Mean   : 1.262  
##  Max.nchar:    40   3rd Qu.:  25.00   3rd Qu.: 19.23   3rd Qu.: 1.000  
##                     Max.   :1000.00   Max.   :769.23   Max.   :96.000  
##                                                                        
##     F.Ticket      NombreDepartamento   NombreFamilia     NombreCategoria  
##  Min.   :     1   Length   :200625   Length   :200625   Length   :200625  
##  1st Qu.: 33964   N.unique :     9   N.unique :    51   N.unique :   174  
##  Median :105993   N.blank  :     0   N.blank  :     0   N.blank  :     0  
##  Mean   :193990   Min.nchar:     6   Min.nchar:     3   Min.nchar:     2  
##  3rd Qu.:383005   Max.nchar:    20   Max.nchar:    25   Max.nchar:    37  
##  Max.   :450040                                                           
##                                                                           
##        Estado           Mts.2        Tipo.ubicación          Giro       
##  Length   :200625   Min.   :47.0   Length   :200625   Length   :200625  
##  N.unique :     5   1st Qu.:53.0   N.unique :     3   N.unique :     2  
##  N.blank  :     0   Median :60.0   N.blank  :     0   N.blank  :     0  
##  Min.nchar:     7   Mean   :56.6   Min.nchar:     7   Min.nchar:     9  
##  Max.nchar:    12   3rd Qu.:60.0   Max.nchar:    12   Max.nchar:    10  
##                     Max.   :62.0                                        
##                                                                         
##     Hora.inicio        Hora.cierre    
##  Length   :200625   Length   :200625  
##  N.unique :     3   N.unique :     3  
##  N.blank  :     0   N.blank  :     0  
##  Min.nchar:     5   Min.nchar:     5  
##  Max.nchar:     5   Max.nchar:     5  
##                                       
## 
str(df)
## 'data.frame':    200625 obs. of  22 variables:
##  $ ClaveTienda       : chr  "MX001" "MX001" "MX001" "MX001" ...
##  $ DescGiro          : chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ Codigo.Barras     : num  7.5e+12 7.5e+12 7.5e+12 7.5e+12 7.5e+12 ...
##  $ PLU               : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ Fecha             : chr  "19/06/2020" "19/06/2020" "19/06/2020" "19/06/2020" ...
##  $ Hora              : chr  "08:16:21" "08:23:33" "08:24:33" "08:24:33" ...
##  $ Marca             : chr  "NUTRI LECHE" "DAN UP" "BIMBO" "PEPSI" ...
##  $ Fabricante        : chr  "MEXILAC" "DANONE DE MEXICO" "GRUPO BIMBO" "PEPSI-COLA MEXICANA" ...
##  $ Producto          : chr  "Nutri Leche 1 Litro" "DANUP STRAWBERRY P/BEBER 350GR NAL" "Rebanadas Bimbo 2Pz" "Pepsi N.R. 400Ml" ...
##  $ Precio            : num  16 14 5 8 19.5 16 14 5 8 19.5 ...
##  $ Ult.Costo         : num  12.3 14 5 8 15 ...
##  $ Unidades          : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ F.Ticket          : int  1 2 3 3 4 1 2 3 3 4 ...
##  $ NombreDepartamento: chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ NombreFamilia     : chr  "Lacteos y Refrigerados" "Lacteos y Refrigerados" "Pan y Tortilla" "Bebidas" ...
##  $ NombreCategoria   : chr  "Leche" "Yogurt" "Pan Dulce Empaquetado" "Refrescos Plástico (N.R.)" ...
##  $ Estado            : chr  "Nuevo León" "Nuevo León" "Nuevo León" "Nuevo León" ...
##  $ Mts.2             : int  60 60 60 60 60 60 60 60 60 60 ...
##  $ Tipo.ubicación    : chr  "Esquina" "Esquina" "Esquina" "Esquina" ...
##  $ Giro              : chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ Hora.inicio       : chr  "08:00" "08:00" "08:00" "08:00" ...
##  $ Hora.cierre       : chr  "22:00" "22:00" "22:00" "22:00" ...
# count(df, ClaveTienda, sort=TRUE)
# count(df, DescGiro, sort=TRUE)
# count(df, Fecha, sort=TRUE)
# count(df, Hora, sort=TRUE)
# count(df, Marca, sort=TRUE)
# count(df, Fabricante, sort=TRUE)
# count(df, Producto, sort=TRUE)
# count(df, NombreDepartamento, sort=TRUE)
# count(df, NombreFamilia, sort=TRUE)
# count(df, NombreCategoria, sort=TRUE)
# count(df, Estado, sort=TRUE)
# count(df, Tipo.ubicación, sort=TRUE)
# count(df, Giro, sort=TRUE)
# count(df, Hora.inicio, sort=TRUE)
# count(df, Hora.cierre, sort=TRUE)
head(df,10)
##    ClaveTienda  DescGiro Codigo.Barras PLU      Fecha     Hora
## 1        MX001 Abarrotes  7.501021e+12  NA 19/06/2020 08:16:21
## 2        MX001 Abarrotes  7.501032e+12  NA 19/06/2020 08:23:33
## 3        MX001 Abarrotes  7.501000e+12  NA 19/06/2020 08:24:33
## 4        MX001 Abarrotes  7.501031e+12  NA 19/06/2020 08:24:33
## 5        MX001 Abarrotes  7.501026e+12  NA 19/06/2020 08:26:28
## 6        MX001 Abarrotes  7.501021e+12  NA 19/06/2020 08:16:21
## 7        MX001 Abarrotes  7.501032e+12  NA 19/06/2020 08:23:33
## 8        MX001 Abarrotes  7.501000e+12  NA 19/06/2020 08:24:33
## 9        MX001 Abarrotes  7.501031e+12  NA 19/06/2020 08:24:33
## 10       MX001 Abarrotes  7.501026e+12  NA 19/06/2020 08:26:28
##                         Marca                 Fabricante
## 1                 NUTRI LECHE                    MEXILAC
## 2                      DAN UP           DANONE DE MEXICO
## 3                       BIMBO                GRUPO BIMBO
## 4                       PEPSI        PEPSI-COLA MEXICANA
## 5  BLANCA NIEVES (DETERGENTE) FABRICA DE JABON LA CORONA
## 6                 NUTRI LECHE                    MEXILAC
## 7                      DAN UP           DANONE DE MEXICO
## 8                       BIMBO                GRUPO BIMBO
## 9                       PEPSI        PEPSI-COLA MEXICANA
## 10 BLANCA NIEVES (DETERGENTE) FABRICA DE JABON LA CORONA
##                              Producto Precio Ult.Costo Unidades F.Ticket
## 1                 Nutri Leche 1 Litro   16.0     12.31        1        1
## 2  DANUP STRAWBERRY P/BEBER 350GR NAL   14.0     14.00        1        2
## 3                 Rebanadas Bimbo 2Pz    5.0      5.00        1        3
## 4                    Pepsi N.R. 400Ml    8.0      8.00        1        3
## 5       Detergente Blanca Nieves 500G   19.5     15.00        1        4
## 6                 Nutri Leche 1 Litro   16.0     12.31        1        1
## 7  DANUP STRAWBERRY P/BEBER 350GR NAL   14.0     14.00        1        2
## 8                 Rebanadas Bimbo 2Pz    5.0      5.00        1        3
## 9                    Pepsi N.R. 400Ml    8.0      8.00        1        3
## 10      Detergente Blanca Nieves 500G   19.5     15.00        1        4
##    NombreDepartamento          NombreFamilia           NombreCategoria
## 1           Abarrotes Lacteos y Refrigerados                     Leche
## 2           Abarrotes Lacteos y Refrigerados                    Yogurt
## 3           Abarrotes         Pan y Tortilla     Pan Dulce Empaquetado
## 4           Abarrotes                Bebidas Refrescos Plástico (N.R.)
## 5           Abarrotes     Limpieza del Hogar                Lavandería
## 6           Abarrotes Lacteos y Refrigerados                     Leche
## 7           Abarrotes Lacteos y Refrigerados                    Yogurt
## 8           Abarrotes         Pan y Tortilla     Pan Dulce Empaquetado
## 9           Abarrotes                Bebidas Refrescos Plástico (N.R.)
## 10          Abarrotes     Limpieza del Hogar                Lavandería
##        Estado Mts.2 Tipo.ubicación      Giro Hora.inicio Hora.cierre
## 1  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 2  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 3  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 4  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 5  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 6  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 7  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 8  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 9  Nuevo León    60        Esquina Abarrotes       08:00       22:00
## 10 Nuevo León    60        Esquina Abarrotes       08:00       22:00
tail(df,10)
##        ClaveTienda DescGiro Codigo.Barras PLU      Fecha     Hora
## 200616       MX005 Depósito   7.62221e+12  NA 07/08/2020 19:30:13
## 200617       MX005 Depósito   7.62221e+12  NA 25/07/2020 18:42:24
## 200618       MX005 Depósito   7.62221e+12  NA 18/07/2020 22:45:58
## 200619       MX005 Depósito   7.62221e+12  NA 12/07/2020 00:36:34
## 200620       MX005 Depósito   7.62221e+12  NA 12/07/2020 01:08:25
## 200621       MX005 Depósito   7.62221e+12  NA 23/10/2020 22:17:37
## 200622       MX005 Depósito   7.62221e+12  NA 10/10/2020 20:30:20
## 200623       MX005 Depósito   7.62221e+12  NA 10/10/2020 22:40:43
## 200624       MX005 Depósito   7.62221e+12  NA 27/06/2020 22:30:19
## 200625       MX005 Depósito   7.62221e+12  NA 26/06/2020 23:43:34
##                    Marca    Fabricante                          Producto Precio
## 200616 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200617 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200618 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200619 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200620 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200621 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200622 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200623 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200624 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
## 200625 TRIDENT XTRA CARE CADBURY ADAMS Trident Xtracare Freshmint 16.32G      9
##        Ult.Costo Unidades F.Ticket NombreDepartamento NombreFamilia
## 200616      6.92        1   106411          Abarrotes      Dulcería
## 200617      6.92        1   104693          Abarrotes      Dulcería
## 200618      6.92        1   103856          Abarrotes      Dulcería
## 200619      6.92        1   103087          Abarrotes      Dulcería
## 200620      6.92        1   103100          Abarrotes      Dulcería
## 200621      6.92        1   116598          Abarrotes      Dulcería
## 200622      6.92        1   114886          Abarrotes      Dulcería
## 200623      6.92        1   114955          Abarrotes      Dulcería
## 200624      6.92        1   101121          Abarrotes      Dulcería
## 200625      6.92        1   100879          Abarrotes      Dulcería
##        NombreCategoria       Estado Mts.2 Tipo.ubicación       Giro Hora.inicio
## 200616 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200617 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200618 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200619 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200620 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200621 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200622 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200623 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200624 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
## 200625 Gomas de Mazcar Quintana Roo    58        Esquina Mini súper       08:00
##        Hora.cierre
## 200616       21:00
## 200617       21:00
## 200618       21:00
## 200619       21:00
## 200620       21:00
## 200621       21:00
## 200622       21:00
## 200623       21:00
## 200624       21:00
## 200625       21:00
# Tabla de Tienda y Departamento
tabyl(df, ClaveTienda, NombreDepartamento)
##  ClaveTienda Abarrotes Bebes e Infantiles Carnes Farmacia Ferretería Mercería
##        MX001     95415                515      1      147        245       28
##        MX002      6590                 21      0        4         10        0
##        MX003      4026                 15      0        2          8        0
##        MX004     82234                932      0      102        114       16
##        MX005     10014                  0      0        0          0        0
##  Papelería Productos a Eliminar Vinos y Licores
##         35                    3              80
##          0                    0               4
##          0                    0               0
##         32                    5              20
##          7                    0               0
# Tabla de Estado y Hora de Inicio
tabyl(df, Estado, Hora.inicio)
##        Estado 07:00 08:00 09:00
##       Chiapas  4051     0     0
##       Jalisco     0     0  6629
##    Nuevo León     0 96469     0
##  Quintana Roo     0 10021     0
##       Sinaloa 83455     0     0

Limpiar la base de datos

Técnica 1. Eliminar valores irrelevantes

# Eliminar columnas
df <- subset(df, select=-c(PLU))

# Eliminar renglones
df <- df[df$Precio>0, ]

Técnica 2. Eliminar valores repetidos

df <- distinct(df)

Técnica 3. Corregir errores tipográficos y similares

df$Unidades <- ceiling(df$Unidades)
summary(df)
##     ClaveTienda          DescGiro      Codigo.Barras             Fecha       
##  Length   :200473   Length   :200473   Min.   :8.347e+05   Length   :200473  
##  N.unique :     5   N.unique :     3   1st Qu.:7.501e+12   N.unique :   195  
##  N.blank  :     0   N.blank  :     0   Median :7.501e+12   N.blank  :     0  
##  Min.nchar:     5   Min.nchar:     8   Mean   :5.950e+12   Min.nchar:    10  
##  Max.nchar:     5   Max.nchar:    10   3rd Qu.:7.501e+12   Max.nchar:    10  
##                                        Max.   :1.750e+13                     
##         Hora              Marca            Fabricante          Producto     
##  Length   :200473   Length   :200473   Length   :200473   Length   :200473  
##  N.unique : 52125   N.unique :   540   N.unique :   241   N.unique :  3406  
##  N.blank  :     0   N.blank  :     0   N.blank  :     0   N.blank  :     0  
##  Min.nchar:     8   Min.nchar:     3   Min.nchar:     3   Min.nchar:     4  
##  Max.nchar:     8   Max.nchar:    30   Max.nchar:    40   Max.nchar:    40  
##                                                                             
##      Precio          Ult.Costo         Unidades         F.Ticket     
##  Min.   :   0.50   Min.   :  0.38   Min.   : 1.000   Min.   :     1  
##  1st Qu.:  11.00   1st Qu.:  8.46   1st Qu.: 1.000   1st Qu.: 33978  
##  Median :  16.00   Median : 12.31   Median : 1.000   Median :106035  
##  Mean   :  19.45   Mean   : 15.31   Mean   : 1.261   Mean   :194101  
##  3rd Qu.:  25.00   3rd Qu.: 19.23   3rd Qu.: 1.000   3rd Qu.:383065  
##  Max.   :1000.00   Max.   :769.23   Max.   :96.000   Max.   :450040  
##  NombreDepartamento   NombreFamilia     NombreCategoria         Estado      
##  Length   :200473   Length   :200473   Length   :200473   Length   :200473  
##  N.unique :     9   N.unique :    51   N.unique :   174   N.unique :     5  
##  N.blank  :     0   N.blank  :     0   N.blank  :     0   N.blank  :     0  
##  Min.nchar:     6   Min.nchar:     3   Min.nchar:     2   Min.nchar:     7  
##  Max.nchar:    20   Max.nchar:    25   Max.nchar:    37   Max.nchar:    12  
##                                                                             
##      Mts.2        Tipo.ubicación          Giro           Hora.inicio    
##  Min.   :47.0   Length   :200473   Length   :200473   Length   :200473  
##  1st Qu.:53.0   N.unique :     3   N.unique :     2   N.unique :     3  
##  Median :60.0   N.blank  :     0   N.blank  :     0   N.blank  :     0  
##  Mean   :56.6   Min.nchar:     7   Min.nchar:     9   Min.nchar:     5  
##  3rd Qu.:60.0   Max.nchar:    12   Max.nchar:    10   Max.nchar:     5  
##  Max.   :62.0                                                           
##     Hora.cierre    
##  Length   :200473  
##  N.unique :     3  
##  N.blank  :     0  
##  Min.nchar:     5  
##  Max.nchar:     5  
## 

Técnica 4. Convertir tipos de datos

df$Fecha <- as.Date(df$Fecha, format="%d/%m/%Y")
str(df)
## 'data.frame':    200473 obs. of  21 variables:
##  $ ClaveTienda       : chr  "MX001" "MX001" "MX001" "MX001" ...
##  $ DescGiro          : chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ Codigo.Barras     : num  7.5e+12 7.5e+12 7.5e+12 7.5e+12 7.5e+12 ...
##  $ Fecha             : Date, format: "2020-06-19" "2020-06-19" ...
##  $ Hora              : chr  "08:16:21" "08:23:33" "08:24:33" "08:24:33" ...
##  $ Marca             : chr  "NUTRI LECHE" "DAN UP" "BIMBO" "PEPSI" ...
##  $ Fabricante        : chr  "MEXILAC" "DANONE DE MEXICO" "GRUPO BIMBO" "PEPSI-COLA MEXICANA" ...
##  $ Producto          : chr  "Nutri Leche 1 Litro" "DANUP STRAWBERRY P/BEBER 350GR NAL" "Rebanadas Bimbo 2Pz" "Pepsi N.R. 400Ml" ...
##  $ Precio            : num  16 14 5 8 19.5 9.5 11 9.5 23.5 12 ...
##  $ Ult.Costo         : num  12.3 14 5 8 15 ...
##  $ Unidades          : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ F.Ticket          : int  1 2 3 3 4 4 4 4 4 5 ...
##  $ NombreDepartamento: chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ NombreFamilia     : chr  "Lacteos y Refrigerados" "Lacteos y Refrigerados" "Pan y Tortilla" "Bebidas" ...
##  $ NombreCategoria   : chr  "Leche" "Yogurt" "Pan Dulce Empaquetado" "Refrescos Plástico (N.R.)" ...
##  $ Estado            : chr  "Nuevo León" "Nuevo León" "Nuevo León" "Nuevo León" ...
##  $ Mts.2             : int  60 60 60 60 60 60 60 60 60 60 ...
##  $ Tipo.ubicación    : chr  "Esquina" "Esquina" "Esquina" "Esquina" ...
##  $ Giro              : chr  "Abarrotes" "Abarrotes" "Abarrotes" "Abarrotes" ...
##  $ Hora.inicio       : chr  "08:00" "08:00" "08:00" "08:00" ...
##  $ Hora.cierre       : chr  "22:00" "22:00" "22:00" "22:00" ...

Técnica 5. Tratamiento de valores faltantes

# Borrar todos los NA's 
# df <- na.omit(df)

# Reemplazar los NA's con CEROS
# df[is.na(df)] <- 0

# Reemplazar los NA's con el PROMEDIO
# df$altura[is.na(df$altura)] <- mean(df$altura, na.rn=TRUE) 

Técnica 6. Herramientas Estadísticas

boxplot(df$Precio, horizontal = TRUE)

boxplot(df$Unidades, horizontal = TRUE)

Generar Masket

# Ordenar de menor a mayor la columna Ticket
df <- df[order(df$F.Ticket), ] 

# Generar Basket
library(plyr)
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
## 
## Attaching package: 'plyr'
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, mutate, rename, summarise, summarize
## The following object is masked from 'package:purrr':
## 
##     compact
basket <- ddply(df, c("F.Ticket"), function(df)paste(df$Marca, collapse =","))

# Eliminar numero de ticket
basket$F.Ticket <- NULL

# Cambiar el titulo de la columna v1 por Marca
colnames(basket) <- c("Marca")

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

Market Basket Analysis

# file.choose()
tr <- read.transactions("/Users/gabotejeda/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
reglas.asociacion <- apriori(tr, parameter=list(supp=0.001, conf=0.2, maxlen=10))
## 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.01s].
## sorting and recoding items ... [207 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## 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)
# inspect(reglas.asociacion)

reglas.asociacion <- sort(reglas.asociacion, by="confidence", decreasing=TRUE)
# summary(reglas.asociacion)
# inspect(reglas.asociacion)

top10reglas <- head(reglas.asociacion, n=10, by="confidence")
plot(top10reglas, method="graph", engine="htmlwidget")
LS0tCnRpdGxlOiAiTWFya2V0IEJhc2tldCBBbmFseXNpcyAtIEFiYXJyb3RlcyIKYXV0aG9yOiAiR2FicmllbCBUZWplZGEgQTAxMTc4NDU5IgpkYXRlOiAiMjAyNi0wOC0xOCIKb3V0cHV0OiAKICBodG1sX2RvY3VtZW50OgogICAgdG9jOiBUUlVFCiAgICB0b2NfZmxvYXQ6IFRSVUUKICAgIGNvZGVfZG93bmxvYWQ6IFRSVUUKICAgIHRoZW1lOiBj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