Teoría

El Market Basket Analysis es una técnica en el ámbito de análisis y minería 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 tres metricas principales para evaluar las reglas de asociación son:
Confidence (Confianza): Probabilidad de comprar B sabiendo que se compro 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 compro 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, el 0.05(5%) de las transacciones comprareon estos dos productos juntos.

Contexto

Una cadena de tienda de conveniencia tiene 5 tiendas ubicadas en distintas ciudades de México.La base de datos “abarrotes” continene un mes de abarrotes,pero presenta errores de calidad que impiden hacer analisis de confiables. El objetivo es limpiar la base de datos de forma estrategica y posteriormente aplicar MBA para decubrir patrones de compra y diseñar promociones que aumenten las ventas

Instalar paquetes y llamar librerias

#install.packages("tidyverse") # Paquete global para la manipulación de datos y analisis de datos
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
#install.packages("janitor") # Examinar y limpiar bases de datos 
library(janitor)
## 
## Adjuntando el paquete: 'janitor'
## 
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
#install.packages("Matrix") # Para trabajar con matrices
library(Matrix)
## 
## Adjuntando el paquete: 'Matrix'
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
#install.packages("arules") # Para trabajar con reglas de asociación
library(arules)
## 
## Adjuntando el paquete: 'arules'
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
#install.packages("arulesViz") # Vizualizar reglas de asociación
library(arulesViz)

#install.packages("arulesViz") # Vizualizar reglas de asociación
library(arulesViz)

#install.packages("plyr") 
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)
## ------------------------------------------------------------------------------
## 
## Adjuntando el paquete: '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

Cargar base da datos

#file.choose()

df <- read.csv("C:\\Users\\pauli\\Documents\\CLASES\\LIT\\7 semestre\\M2- R\\abarrotes.csv")

Entender la base de datos

#summary(df)
#str(df)
#count(df, ClaveTienda, sort= TRUE)
#count(df, DescGiro, sort= TRUE)
#count(df, Fecha, sort= TRUE)
#Etc....


# Tabla de tienda y departamento
#tabyl(df, ClaveTienda, NombreDepartamneto)

# Tabla de Estado y Hora de Inicio
#tabyl(df, Estado , Hora)

Limpiar la base de datos

Técnica 1: Eliminar valores irrelevantes

# Eliminar columnas
df <- subset(df, select=-c(PLU)) #Estoy dejando todas las columnas menos PLU

# Eliminar renglones
df <- df[df$Precio> 0, ] #Quitar registros con el precio menor a 0 

Técnica 2: Eliminar duplicados

df <- distinct(df)

Técnica 3: Correguir errores tipograficos y similares

df$Unidades <- ceiling(df$Unidades)

Técnica 4: Convertir tipos de datos

df$Fecha <- as.Date(df$Fecha, format="%d/%m/%Y")

Técnica 5:Tratar 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 el Ticket de Mayor a Menor
df <- df[order(df$F.Ticket), ]

# Generar Basket 
library(plyr)
basket <- ddply(df, .(F.Ticket), summarize, Marca = paste(Marca, collapse = ","))

# Eliminar número de Ticket
basket$F.Ticket <- NULL

#Cambiar el nombre 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()

transactions <- read.transactions("C:/Users/pauli/Documents/CLASES/LIT/7 semestre/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(transactions,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.02s].
## 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
##  transactions        115031   0.001        0.2
##                                                                                   call
##  apriori(data = transactions, 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
##  transactions        115031   0.001        0.2
##                                                                                   call
##  apriori(data = transactions, 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",)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