El Market Basket Analysis es una técnica en el ámbito de análisis y minería de datos en el camo del comercio. Su objetivo rincial 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 asociación son:
Este caso de estudio utiliza el dataset real de Instacart en Kaggle, el cual registra más de 3 millones de pedidos de 200,000 usuarios con un catálogo de 50,000 productos, con el objetivo de descubrir los hábitos de consumo y predecir las compras repetidas de los clientes. A diferencia de un modelo inmobiliario tradicional, este ecosistema carece de datos de precios, por lo que se aborda mediante un Market Basket Analysis (Análisis de la Canasta de Compra) utilizando el algoritmo Apriori; esto permite conectar múltiples tablas relacionales para identificar reglas de asociación y combinaciones frecuentes de productos (como qué artículos se agregan juntos al carrito), información que las empresas de comercio electrónico utilizan estratégicamente para optimizar recomendaciones en la app, diseñar promociones y organizar sus inventarios.
H, M. Y. (2022). InstaCart Online Grocery Basket Analysis Dataset. Kaggledatasets. https://www.kaggle.com/datasets/yasserh/instacart-online-grocery-basket-analysis-dataset
# install.packages("tidyverse") # paquete global para manipulación de datos
library(tidyverse)
# install.packages("janitor") # Examinar y limpiar base de datos
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)
# install.packages("plyr")
library(plyr)
# Solo se importan las bases necesarias para el Market Basket Analysis:
# order_products_prior y order_products_train (para order_id y product_id)
# products (para obtener product_name)
# No se requieren orders, aisles ni departments para generar las reglas de asociación
order_prior = read.csv(file.choose())
order_train = read.csv(file.choose())
products = read.csv(file.choose())
order = rbind(order_prior, order_train)
df = left_join(order, products, by = "product_id")
summary(df)
## order_id product_id add_to_cart_order reordered
## Min. : 1 Min. : 1 Min. : 1.000 Min. :0.0000
## 1st Qu.: 855413 1st Qu.:13519 1st Qu.: 3.000 1st Qu.:0.0000
## Median :1710660 Median :25256 Median : 6.000 Median :1.0000
## Mean :1710566 Mean :25576 Mean : 8.368 Mean :0.5901
## 3rd Qu.:2565587 3rd Qu.:37935 3rd Qu.: 11.000 3rd Qu.:1.0000
## Max. :3421083 Max. :49688 Max. :145.000 Max. :1.0000
## product_name aisle_id department_id
## Length :33819106 Min. : 1.00 Min. : 1.000
## N.unique : 49685 1st Qu.: 31.00 1st Qu.: 4.000
## N.blank : 0 Median : 83.00 Median : 9.000
## Min.nchar: 3 Mean : 71.22 Mean : 9.919
## Max.nchar: 159 3rd Qu.:107.00 3rd Qu.:16.000
## Max. :134.00 Max. :21.000
str(df)
## 'data.frame': 33819106 obs. of 7 variables:
## $ order_id : int 2 2 2 2 2 2 2 2 2 3 ...
## $ product_id : int 33120 28985 9327 45918 30035 17794 40141 1819 43668 33754 ...
## $ add_to_cart_order: int 1 2 3 4 5 6 7 8 9 1 ...
## $ reordered : int 1 1 0 1 0 1 1 1 0 1 ...
## $ product_name : chr "Organic Egg Whites" "Michigan Organic Kale" "Garlic Powder" "Coconut Butter" ...
## $ aisle_id : int 86 83 104 19 17 83 105 88 123 120 ...
## $ department_id : int 16 4 13 13 13 4 13 13 4 16 ...
head(df, 10)
## order_id product_id add_to_cart_order reordered
## 1 2 33120 1 1
## 2 2 28985 2 1
## 3 2 9327 3 0
## 4 2 45918 4 1
## 5 2 30035 5 0
## 6 2 17794 6 1
## 7 2 40141 7 1
## 8 2 1819 8 1
## 9 2 43668 9 0
## 10 3 33754 1 1
## product_name aisle_id department_id
## 1 Organic Egg Whites 86 16
## 2 Michigan Organic Kale 83 4
## 3 Garlic Powder 104 13
## 4 Coconut Butter 19 13
## 5 Natural Sweetener 17 13
## 6 Carrots 83 4
## 7 Original Unflavored Gelatine Mix 105 13
## 8 All Natural No Stir Creamy Almond Butter 88 13
## 9 Classic Blend Cole Slaw 123 4
## 10 Total 2% with Strawberry Lowfat Greek Strained Yogurt 120 16
tail(df, 10)
## order_id product_id add_to_cart_order reordered
## 33819097 3421058 30316 6 1
## 33819098 3421058 35578 7 0
## 33819099 3421058 32650 8 1
## 33819100 3421063 49235 1 1
## 33819101 3421063 13565 2 1
## 33819102 3421063 14233 3 1
## 33819103 3421063 35548 4 1
## 33819104 3421070 35951 1 1
## 33819105 3421070 16953 2 1
## 33819106 3421070 4724 3 1
## product_name
## 33819097 Baby Brie
## 33819098 Genoa Salame with White Cheddar Cheese & Toasted Rounds Small Plates
## 33819099 White Giant Paper Towel Rolls
## 33819100 Organic Half & Half
## 33819101 No Salt Added Gluten-Free Blue Chips Made with Organic Blue Corn
## 33819102 Natural Artesian Water
## 33819103 Twice Baked Potatoes
## 33819104 Organic Unsweetened Almond Milk
## 33819105 Creamy Peanut Butter
## 33819106 Broccoli Florettes
## aisle_id department_id
## 33819097 21 16
## 33819098 7 12
## 33819099 54 17
## 33819100 53 16
## 33819101 107 19
## 33819102 115 7
## 33819103 13 20
## 33819104 91 16
## 33819105 88 13
## 33819106 32 4
# Tabla de reordered
# count(df, reordered, sort=TRUE)
# count(df, product_name, sort=TRUE)
# count(df, aisle_id, sort=TRUE)
# count(df, department_id, sort=TRUE)
# Tabla de aisle_id y department_id
tabyl(df, aisle_id, department_id)
## aisle_id 1 2 3 4 5 6 7 8 9 10
## 1 0 0 0 0 0 0 0 0 0 0
## 2 0 0 0 0 0 0 0 0 0 0
## 3 0 0 0 0 0 0 0 0 0 0
## 4 0 0 0 0 0 0 0 0 210604 0
## 5 0 0 0 0 0 0 0 0 0 0
## 6 0 38086 0 0 0 0 0 0 0 0
## 7 0 0 0 0 0 0 0 0 0 0
## 8 0 0 36372 0 0 0 0 0 0 0
## 9 0 0 0 0 0 0 0 0 228123 0
## 10 0 0 0 0 0 0 0 0 0 0
## 11 0 0 0 0 0 0 0 0 0 0
## 12 0 0 0 0 0 0 0 0 38355 0
## 13 0 0 0 0 0 0 0 0 0 0
## 14 0 0 0 0 0 0 0 0 0 0
## 15 0 0 0 0 0 0 0 0 0 0
## 16 0 0 0 393793 0 0 0 0 0 0
## 17 0 0 0 0 0 0 0 0 0 0
## 18 0 0 0 0 0 0 0 0 0 18093
## 19 0 0 0 0 0 0 0 0 0 0
## 20 0 0 0 0 0 0 0 0 0 0
## 21 0 0 0 0 0 0 0 0 0 0
## 22 0 0 0 0 0 0 0 0 0 0
## 23 0 0 0 0 0 0 0 0 0 0
## 24 0 0 0 3792661 0 0 0 0 0 0
## 25 0 0 0 0 0 0 0 0 0 0
## 26 0 0 0 0 0 0 215467 0 0 0
## 27 0 0 0 0 50496 0 0 0 0 0
## 28 0 0 0 0 36424 0 0 0 0 0
## 29 0 0 0 0 0 0 0 0 0 0
## 30 0 0 0 0 0 78495 0 0 0 0
## 31 0 0 0 0 0 0 599109 0 0 0
## 32 0 0 0 289488 0 0 0 0 0 0
## 33 0 0 0 0 0 12426 0 0 0 0
## 34 75083 0 0 0 0 0 0 0 0 0
## 35 0 0 0 0 0 0 0 0 0 0
## 36 0 0 0 0 0 0 0 0 0 0
## 37 521101 0 0 0 0 0 0 0 0 0
## 38 408520 0 0 0 0 0 0 0 0 0
## 39 0 0 0 0 0 0 0 0 0 0
## 40 0 0 0 0 0 0 0 35915 0 0
## 41 0 0 0 0 0 0 0 66306 0 0
## 42 104096 0 0 0 0 0 0 0 0 0
## 43 0 0 118069 0 0 0 0 0 0 0
## 44 0 0 0 0 0 0 0 0 0 0
## 45 0 0 0 0 0 0 0 0 0 0
## 46 0 0 0 0 0 0 0 0 0 0
## 47 0 0 0 0 0 0 0 0 0 0
## 48 0 0 0 0 0 0 0 0 0 0
## 49 0 0 0 0 0 0 0 0 0 0
## 50 0 0 0 0 0 0 0 0 0 0
## 51 0 0 0 0 0 0 0 0 0 0
## 52 242492 0 0 0 0 0 0 0 0 0
## 53 0 0 0 0 0 0 0 0 0 0
## 54 0 0 0 0 0 0 0 0 0 0
## 55 0 0 0 0 0 0 0 0 0 0
## 56 0 0 0 0 0 0 0 0 0 0
## 57 0 0 0 0 0 0 0 0 0 0
## 58 41740 0 0 0 0 0 0 0 0 0
## 59 0 0 0 0 0 0 0 0 0 0
## 60 0 0 0 0 0 0 0 0 0 0
## 61 0 0 0 0 0 0 0 0 0 0
## 62 0 0 0 0 31646 0 0 0 0 0
## 63 0 0 0 0 0 0 0 0 150323 0
## 64 0 0 0 0 0 0 108357 0 0 0
## 65 0 0 0 0 0 0 0 0 0 0
## 66 0 0 0 0 0 173614 0 0 0 0
## 67 0 0 0 0 0 0 0 0 0 0
## 68 0 0 0 0 0 0 0 0 0 17839
## 69 0 0 0 0 0 0 0 0 0 0
## 70 0 0 0 0 0 0 0 0 0 0
## 71 0 0 0 0 0 0 0 0 0 0
## 72 0 0 0 0 0 0 0 0 0 0
## 73 0 0 0 0 0 0 0 0 0 0
## 74 0 0 0 0 0 0 0 0 0 0
## 75 0 0 0 0 0 0 0 0 0 0
## 76 0 0 0 0 0 16620 0 0 0 0
## 77 0 0 0 0 0 0 373816 0 0 0
## 78 0 0 0 0 0 0 0 0 0 0
## 79 169879 0 0 0 0 0 0 0 0 0
## 80 0 0 0 0 0 0 0 0 0 0
## 81 0 0 0 0 0 0 0 0 0 0
## 82 0 0 0 0 0 0 0 0 0 0
## 83 0 0 0 3568630 0 0 0 0 0 0
## 84 0 0 0 0 0 0 0 0 0 0
## 85 0 0 0 0 0 0 0 0 0 0
## 86 0 0 0 0 0 0 0 0 0 0
## 87 0 0 0 0 0 0 0 0 0 0
## 88 0 0 0 0 0 0 0 0 0 0
## 89 0 0 0 0 0 0 0 0 0 0
## 90 0 0 0 0 0 0 22276 0 0 0
## 91 0 0 0 0 0 0 0 0 0 0
## 92 0 0 0 0 0 0 0 0 0 0
## 93 0 0 260621 0 0 0 0 0 0 0
## 94 0 0 0 0 0 0 258717 0 0 0
## 95 0 0 0 0 0 0 0 0 0 0
## 96 0 0 0 0 0 0 0 0 0 0
## 97 0 0 0 0 0 0 0 0 0 0
## 98 0 0 0 0 0 0 348283 0 0 0
## 99 0 0 0 0 0 0 0 0 0 0
## 100 0 0 0 0 0 0 0 0 0 0
## 101 0 0 0 0 0 0 0 0 0 0
## 102 0 0 0 0 0 0 0 0 0 0
## 103 0 0 0 0 0 0 0 0 0 0
## 104 0 0 0 0 0 0 0 0 0 0
## 105 0 0 0 0 0 0 0 0 0 0
## 106 0 0 0 0 0 0 0 0 0 0
## 107 0 0 0 0 0 0 0 0 0 0
## 108 0 0 0 0 0 0 0 0 0 0
## 109 0 0 0 0 0 0 0 0 0 0
## 110 0 0 0 0 0 0 0 0 0 0
## 111 0 0 0 0 0 0 0 0 0 0
## 112 0 0 608469 0 0 0 0 0 0 0
## 113 5147 0 0 0 0 0 0 0 0 0
## 114 0 0 0 0 0 0 0 0 0 0
## 115 0 0 0 0 0 0 878150 0 0 0
## 116 545107 0 0 0 0 0 0 0 0 0
## 117 0 0 0 0 0 0 0 0 0 0
## 118 0 0 0 0 0 0 0 0 0 0
## 119 20241 0 0 0 0 0 0 0 0 0
## 120 0 0 0 0 0 0 0 0 0 0
## 121 0 0 0 0 0 0 0 0 0 0
## 122 0 0 0 0 0 0 0 0 0 0
## 123 0 0 0 1843806 0 0 0 0 0 0
## 124 0 0 0 0 29069 0 0 0 0 0
## 125 0 0 0 0 0 0 0 0 0 0
## 126 0 0 0 0 0 0 0 0 0 0
## 127 0 0 0 0 0 0 0 0 0 0
## 128 0 0 201650 0 0 0 0 0 0 0
## 129 203452 0 0 0 0 0 0 0 0 0
## 130 0 0 0 0 0 0 0 0 0 0
## 131 0 0 0 0 0 0 0 0 277935 0
## 132 0 0 0 0 0 0 0 0 0 0
## 133 0 0 0 0 0 0 0 0 0 0
## 134 0 0 0 0 11659 0 0 0 0 0
## 11 12 13 14 15 16 17 18 19 20 21
## 0 0 0 0 0 0 0 0 0 74864 0
## 0 0 0 0 0 86364 0 0 0 0 0
## 0 0 0 0 0 0 0 0 473835 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 65415 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 35391 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 9620 0 0 0 0
## 27407 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 103165 0
## 0 0 0 0 0 0 0 0 0 134597 0
## 0 21840 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 339780 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 256086 0 0 0 0 0 0 0 0
## 66819 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 1021462 0 0 0 0 0
## 33482 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 170441 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 66832 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 69790 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 134722 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 264892 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 30726 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 9522 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 312020 0 0
## 0 0 0 0 0 0 0 0 23626 0 0
## 47028 0 0 0 0 0 0 0 0 0 0
## 0 0 0 75004 0 0 0 0 0 0 0
## 0 124045 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 182498 0 0
## 0 0 113879 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 330358 0 0 0 0 0
## 0 0 0 0 0 0 255690 0 0 0 0
## 10876 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 25714 0 0 0
## 0 0 0 105762 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 282088 0 0 0 0 0 0
## 0 0 0 0 0 0 33702 0 0 0 0
## 0 0 0 0 0 0 0 0 244045 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 38211 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 370827 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 361573 0 0 0 0 0 0
## 28078 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 39420 0 0 0 0 0
## 0 0 231792 0 0 0 0 0 0 0 0
## 12915 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 98797 0 0 0 0
## 0 0 0 0 0 0 98990 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 478430 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 15673 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 309716 0 0 0 0 0 0
## 0 0 0 0 0 0 0 8466 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 923659 0 0 0 0 0
## 0 0 0 0 0 0 68852 0 0 0 0
## 0 0 0 0 0 472009 0 0 0 0 0
## 0 0 0 0 0 0 18405 0 0 0 0
## 0 0 301502 0 0 0 0 0 0 0 0
## 0 0 104050 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 664493 0 0 0 0 0
## 0 0 0 0 0 0 0 395654 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 70287 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 412087 0
## 0 0 24786 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 91193 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 77396
## 0 0 0 0 0 0 20918 0 0 0 0
## 0 0 0 0 0 0 0 8909 0 0 0
## 0 0 0 0 0 0 0 0 11706 0 0
## 0 0 221371 0 0 0 0 0 0 0 0
## 0 0 110847 0 0 0 0 0 0 0 0
## 0 318468 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 753739 0 0
## 0 0 0 0 0 320827 0 0 0 0 0
## 10698 0 0 0 0 0 0 0 0 0 0
## 0 0 117521 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 45307 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 124371 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 319019 0 0
## 11411 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 1507583 0 0 0 0 0
## 0 0 0 393787 0 0 0 0 0 0 0
## 0 74046 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 37053 0 0
## 20801 0 0 0 0 0 0 0 0 0 0
## 42905 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 0 0 0 164516 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
## 6455 0 0 0 0 0 0 0 0 0 0
## 19580 0 0 0 0 0 0 0 0 0 0
## 0 0 0 0 0 0 0 0 0 0 0
# Eliminar columnas que no se usan para el Market Basket
df = subset(df, select=-c(add_to_cart_order, aisle_id, department_id))
# Eliminar renglones sin product_name
df = df[df$product_name != "" & !is.na(df$product_name), ]
df = distinct(df)
df$product_name = trimws(df$product_name)
df$order_id = as.factor(df$order_id)
df$reordered = as.factor(df$reordered)
# No hay NA's relevantes tras el filtro de Técnica 1, se deja como referencia:
# df = na.omit(df)
# No hay Precio/Unidades en esta base; se revisa cantidad de productos por orden
productos_por_orden = table(df$order_id)
boxplot(as.numeric(productos_por_orden), horizontal = TRUE)
## Muestrear la base de datos
set.seed(123)
ordenes_muestra = sample(unique(df$order_id), 20000)
df = df[df$order_id %in% ordenes_muestra, ]
# esto lo hice porqué no me corria el código por nada.
# Ordenar de menor a mayor la columna order_id
df = df[order(df$order_id), ]
# Generar basket por product_name
basket = ddply(df, c("order_id"), function(df) paste(df$product_name, collapse=","))
# Eliminar número de orden
basket$order_id = NULL
# Cambiar el título de la columna a Producto
colnames(basket) = c("Producto")
# Exportar Basket
write.csv(basket, "basket2.csv", quote=FALSE, row.names=FALSE)
tr = read.transactions(file.choose(), format = "basket", sep = ",")
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: 20
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[22761 item(s), 20001 transaction(s)] done [0.10s].
## sorting and recoding items ... [1713 item(s)] done [0.00s].
## creating transaction tree ... done [0.01s].
## checking subsets of size 1 2 3 4 done [0.02s].
## writing ... [1109 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")