Market Basket Analysis (MBA) atau terjemahan kasarnya analisis keranjang pasar merupakan metode untuk mengetahui perilaku konsumen terhadap barang yang dibelinya. Market Baskey Analysis menggunakan prinsip association rule, yaitu hubungan satu produk dengan produk lainnya yang dibahasakan dengan rumus jika … maka … (jika produk A dibeli maka produk B dibeli). Tujuan utamanya adalah untuk mencari pattern atas pembelian produk dan mencari kombinasi kebiasaan konsumen atas produk tertentu. Di bawah ini akan dicontohkan aplikasi Market Basket Analysis menggunakan dataset toko roti bersumber dari kaggel yang dapat diakses melalui tautan berikut: https://www.kaggle.com/datasets/akashdeepkuila/bakery

Library

library(readxl) #membaca fail format excel
library(tidyverse) #menggunakan fungsi save ke format txt
## ── 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
library(arules) #Association rules
## Warning: package 'arules' was built under R version 4.6.1
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## 
## 
## Attaching package: 'arules'
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## The following objects are masked from 'package:base':
## 
##     abbreviate, write
library(dplyr) #Memudahkan penulisan

Data

Toko.roti <- read_xlsx("D:/Downloads/Dataset Kaggle/Bakery.xlsx", sheet = 2)
head(Toko.roti)
## # A tibble: 6 × 7
##   TransactionNo Items         DateTime            Daypart DayType Day   
##           <dbl> <chr>         <dttm>              <chr>   <chr>   <chr> 
## 1             1 Bread         2016-10-30 09:58:11 Morning Weekend Sunday
## 2             2 Scandinavian  2016-10-30 10:05:34 Morning Weekend Sunday
## 3             2 Scandinavian  2016-10-30 10:05:34 Morning Weekend Sunday
## 4             3 Hot chocolate 2016-10-30 10:07:57 Morning Weekend Sunday
## 5             3 Jam           2016-10-30 10:07:57 Morning Weekend Sunday
## 6             3 Cookies       2016-10-30 10:07:57 Morning Weekend Sunday
## # ℹ 1 more variable: TIME <dttm>
str(Toko.roti)
## tibble [20,507 × 7] (S3: tbl_df/tbl/data.frame)
##  $ TransactionNo: num [1:20507] 1 2 2 3 3 3 4 5 5 5 ...
##  $ Items        : chr [1:20507] "Bread" "Scandinavian" "Scandinavian" "Hot chocolate" ...
##  $ DateTime     : POSIXct[1:20507], format: "2016-10-30 09:58:11" "2016-10-30 10:05:34" ...
##  $ Daypart      : chr [1:20507] "Morning" "Morning" "Morning" "Morning" ...
##  $ DayType      : chr [1:20507] "Weekend" "Weekend" "Weekend" "Weekend" ...
##  $ Day          : chr [1:20507] "Sunday" "Sunday" "Sunday" "Sunday" ...
##  $ TIME         : POSIXct[1:20507], format: "1899-12-31 09:58:11" "1899-12-31 10:05:34" ...

Data terdiri dari 7 kolom (hasil modifikasi dari data asli kaggle) mulai dari TransactionNo menunjukkan nomor transaksi, Items menujukkan produk yang dibeli, Datetime hingga TIME menunjukkan waktu terjadinya transaksi. Di sini kita cukup menggunakan kolom pertama dan kedua saja.

Deskripsi Data

kuantitas.beli <- Toko.roti %>%
  count(TransactionNo, Items, name = "Quantity")
kuantitas.beli <- as.data.frame(aggregate(kuantitas.beli$Quantity, list(kuantitas.beli$Items), FUN = sum))
colnames(kuantitas.beli) <- c("Items", "Total")
kuantitas.beli <- kuantitas.beli[order(kuantitas.beli$Total, decreasing = TRUE),]
kuantitas.beli
##                            Items Total
## 24                        Coffee  5471
## 12                         Bread  3325
## 84                           Tea  1435
## 16                          Cake  1025
## 66                        Pastry   856
## 74                      Sandwich   771
## 56                     Medialuna   616
## 49                 Hot chocolate   590
## 27                       Cookies   540
## 15                       Brownie   379
## 38                    Farm House   374
## 61                        Muffin   370
## 3                      Alfajores   369
## 52                         Juice   369
## 79                          Soup   342
## 76                         Scone   327
## 88                         Toast   318
## 75                  Scandinavian   277
## 89                      Truffles   193
## 26                          Coke   185
## 80                Spanish Brunch   172
## 41                         Fudge   159
## 7                       Baguette   152
## 50                           Jam   149
## 87                        Tiffin   146
## 58                 Mineral water   136
## 51                Jammie Dodgers   125
## 20                  Chicken Stew   123
## 47             Hearty & Seasonal   107
## 73                         Salad    99
## 40                      Frittata    81
## 78                     Smoothies    77
## 53              Keeping It Local    63
## 86                     The Nomad    58
## 39                      Focaccia    54
## 93                Vegan mincepie    54
## 8                       Bakewell    48
## 83                       Tartine    47
## 2       Afternoon with the baker    44
## 5                       Art Tray    38
## 36          Extra Salami or Feta    38
## 33                          Eggs    28
## 44                       Granola    28
## 90                        Tshirt    21
## 62              My-5 Fruit Shoot    18
## 34        Ella's Kitchen Pouches    17
## 92                   Vegan Feast    16
## 29                        Crisps    14
## 32                Dulce de Leche    13
## 91              Valentine's card    13
## 31                      Duck egg    12
## 54                  Kids biscuit    12
## 67            Pick and Mix Bowls    12
## 23              Christmas common    11
## 57                Mighty Protein    11
## 82                  Tacos/Fajita    11
## 22                    Chocolates    10
## 70                      Postcard    10
## 43             Gingerbread syrup     9
## 30     Drinking chocolate spoons     8
## 60                        Muesli     8
## 63                     Nomad bag     8
## 4                Argentina Night     7
## 25               Coffee granules     7
## 35                     Empanadas     7
## 94              Victorian Sponge     7
## 10                        Basket     6
## 28                        Crepes     6
## 46            Half slice Monster     6
## 48                         Honey     6
## 55             Lemon and coconut     6
## 68                       Pintxos     6
## 9                   Bare Popcorn     5
## 59                      Mortimer     5
## 65                      Panatone     5
## 13                 Bread Pudding     4
## 14            Brioche and salami     3
## 17                 Caramel bites     3
## 18         Cherry me Dried fruit     3
## 71 Raspberry shortbread sandwich     3
## 11                 Bowl Nic Pitt     2
## 21               Chimichurri Oil     2
## 37                   Fairy Doors     2
## 45                Hack the stack     2
## 77                      Siblings     2
## 81                        Spread     2
## 1                     Adjustment     1
## 6                          Bacon     1
## 19                  Chicken sand     1
## 42                  Gift voucher     1
## 64                Olum & polenta     1
## 69                       Polenta     1
## 72                      Raw bars     1
## 85                      The BART     1

Dari tabel di atas dapat terlihat bahwa Top 3 tertinggi produk yang terjual adalah Coffe dengan 5471 pembelian, Bread dengan 3325 pembelian, dan Tea dengan 1435 pembelian. Deskripsi dasarnya sudah kita dapatkan sekarang lanjut ke Market Basket Analysis.

library arules (association rules) adalah library utama yang akan kita gunakan untuk melakukan Market Basket Analysis. Library arules ini hanya menerima input berupa fail format txt dan csv. Kebetulan data kita memiliki format excel jadinya perlu kita ubah dahulu agar sesuai dengan format yang disyaratkan oleh arules. terdapat 2 cara yang akan kita contohkan, yaitu cara “single” dan cara “basket”.

Deteksi elemen khusus

contains_apostrof <- grepl("'", Toko.roti$Items)
any(contains_apostrof == TRUE)
## [1] TRUE

package arules dalam penerapannya bisa saja memberikan warning semacam Warning in scan(text = l, what = “character”, sep = sep, quote = quote, : EOF within quoted string. warning tersebut muncul karena terdapat suatu tanda kata pada produk yang disalahartikan oleh fungsi di arules sebagai separator, tanda tersebut bisa berupa apostrof (‘), dan kutip (“) yang pada kasus ini adalah apostrof (’). ketika memakai format csv umumnya separator yang dipakai adalah koma (,) atau jika menggunakan txt separator yang digunakan umumnya adalah tab sehingga ketika ada apostrof pada nama produk akan membingungkan fungsi arules dan menganggap apostrof tersebut bagian dari separator juga

pada data kita setelah dicek dengan R ternyata ada yang mengandung apostrof. Selanjutnya dilakukan pencarian manual lewat microsoft excel nama produk apa saja yang mengandung apostrof, kemudian didapatkan produk Ella’s Kitchen Pouches dan Valentine’s card. Kedua nama produk tersebut kemudian dihilangkan apostrofnya sebagai berikut

Toko.roti$Items <-replace(Toko.roti$Items, Toko.roti$Items %in% c("Ella's Kitchen Pouches","Valentine's card"), c("Ellas Kitchen Pouches","Valentines card"))

setelah itu kita bisa melanjutkan ke langkah selanjutnya

Cara Single (format: “single”)

1) ubah dataframe menjadi txt atai csv

Di sini kita mengubahnya menjadi format txt

#write_tsv(Toko.roti[,c(1:2)], file = "D:/Downloads/Dataset Kaggle/bakery_teks.txt")

2) Ubah data csv/txt menjadi data transaksi

untuk mengubah csv/txt menjadi transactions kita menggunakan fungsi read.transactions(). penjelasannya satu persatu:

file = alamat dokumen di laptop kita
format = ada “single” ada “basket”
cols = kolom mana saja yang akan digunakan
skip = ingin me-skip berapa baris pertama

transaksi.single <- read.transactions(file = "D:/Downloads/Dataset Kaggle/bakery_teks.txt",
                               format = "single",
                               sep = "\t",
                               cols = c(1,2),
                               skip = 1)
transaksi.single <- transaksi.single[order(as.numeric(transactionInfo(transaksi.single)$transactionID))]

Cara Basket (format: “basket”)

cara kedua kita perlu merubah format terlebih dahulu menjadi semacam list yang satu baris data menunjukkan seluruh produk yang dibeli dalam satu transaksi

Toko.roti_formatting <- Toko.roti[order(Toko.roti$TransactionNo),]
Toko.roti_formatting$TransactionNo <- as.numeric(Toko.roti_formatting$TransactionNo)
glimpse(Toko.roti_formatting)
## Rows: 20,507
## Columns: 7
## $ TransactionNo <dbl> 1, 2, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8,…
## $ Items         <chr> "Bread", "Scandinavian", "Scandinavian", "Hot chocolate"…
## $ DateTime      <dttm> 2016-10-30 09:58:11, 2016-10-30 10:05:34, 2016-10-30 10…
## $ Daypart       <chr> "Morning", "Morning", "Morning", "Morning", "Morning", "…
## $ DayType       <chr> "Weekend", "Weekend", "Weekend", "Weekend", "Weekend", "…
## $ Day           <chr> "Sunday", "Sunday", "Sunday", "Sunday", "Sunday", "Sunda…
## $ TIME          <dttm> 1899-12-31 09:58:11, 1899-12-31 10:05:34, 1899-12-31 10…
Toko.roti_formatting <- plyr::ddply(Toko.roti_formatting, c("TransactionNo"), function(temp_df)paste(temp_df$Items,collapse = ","))
Toko.roti_formatting <- subset(Toko.roti_formatting, select = V1)
head(Toko.roti_formatting)
##                          V1
## 1                     Bread
## 2 Scandinavian,Scandinavian
## 3 Hot chocolate,Jam,Cookies
## 4                    Muffin
## 5       Coffee,Pastry,Bread
## 6   Medialuna,Pastry,Muffin
#write.csv(Toko.roti_formatting, file = "D:/Downloads/Dataset Kaggle/bakery_csv.csv", quote = FALSE,  row.names = T)
#write.csv(Toko.roti_formatting, file = "D:/Downloads/Dataset Kaggle/bakery_csv2.csv", quote = TRUE,  row.names = T)
transaksi.basket <- arules::read.transactions("D:/Downloads/Dataset Kaggle/bakery_csv.csv", format = "basket", sep = ",", cols = 1, skip = 1)
## Warning in asMethod(object): removing duplicated items in transactions
transaksi.basket2 <- arules::read.transactions("D:/Downloads/Dataset Kaggle/bakery_csv2.csv", format = "basket", sep = ",", cols = 1, skip = 1)

khusus format basket ini sengaja dibuat ada dua fail pertama dengan quote = FALSE dan kedua dengan quote = TRUE. saat melakukan read.trasactions menggunakan fail quote FALSE terlihat terdapat warning berupa status menghilangkan nilai duplikat. kenapa begitu dan apa perbedaannya? mari kita bahasa di bagian berikutnya

Visualisasi Bentuk Data dana Format single dan basket

untuk memperjelas perbedaan bentuk data kapan menggunakan format single dan kapan menggunakan format basket, coba lihat ilustrasi gambar di bawah ini

Bentuk data untuk format single
Bentuk data untuk format single

format single membutuhkan bentuk data seperti di atas. seminimalnya terdapat 2 kolom, yaitu kolom Items (paling utama) dan kolom grup yang dalam contoh ini adalah TransactionID. Kolom grup kita bisa hanya menggunakan satu kolom, tapi jika sekiranya satu kolom masih kurang untuk me-grup-kan item transaksi kita bisa menggunakan lebih dari satu kolom, contoh kolom ID pelanggan dan tanggal transaksi karena ada kemungkinan seorang pelanggan akan melakukan pembelian berulang.

Bentuk data untuk format basket
Bentuk data untuk format basket

Lain single lain pula basket. Format basket memerlukan bentuk data seperti di atas. Satu baris mewakili satu transaksi, kecuali baris header jika ada. Kolom satu di atas mempertegas transaksi ke berapa item tersebut dibeli. Kita juga bisa menggunakan data tanpa header maupun keterangan transaksi seperti di bawah sebagai alternatif lain.

Bentuk data untuk format basket opsi 2
Bentuk data untuk format basket opsi 2

Penjelasan hasil read.transactions format single dan basket

Okei mari kita lihat rangkuman dari ketiga data transaksi yang telah kita bentuk

summary(transaksi.single)
## transactions as itemMatrix in sparse format with
##  9465 rows (elements/itemsets/transactions) and
##  94 columns (items) and a density of 0.02122827 
## 
## most frequent items:
##  Coffee   Bread     Tea    Cake  Pastry (Other) 
##    4528    3097    1350     983     815    8114 
## 
## element (itemset/transaction) length distribution:
## sizes
##    1    2    3    4    5    6    7    8    9   10 
## 3948 3059 1471  662  234   64   17    4    5    1 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   1.000   2.000   1.995   3.000  10.000 
## 
## includes extended item information - examples:
##                     labels
## 1               Adjustment
## 2 Afternoon with the baker
## 3                Alfajores
## 
## includes extended transaction information - examples:
##      transactionID
## 1                1
## 1096             2
## 2168             3
summary(transaksi.basket)
## transactions as itemMatrix in sparse format with
##  9465 rows (elements/itemsets/transactions) and
##  94 columns (items) and a density of 0.02122827 
## 
## most frequent items:
##  Coffee   Bread     Tea    Cake  Pastry (Other) 
##    4528    3097    1350     983     815    8114 
## 
## element (itemset/transaction) length distribution:
## sizes
##    1    2    3    4    5    6    7    8    9   10 
## 3948 3059 1471  662  234   64   17    4    5    1 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   1.000   2.000   1.995   3.000  10.000 
## 
## includes extended item information - examples:
##                     labels
## 1               Adjustment
## 2 Afternoon with the baker
## 3                Alfajores
## 
## includes extended transaction information - examples:
##   transactionID
## 1             1
## 2             2
## 3             3
summary(transaksi.basket2)
## transactions as itemMatrix in sparse format with
##  9465 rows (elements/itemsets/transactions) and
##  2893 columns (items) and a density of 0.0003456619 
## 
## most frequent items:
##         Bread        Coffee    Farm House           Tea Coffee,Coffee 
##          1122          1008           199           188           177 
##       (Other) 
##          6771 
## 
## element (itemset/transaction) length distribution:
## sizes
##    1 
## 9465 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       1       1       1       1       1       1 
## 
## includes extended item information - examples:
##                                              labels
## 1                                        Adjustment
## 2                          Afternoon with the baker
## 3 Afternoon with the baker,Afternoon with the baker
## 
## includes extended transaction information - examples:
##   transactionID
## 1             1
## 2             2
## 3             3

pada tulisan transactions as itemMatrix in sparse format with 9465 rows (elements/itemsets/transactions) and 94 columns (items) and a density of 0.02122827 menunjukkan bahwa terdapat 9465 transaksi (rows) dan 94 produk (items) yang ada pada data. data transaksi.single dan transaksi.basket memiliki nilai yang sama tapi kok data transaksi.basket2 tertulis memiliki 2893 produk? kok bisa. Masalahnya terletak pada penggunaan quote = TRUE pada bagian sebelumnya. saat quote ditulis TRUE maka pada baris akan diberikan tanda kutip di awal dan akhir, contoh jika quote = FALSE maka akan tertulis bread,scandinavian sedangkan jika quote = TRUE maka akan tertulis “bread,scandinavian”. seperti penjelasan sebelum tanda (’) dan tanda (“) dapat membingungkan package arules sehingga menghasilkan hasil yang keliru.

penjelasan tambahan lain silahkan lihat list produk yang tertuang pada 10 transaksi pertama berikut

inspect(transaksi.single[1:10])
##      items                            transactionID
## [1]  {Bread}                          1            
## [2]  {Scandinavian}                   2            
## [3]  {Cookies, Hot chocolate, Jam}    3            
## [4]  {Muffin}                         4            
## [5]  {Bread, Coffee, Pastry}          5            
## [6]  {Medialuna, Muffin, Pastry}      6            
## [7]  {Coffee, Medialuna, Pastry, Tea} 7            
## [8]  {Bread, Pastry}                  8            
## [9]  {Bread, Muffin}                  9            
## [10] {Medialuna, Scandinavian}        10
inspect(transaksi.basket[1:10])
##      items                            transactionID
## [1]  {Bread}                          1            
## [2]  {Scandinavian}                   2            
## [3]  {Cookies, Hot chocolate, Jam}    3            
## [4]  {Muffin}                         4            
## [5]  {Bread, Coffee, Pastry}          5            
## [6]  {Medialuna, Muffin, Pastry}      6            
## [7]  {Coffee, Medialuna, Pastry, Tea} 7            
## [8]  {Bread, Pastry}                  8            
## [9]  {Bread, Muffin}                  9            
## [10] {Medialuna, Scandinavian}        10
inspect(transaksi.basket2[1:10])
##      items                         transactionID
## [1]  {Bread}                       1            
## [2]  {Scandinavian,Scandinavian}   2            
## [3]  {Hot chocolate,Jam,Cookies}   3            
## [4]  {Muffin}                      4            
## [5]  {Coffee,Pastry,Bread}         5            
## [6]  {Medialuna,Pastry,Muffin}     6            
## [7]  {Medialuna,Pastry,Coffee,Tea} 7            
## [8]  {Pastry,Bread}                8            
## [9]  {Bread,Muffin}                9            
## [10] {Scandinavian,Medialuna}      10

Coba lihat mana yang berbeda dari ketiga data transaksi di atas? terlihat bahwa pada transaksi nomor 2 untuk transaksi.single dan transaksi.basket tertulis {Scandinavian} saja sedangkan pada transaksi.basket2 tertulis {Scandinavian,Scandinavian}. secara pengaturan (setting) package arules akan menghilangkan data duplikat pada transaksi yang sama, jadi jika pada transaksi yang sama terdapat dua atau lebih produk dengan nama yang sama maka duplikatnya dihilangkan sehingga hanya menyisakan satu nama produk yang unik di masing-masing transaksi.erarti jumlah produknya berkurang dong? bukan berkurang melainkan di association rules ketika ada semisal {Scandinavian, Scandinavian} diartikan sebagai “Jika membeli Scandinavian maka akan membeli Scandinavian juga” terdengar aneh dan tidak memberikan insight berarti. jadi dengan kata lain, association rules mencari hubungan antara satu produk dengan produk berlainan bukan hubungan diantara produk yang sama.

sekarang kita review kembali deskripsi data di awal dengan hasil read.transactions

head(kuantitas.beli, 10)
##            Items Total
## 24        Coffee  5471
## 12         Bread  3325
## 84           Tea  1435
## 16          Cake  1025
## 66        Pastry   856
## 74      Sandwich   771
## 56     Medialuna   616
## 49 Hot chocolate   590
## 27       Cookies   540
## 15       Brownie   379
summary(transaksi.single)
## transactions as itemMatrix in sparse format with
##  9465 rows (elements/itemsets/transactions) and
##  94 columns (items) and a density of 0.02122827 
## 
## most frequent items:
##  Coffee   Bread     Tea    Cake  Pastry (Other) 
##    4528    3097    1350     983     815    8114 
## 
## element (itemset/transaction) length distribution:
## sizes
##    1    2    3    4    5    6    7    8    9   10 
## 3948 3059 1471  662  234   64   17    4    5    1 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   1.000   2.000   1.995   3.000  10.000 
## 
## includes extended item information - examples:
##                     labels
## 1               Adjustment
## 2 Afternoon with the baker
## 3                Alfajores
## 
## includes extended transaction information - examples:
##      transactionID
## 1                1
## 1096             2
## 2168             3

jika dibandingkan keduanya, 5 besar produk terlaris dari urutan masih sama, yaitu mulai dari Coffee, Bread, Tea, Cake, dan Pastry. tapi, kenapa jumlahnya berbeda? Coffee pada tabel pertama berjumlah 5471 sedangkan pada summary berjumlah 4528 begitupun dengan bread berjumlah 3325 dengan 3097. Perbedaan tersebut itu maksudnya dari segi penjualan total benar bahwa total Coffee terjual adalah 5471 cangkir, sedangkan jumlah 4528 itu merupakan jumlah transaksi yang terdapat pembelian Coffee. Contoh transaksi nomor 21 membeli coffee sebanyak 2 cangkir berarti total coffee terjual sebanyak 2 cangkir dan transaksi yang mengandung coffee sebanyak 1 transaksi.

Eksplorasi Data

selanjutnya kita melakukan eksplorasi melihat performa items untuk seluruh transaksi

Top 15 Produk

itemFrequency(transaksi.single, type = "relative") %>% sort(decreasing = T) %>% head(n = 15)
##        Coffee         Bread           Tea          Cake        Pastry 
##    0.47839408    0.32720549    0.14263074    0.10385631    0.08610671 
##      Sandwich     Medialuna Hot chocolate       Cookies       Brownie 
##    0.07184363    0.06180666    0.05832013    0.05441099    0.04004226 
##    Farm House         Juice        Muffin     Alfajores         Scone 
##    0.03919704    0.03856313    0.03845747    0.03634443    0.03454834

Dapat dilihat bahwa 15 produk terlaris dimulai dari Coffee di urutan pertama hingga Scone di urutan ke-15. Data di atas sendiri dihitung dalam bentuk persentase yang jika kita interpretasikan ke dalam kalimat dapat ditulis seperti ini, Produk Coffee tercatat terjual dalam 47% dari seluruh transaksi. Jika tidak ingin menggunakan persentase melainkan angka, kita bisa merubah syntaxnya menjadi

itemFrequency(transaksi.single, type = "absolute") %>% sort(decreasing = T) %>% head(n = 15)
##        Coffee         Bread           Tea          Cake        Pastry 
##          4528          3097          1350           983           815 
##      Sandwich     Medialuna Hot chocolate       Cookies       Brownie 
##           680           585           552           515           379 
##    Farm House         Juice        Muffin     Alfajores         Scone 
##           371           365           364           344           327

jadi kita bisa mengatakan bahwa Coffee tercatat dalam 4528 transaksi dan merupakan produk terlaris di toko kita. tentunya angka saja seperti di atas kurang menarik untuk dilihat kan, maka agar lebih menarik kita dapat memvisualisasikannya dengan barplot seperti di bawah ini

itemFrequencyPlot(transaksi.single,type = "absolute", topN=15) #type = "relative jika ingin dalam bentuk persen

Modelling Data

dalam membentuk model terdapat beberapa parameter yang perlu diperhatikan:

support = berapa kontribusi produk tersebut terhadap seluruh transaksi (default = 0.1)
confidence = mengukur seberapa kuat rules (default = 0.8). rules = jika … maka …
minlen = minimal items yang terdapat dalam rules (default = 1)
maxlen = maksimal items yang terdapat dalam rules (default = 10)

bakeryrules<-apriori(transaksi.single, parameter=list(support = 0.002, confidence=0.25,
                                                minlen=2))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##        0.25    0.1    1 none FALSE            TRUE       5   0.002      2
##  maxlen target  ext
##      10  rules TRUE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 18 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[94 item(s), 9465 transaction(s)] done [0.00s].
## sorting and recoding items ... [44 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 done [0.00s].
## writing ... [112 rule(s)] done [0.00s].
## creating S4 object  ... done [0.00s].

kesempatan kali ini kita membuat penyesuaian parameter apriori. parameter support ditentukan sebesar 0.02 mengasumsikan setidaknya suatu item dibeli setidaknya dua kali dalam sebulan. transaksi pertama terdapat di januari 2016 dan transaksi terakhir di desember 2017 total 24 bulan, lalu total transaksi terhitung ada 9465 transaksi sehingga bisa kita dapatkan perhitungan 24*2/9465 = 0.002535658 atau 0.002 melalui pembulatan ke bawah. Confidence diambil 0.25 dengan maksud bahwa rules tersebut setidaknya benar untuk 25% dari total transaksi. terkahir, minlen diambil 2 agar transaksi yang hanya mengandung 1 jenis items tidak ikut dimasukkan ke dalam model karena tidak memberikan insight asosiasi antar item.

length(unique(Toko.roti$TransactionNo))
## [1] 9465
min(Toko.roti$DateTime)
## [1] "2016-01-11 07:51:20 UTC"
max(Toko.roti$DateTime)
## [1] "2017-12-03 16:28:00 UTC"
support_parameter = 24/9465
support_parameter
## [1] 0.002535658

Evaluasi model

summary(bakeryrules)
## set of 112 rules
## 
## rule length distribution (lhs + rhs):sizes
##  2  3 
## 52 60 
## 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.000   2.000   3.000   2.536   3.000   3.000 
## 
## summary of quality measures:
##     support           confidence        coverage             lift       
##  Min.   :0.002007   Min.   :0.2500   Min.   :0.002747   Min.   :0.5226  
##  1st Qu.:0.002615   1st Qu.:0.3307   1st Qu.:0.006366   1st Qu.:0.8325  
##  Median :0.003962   Median :0.4556   Median :0.009139   Median :1.0287  
##  Mean   :0.008680   Mean   :0.4497   Mean   :0.021224   Mean   :1.1184  
##  3rd Qu.:0.007422   3rd Qu.:0.5490   3rd Qu.:0.019440   3rd Qu.:1.1910  
##  Max.   :0.090016   Max.   :0.8158   Max.   :0.327205   Max.   :4.3355  
##      count       
##  Min.   : 19.00  
##  1st Qu.: 24.75  
##  Median : 37.50  
##  Mean   : 82.15  
##  3rd Qu.: 70.25  
##  Max.   :852.00  
## 
## mining info:
##              data ntransactions support confidence
##  transaksi.single          9465   0.002       0.25
##                                                                                                call
##  apriori(data = transaksi.single, parameter = list(support = 0.002, confidence = 0.25, minlen = 2))

Dari aturan parameter yang tela =h kita buat didapatkan sebanyak 112 rules yang bisa dibilang cukup tidak terlalu banyak maupun tidak terlalu sedikit. panjang rules sebanyak 2 item berjumlah 52 dan rules sebanyak 3 item berjumlah 60 buat. Di sana tertulis istilah lhs dan rhs, dua istilah tersebut menandakan posisi pada rules, lhs untuk left dan rhs untuk right atau dalam kalimat bisa dibentuk “jika lhs maka rhs”. Pada quality measures aturan umumnya ialah semakin besar semakin baik terutama kita fokuskan pada matriks confidence dan lift.

Interpretasi rules

Umum

inspect(bakeryrules[1:5])
##     lhs                 rhs      support     confidence coverage    lift    
## [1] {Tartine}        => {Coffee} 0.003063920 0.6304348  0.004860011 1.317815
## [2] {Focaccia}       => {Bread}  0.002007396 0.3518519  0.005705230 1.075324
## [3] {Bakewell}       => {Coffee} 0.003063920 0.6041667  0.005071315 1.262906
## [4] {Vegan mincepie} => {Coffee} 0.003169572 0.5769231  0.005493925 1.205958
## [5] {Art Tray}       => {Coffee} 0.002746962 0.6842105  0.004014791 1.430224
##     count
## [1] 29   
## [2] 19   
## [3] 29   
## [4] 30   
## [5] 26

Ouput di atas terdapat rules Jika membeli {Tartine} maka akan membeli {Coffee} memiliki confidence 0.63 atau 6 dari 10 konsumen yang membeli {Tratine} juga membeli {Coffee}. Kemudian, lift memperlihatkan angka 1.317815 sehingga bisa kita katakan konsumen yang membeli {Tratine} memiliki kemungkinan 1.3x lebih besar untuk membeli {Coffee} dibandingkan konsumen pada umumnya.

sekarang kita coba mensorting rules berdasarkan nilai liftnya

inspect(sort(bakeryrules, by="lift")[1:10])
##      lhs                        rhs        support     confidence coverage   
## [1]  {Coffee, Coke}          => {Sandwich} 0.002007396 0.3114754  0.006444797
## [2]  {Coffee, Truffles}      => {Sandwich} 0.002113048 0.2816901  0.007501321
## [3]  {Coke}                  => {Sandwich} 0.005176968 0.2663043  0.019440042
## [4]  {Hot chocolate, Tea}    => {Cake}     0.002007396 0.2500000  0.008029583
## [5]  {Soup}                  => {Tea}      0.009086107 0.2638037  0.034442684
## [6]  {Spanish Brunch}        => {Tea}      0.004648706 0.2558140  0.018172213
## [7]  {Extra Salami or Feta}  => {Coffee}   0.003275225 0.8157895  0.004014791
## [8]  {Keeping It Local}      => {Coffee}   0.005388273 0.8095238  0.006656101
## [9]  {Juice, Spanish Brunch} => {Coffee}   0.002007396 0.7307692  0.002746962
## [10] {Toast}                 => {Coffee}   0.023666138 0.7044025  0.033597464
##      lift     count
## [1]  4.335463  19  
## [2]  3.920878  20  
## [3]  3.706722  49  
## [4]  2.407172  19  
## [5]  1.849557  86  
## [6]  1.793540  44  
## [7]  1.705267  31  
## [8]  1.692169  51  
## [9]  1.527547  19  
## [10] 1.472431 224

rules dengan ranking 3 teratas memiliki lift lebih besar dari 3. Rules pertama jika membeli {Coffee, Coke} maka akan membeli {sandwich}, kedua jika membeli {Coffee, Truffles} maka akan membeli {Sandwich}, dan ketiga jika membeli {Coke} maka akan membeli {Sandwich}. ketiga rules terbesar memiliki rhs yang sama yaitu {Sandwich} dengan kata lain konsumen yang membeli kombinasi produk-produk tersebut memiliki peluang 3-4x lebih besar untuk membeli Sandwich juga dibanding konsumen biasa. Pattern lain yang cukup tinggi juga ialah asosiasi produk {Hot chocolate, Tea} dengan {Cake} dan {Soup} dengan {Tea} yang memiliki kecondongan 1.8x dan 2.4x lebih besar dari konsumen biasa. Pattern-pattern tersebut memberikan insight bahwa produk-produk tersebut dapat dibuat bundle paket pembelian supaya meningkatkan penjualan Toko.

Subset khusus

Jika kita hanya ingin mencari pattern dari salah satu produk saja, misal Coffee dalam contoh ini. Kita bisa menggunakan kode seperti berikut.

coffeerules <- bakeryrules %>% subset(items %in% "Coffee") %>% sort(by = "lift")
inspect(coffeerules)
##      lhs                           rhs        support     confidence
## [1]  {Coffee, Coke}             => {Sandwich} 0.002007396 0.3114754 
## [2]  {Coffee, Truffles}         => {Sandwich} 0.002113048 0.2816901 
## [3]  {Extra Salami or Feta}     => {Coffee}   0.003275225 0.8157895 
## [4]  {Keeping It Local}         => {Coffee}   0.005388273 0.8095238 
## [5]  {Juice, Spanish Brunch}    => {Coffee}   0.002007396 0.7307692 
## [6]  {Toast}                    => {Coffee}   0.023666138 0.7044025 
## [7]  {Cake, Medialuna}          => {Coffee}   0.002535658 0.6857143 
## [8]  {Art Tray}                 => {Coffee}   0.002746962 0.6842105 
## [9]  {Cake, Sandwich}           => {Coffee}   0.004648706 0.6769231 
## [10] {Hot chocolate, Pastry}    => {Coffee}   0.003803487 0.6666667 
## [11] {Sandwich, Soup}           => {Coffee}   0.003592182 0.6538462 
## [12] {Hot chocolate, Medialuna} => {Coffee}   0.003063920 0.6444444 
## [13] {Tartine}                  => {Coffee}   0.003063920 0.6304348 
## [14] {Salad}                    => {Coffee}   0.006550449 0.6262626 
## [15] {Cookies, Hot chocolate}   => {Coffee}   0.003697834 0.6140351 
## [16] {Bakewell}                 => {Coffee}   0.003063920 0.6041667 
## [17] {Cookies, Juice}           => {Coffee}   0.003697834 0.6034483 
## [18] {Cake, Hot chocolate}      => {Coffee}   0.006867406 0.6018519 
## [19] {Cake, Scone}              => {Coffee}   0.002852615 0.6000000 
## [20] {Spanish Brunch}           => {Coffee}   0.010882198 0.5988372 
## [21] {Brownie, Hot chocolate}   => {Coffee}   0.002430005 0.5897436 
## [22] {Cake, Cookies}            => {Coffee}   0.004226096 0.5797101 
## [23] {Vegan mincepie}           => {Coffee}   0.003169572 0.5769231 
## [24] {Hot chocolate, Sandwich}  => {Coffee}   0.002535658 0.5714286 
## [25] {Medialuna}                => {Coffee}   0.035182250 0.5692308 
## [26] {Alfajores, Cake}          => {Coffee}   0.002324353 0.5641026 
## [27] {Alfajores, Hot chocolate} => {Coffee}   0.002007396 0.5588235 
## [28] {Sandwich, Truffles}       => {Coffee}   0.002113048 0.5555556 
## [29] {Cake, Juice}              => {Coffee}   0.003909139 0.5522388 
## [30] {Pastry}                   => {Coffee}   0.047543582 0.5521472 
## [31] {Tiffin}                   => {Coffee}   0.008452192 0.5479452 
## [32] {Cake, Soup}               => {Coffee}   0.002430005 0.5476190 
## [33] {Alfajores}                => {Coffee}   0.019651347 0.5406977 
## [34] {Hearty & Seasonal}        => {Coffee}   0.005705230 0.5400000 
## [35] {The Nomad}                => {Coffee}   0.003275225 0.5344828 
## [36] {Juice}                    => {Coffee}   0.020602219 0.5342466 
## [37] {Sandwich}                 => {Coffee}   0.038246170 0.5323529 
## [38] {Frittata}                 => {Coffee}   0.004543053 0.5308642 
## [39] {Cake, Pastry}             => {Coffee}   0.002746962 0.5306122 
## [40] {Medialuna, Pastry}        => {Coffee}   0.004860011 0.5287356 
## [41] {Cake}                     => {Coffee}   0.054727945 0.5269583 
## [42] {Scone}                    => {Coffee}   0.018066561 0.5229358 
## [43] {Cookies}                  => {Coffee}   0.028209192 0.5184466 
## [44] {Bread, Spanish Brunch}    => {Coffee}   0.002430005 0.5111111 
## [45] {Tea, Toast}               => {Coffee}   0.003275225 0.5081967 
## [46] {Hot chocolate}            => {Coffee}   0.029582673 0.5072464 
## [47] {Jammie Dodgers}           => {Coffee}   0.006656101 0.5040000 
## [48] {Smoothies}                => {Coffee}   0.004014791 0.4935065 
## [49] {Brownie}                  => {Coffee}   0.019651347 0.4907652 
## [50] {Muffin}                   => {Coffee}   0.018806128 0.4890110 
## [51] {Pastry, Tea}              => {Coffee}   0.004648706 0.4835165 
## [52] {Bread, Tiffin}            => {Coffee}   0.002324353 0.4782609 
## [53] {Cake, Muffin}             => {Coffee}   0.002324353 0.4782609 
## [54] {Brownie, Cake}            => {Coffee}   0.002113048 0.4761905 
## [55] {Bread, Toast}             => {Coffee}   0.003697834 0.4729730 
## [56] {Juice, Sandwich}          => {Coffee}   0.002746962 0.4727273 
## [57] {Soup}                     => {Coffee}   0.015847861 0.4601227 
## [58] {Bread, Hot chocolate}     => {Coffee}   0.006127839 0.4566929 
## [59] {Medialuna, Tea}           => {Coffee}   0.003697834 0.4545455 
## [60] {Alfajores, Tea}           => {Coffee}   0.003063920 0.4531250 
## [61] {Muffin, Tea}              => {Coffee}   0.002852615 0.4354839 
## [62] {Bread, Cake}              => {Coffee}   0.010036978 0.4298643 
## [63] {Bread, Sandwich}          => {Coffee}   0.007184363 0.4223602 
## [64] {Cake, Tea}                => {Coffee}   0.010036978 0.4222222 
## [65] {Alfajores, Bread}         => {Coffee}   0.004331749 0.4183673 
## [66] {Scone, Tea}               => {Coffee}   0.003380877 0.4050633 
## [67] {Coffee, Tiffin}           => {Bread}    0.002324353 0.2750000 
## [68] {Bread, Juice}             => {Coffee}   0.002958267 0.4000000 
## [69] {Bread, Medialuna}         => {Coffee}   0.006761754 0.4000000 
## [70] {Chicken Stew}             => {Coffee}   0.005176968 0.3983740 
## [71] {Cookies, Tea}             => {Coffee}   0.003909139 0.3978495 
## [72] {Mineral water}            => {Coffee}   0.005599577 0.3955224 
## [73] {Coke, Sandwich}           => {Coffee}   0.002007396 0.3877551 
## [74] {Bread, Pastry}            => {Coffee}   0.011199155 0.3840580 
## [75] {Bread, Scone}             => {Coffee}   0.003486529 0.3837209 
## [76] {Sandwich, Tea}            => {Coffee}   0.005388273 0.3750000 
## [77] {Truffles}                 => {Coffee}   0.007501321 0.3697917 
## [78] {Bread, Cookies}           => {Coffee}   0.005282620 0.3649635 
## [79] {Bread, Brownie}           => {Coffee}   0.003803487 0.3529412 
## [80] {Tea}                      => {Coffee}   0.049867934 0.3496296 
## [81] {Bread, Soup}              => {Coffee}   0.002218700 0.3387097 
## [82] {Coke}                     => {Coffee}   0.006444797 0.3315217 
## [83] {Brownie, Tea}             => {Coffee}   0.002218700 0.3281250 
## [84] {Soup, Tea}                => {Coffee}   0.002746962 0.3023256 
## [85] {Bread, Muffin}            => {Coffee}   0.002430005 0.2987013 
## [86] {Juice, Tea}               => {Coffee}   0.002007396 0.2794118 
## [87] {Bread}                    => {Coffee}   0.090015848 0.2751049 
## [88] {Jam}                      => {Coffee}   0.004120444 0.2746479 
## [89] {Bread, Tea}               => {Coffee}   0.007395668 0.2631579 
## [90] {Hot chocolate, Tea}       => {Coffee}   0.002007396 0.2500000 
##      coverage    lift      count
## [1]  0.006444797 4.3354629  19  
## [2]  0.007501321 3.9208782  20  
## [3]  0.004014791 1.7052666  31  
## [4]  0.006656101 1.6921694  51  
## [5]  0.002746962 1.5275465  19  
## [6]  0.033597464 1.4724315 224  
## [7]  0.003697834 1.4333670  24  
## [8]  0.004014791 1.4302236  26  
## [9]  0.006867406 1.4149905  44  
## [10] 0.005705230 1.3935512  36  
## [11] 0.005493925 1.3667522  34  
## [12] 0.004754358 1.3470995  29  
## [13] 0.004860011 1.3178148  29  
## [14] 0.010459588 1.3090936  62  
## [15] 0.006022187 1.2835340  35  
## [16] 0.005071315 1.2629058  29  
## [17] 0.006127839 1.2614041  35  
## [18] 0.011410460 1.2580671  65  
## [19] 0.004754358 1.2541961  27  
## [20] 0.018172213 1.2517655 103  
## [21] 0.004120444 1.2327569  23  
## [22] 0.007290016 1.2117837  40  
## [23] 0.005493925 1.2059578  30  
## [24] 0.004437401 1.1944725  24  
## [25] 0.061806656 1.1898784 333  
## [26] 0.004120444 1.1791587  22  
## [27] 0.003592182 1.1681238  19  
## [28] 0.003803487 1.1612927  20  
## [29] 0.007078711 1.1543596  37  
## [30] 0.086106709 1.1541682 450  
## [31] 0.015425251 1.1453846  80  
## [32] 0.004437401 1.1447028  23  
## [33] 0.036344427 1.1302349 186  
## [34] 0.010565240 1.1287765  54  
## [35] 0.006127839 1.1172437  31  
## [36] 0.038563127 1.1167500 195  
## [37] 0.071843634 1.1127916 362  
## [38] 0.008557845 1.1096797  43  
## [39] 0.005176968 1.1091530  26  
## [40] 0.009191759 1.1052303  46  
## [41] 0.103856313 1.1015151 518  
## [42] 0.034548336 1.0931067 171  
## [43] 0.054410988 1.0837229 267  
## [44] 0.004754358 1.0683893  23  
## [45] 0.006444797 1.0622973  31  
## [46] 0.058320127 1.0603107 280  
## [47] 0.013206550 1.0535247  63  
## [48] 0.008135235 1.0315899  38  
## [49] 0.040042261 1.0258596 186  
## [50] 0.038457475 1.0221928 178  
## [51] 0.009614369 1.0107075  44  
## [52] 0.004860011 0.9997215  22  
## [53] 0.004860011 0.9997215  22  
## [54] 0.004437401 0.9953937  20  
## [55] 0.007818278 0.9886681  35  
## [56] 0.005810882 0.9881545  26  
## [57] 0.034442684 0.9618068 150  
## [58] 0.013417855 0.9546375  58  
## [59] 0.008135235 0.9501486  35  
## [60] 0.006761754 0.9471794  29  
## [61] 0.006550449 0.9103036  27  
## [62] 0.023349181 0.8985568  95  
## [63] 0.017010037 0.8828710  68  
## [64] 0.023771791 0.8825824  95  
## [65] 0.010353936 0.8745245  41  
## [66] 0.008346540 0.8467147  32  
## [67] 0.008452192 0.8404504  22  
## [68] 0.007395668 0.8361307  28  
## [69] 0.016904385 0.8361307  64  
## [70] 0.012995246 0.8327318  49  
## [71] 0.009825674 0.8316354  37  
## [72] 0.014157422 0.8267711  53  
## [73] 0.005176968 0.8105349  19  
## [74] 0.029160063 0.8028067 106  
## [75] 0.009086107 0.8021022  33  
## [76] 0.014368727 0.7838726  51  
## [77] 0.020285261 0.7729855  71  
## [78] 0.014474379 0.7628930  50  
## [79] 0.010776545 0.7377624  36  
## [80] 0.142630745 0.7308402 472  
## [81] 0.006550449 0.7080139  21  
## [82] 0.019440042 0.6929888  61  
## [83] 0.006761754 0.6858885  21  
## [84] 0.009086107 0.6319593  26  
## [85] 0.008135235 0.6243833  23  
## [86] 0.007184363 0.5840619  19  
## [87] 0.327205494 0.5750592 852  
## [88] 0.015002641 0.5741039  39  
## [89] 0.028103539 0.5500860  70  
## [90] 0.008029583 0.5225817  19

Output di atas memberikan output di mana item Coffee menjadi lhs (sebab) maupun rhs (akibat)

inspect(subset(bakeryrules, lhs %in% "Coffee"))
##     lhs                   rhs        support     confidence coverage   
## [1] {Coffee, Tiffin}   => {Bread}    0.002324353 0.2750000  0.008452192
## [2] {Coffee, Coke}     => {Sandwich} 0.002007396 0.3114754  0.006444797
## [3] {Coffee, Truffles} => {Sandwich} 0.002113048 0.2816901  0.007501321
##     lift      count
## [1] 0.8404504 22   
## [2] 4.3354629 19   
## [3] 3.9208782 20

Output di atas memberikan hasil hanya untuk Coffee sebagai lhs

inspect(subset(bakeryrules, rhs %in% "Coffee"))
##      lhs                           rhs      support     confidence coverage   
## [1]  {Tartine}                  => {Coffee} 0.003063920 0.6304348  0.004860011
## [2]  {Bakewell}                 => {Coffee} 0.003063920 0.6041667  0.005071315
## [3]  {Vegan mincepie}           => {Coffee} 0.003169572 0.5769231  0.005493925
## [4]  {Art Tray}                 => {Coffee} 0.002746962 0.6842105  0.004014791
## [5]  {Extra Salami or Feta}     => {Coffee} 0.003275225 0.8157895  0.004014791
## [6]  {Keeping It Local}         => {Coffee} 0.005388273 0.8095238  0.006656101
## [7]  {The Nomad}                => {Coffee} 0.003275225 0.5344828  0.006127839
## [8]  {Frittata}                 => {Coffee} 0.004543053 0.5308642  0.008557845
## [9]  {Smoothies}                => {Coffee} 0.004014791 0.4935065  0.008135235
## [10] {Hearty & Seasonal}        => {Coffee} 0.005705230 0.5400000  0.010565240
## [11] {Salad}                    => {Coffee} 0.006550449 0.6262626  0.010459588
## [12] {Jam}                      => {Coffee} 0.004120444 0.2746479  0.015002641
## [13] {Chicken Stew}             => {Coffee} 0.005176968 0.3983740  0.012995246
## [14] {Jammie Dodgers}           => {Coffee} 0.006656101 0.5040000  0.013206550
## [15] {Mineral water}            => {Coffee} 0.005599577 0.3955224  0.014157422
## [16] {Tiffin}                   => {Coffee} 0.008452192 0.5479452  0.015425251
## [17] {Coke}                     => {Coffee} 0.006444797 0.3315217  0.019440042
## [18] {Spanish Brunch}           => {Coffee} 0.010882198 0.5988372  0.018172213
## [19] {Truffles}                 => {Coffee} 0.007501321 0.3697917  0.020285261
## [20] {Toast}                    => {Coffee} 0.023666138 0.7044025  0.033597464
## [21] {Scone}                    => {Coffee} 0.018066561 0.5229358  0.034548336
## [22] {Soup}                     => {Coffee} 0.015847861 0.4601227  0.034442684
## [23] {Muffin}                   => {Coffee} 0.018806128 0.4890110  0.038457475
## [24] {Alfajores}                => {Coffee} 0.019651347 0.5406977  0.036344427
## [25] {Brownie}                  => {Coffee} 0.019651347 0.4907652  0.040042261
## [26] {Juice}                    => {Coffee} 0.020602219 0.5342466  0.038563127
## [27] {Cookies}                  => {Coffee} 0.028209192 0.5184466  0.054410988
## [28] {Medialuna}                => {Coffee} 0.035182250 0.5692308  0.061806656
## [29] {Hot chocolate}            => {Coffee} 0.029582673 0.5072464  0.058320127
## [30] {Sandwich}                 => {Coffee} 0.038246170 0.5323529  0.071843634
## [31] {Pastry}                   => {Coffee} 0.047543582 0.5521472  0.086106709
## [32] {Cake}                     => {Coffee} 0.054727945 0.5269583  0.103856313
## [33] {Tea}                      => {Coffee} 0.049867934 0.3496296  0.142630745
## [34] {Bread}                    => {Coffee} 0.090015848 0.2751049  0.327205494
## [35] {Bread, Tiffin}            => {Coffee} 0.002324353 0.4782609  0.004860011
## [36] {Coke, Sandwich}           => {Coffee} 0.002007396 0.3877551  0.005176968
## [37] {Juice, Spanish Brunch}    => {Coffee} 0.002007396 0.7307692  0.002746962
## [38] {Bread, Spanish Brunch}    => {Coffee} 0.002430005 0.5111111  0.004754358
## [39] {Sandwich, Truffles}       => {Coffee} 0.002113048 0.5555556  0.003803487
## [40] {Tea, Toast}               => {Coffee} 0.003275225 0.5081967  0.006444797
## [41] {Bread, Toast}             => {Coffee} 0.003697834 0.4729730  0.007818278
## [42] {Cake, Scone}              => {Coffee} 0.002852615 0.6000000  0.004754358
## [43] {Scone, Tea}               => {Coffee} 0.003380877 0.4050633  0.008346540
## [44] {Bread, Scone}             => {Coffee} 0.003486529 0.3837209  0.009086107
## [45] {Sandwich, Soup}           => {Coffee} 0.003592182 0.6538462  0.005493925
## [46] {Cake, Soup}               => {Coffee} 0.002430005 0.5476190  0.004437401
## [47] {Soup, Tea}                => {Coffee} 0.002746962 0.3023256  0.009086107
## [48] {Bread, Soup}              => {Coffee} 0.002218700 0.3387097  0.006550449
## [49] {Cake, Muffin}             => {Coffee} 0.002324353 0.4782609  0.004860011
## [50] {Muffin, Tea}              => {Coffee} 0.002852615 0.4354839  0.006550449
## [51] {Bread, Muffin}            => {Coffee} 0.002430005 0.2987013  0.008135235
## [52] {Alfajores, Hot chocolate} => {Coffee} 0.002007396 0.5588235  0.003592182
## [53] {Alfajores, Cake}          => {Coffee} 0.002324353 0.5641026  0.004120444
## [54] {Alfajores, Tea}           => {Coffee} 0.003063920 0.4531250  0.006761754
## [55] {Alfajores, Bread}         => {Coffee} 0.004331749 0.4183673  0.010353936
## [56] {Brownie, Hot chocolate}   => {Coffee} 0.002430005 0.5897436  0.004120444
## [57] {Brownie, Cake}            => {Coffee} 0.002113048 0.4761905  0.004437401
## [58] {Brownie, Tea}             => {Coffee} 0.002218700 0.3281250  0.006761754
## [59] {Bread, Brownie}           => {Coffee} 0.003803487 0.3529412  0.010776545
## [60] {Cookies, Juice}           => {Coffee} 0.003697834 0.6034483  0.006127839
## [61] {Juice, Sandwich}          => {Coffee} 0.002746962 0.4727273  0.005810882
## [62] {Cake, Juice}              => {Coffee} 0.003909139 0.5522388  0.007078711
## [63] {Juice, Tea}               => {Coffee} 0.002007396 0.2794118  0.007184363
## [64] {Bread, Juice}             => {Coffee} 0.002958267 0.4000000  0.007395668
## [65] {Cookies, Hot chocolate}   => {Coffee} 0.003697834 0.6140351  0.006022187
## [66] {Cake, Cookies}            => {Coffee} 0.004226096 0.5797101  0.007290016
## [67] {Cookies, Tea}             => {Coffee} 0.003909139 0.3978495  0.009825674
## [68] {Bread, Cookies}           => {Coffee} 0.005282620 0.3649635  0.014474379
## [69] {Hot chocolate, Medialuna} => {Coffee} 0.003063920 0.6444444  0.004754358
## [70] {Medialuna, Pastry}        => {Coffee} 0.004860011 0.5287356  0.009191759
## [71] {Cake, Medialuna}          => {Coffee} 0.002535658 0.6857143  0.003697834
## [72] {Medialuna, Tea}           => {Coffee} 0.003697834 0.4545455  0.008135235
## [73] {Bread, Medialuna}         => {Coffee} 0.006761754 0.4000000  0.016904385
## [74] {Hot chocolate, Sandwich}  => {Coffee} 0.002535658 0.5714286  0.004437401
## [75] {Hot chocolate, Pastry}    => {Coffee} 0.003803487 0.6666667  0.005705230
## [76] {Cake, Hot chocolate}      => {Coffee} 0.006867406 0.6018519  0.011410460
## [77] {Hot chocolate, Tea}       => {Coffee} 0.002007396 0.2500000  0.008029583
## [78] {Bread, Hot chocolate}     => {Coffee} 0.006127839 0.4566929  0.013417855
## [79] {Cake, Sandwich}           => {Coffee} 0.004648706 0.6769231  0.006867406
## [80] {Sandwich, Tea}            => {Coffee} 0.005388273 0.3750000  0.014368727
## [81] {Bread, Sandwich}          => {Coffee} 0.007184363 0.4223602  0.017010037
## [82] {Cake, Pastry}             => {Coffee} 0.002746962 0.5306122  0.005176968
## [83] {Pastry, Tea}              => {Coffee} 0.004648706 0.4835165  0.009614369
## [84] {Bread, Pastry}            => {Coffee} 0.011199155 0.3840580  0.029160063
## [85] {Cake, Tea}                => {Coffee} 0.010036978 0.4222222  0.023771791
## [86] {Bread, Cake}              => {Coffee} 0.010036978 0.4298643  0.023349181
## [87] {Bread, Tea}               => {Coffee} 0.007395668 0.2631579  0.028103539
##      lift      count
## [1]  1.3178148  29  
## [2]  1.2629058  29  
## [3]  1.2059578  30  
## [4]  1.4302236  26  
## [5]  1.7052666  31  
## [6]  1.6921694  51  
## [7]  1.1172437  31  
## [8]  1.1096797  43  
## [9]  1.0315899  38  
## [10] 1.1287765  54  
## [11] 1.3090936  62  
## [12] 0.5741039  39  
## [13] 0.8327318  49  
## [14] 1.0535247  63  
## [15] 0.8267711  53  
## [16] 1.1453846  80  
## [17] 0.6929888  61  
## [18] 1.2517655 103  
## [19] 0.7729855  71  
## [20] 1.4724315 224  
## [21] 1.0931067 171  
## [22] 0.9618068 150  
## [23] 1.0221928 178  
## [24] 1.1302349 186  
## [25] 1.0258596 186  
## [26] 1.1167500 195  
## [27] 1.0837229 267  
## [28] 1.1898784 333  
## [29] 1.0603107 280  
## [30] 1.1127916 362  
## [31] 1.1541682 450  
## [32] 1.1015151 518  
## [33] 0.7308402 472  
## [34] 0.5750592 852  
## [35] 0.9997215  22  
## [36] 0.8105349  19  
## [37] 1.5275465  19  
## [38] 1.0683893  23  
## [39] 1.1612927  20  
## [40] 1.0622973  31  
## [41] 0.9886681  35  
## [42] 1.2541961  27  
## [43] 0.8467147  32  
## [44] 0.8021022  33  
## [45] 1.3667522  34  
## [46] 1.1447028  23  
## [47] 0.6319593  26  
## [48] 0.7080139  21  
## [49] 0.9997215  22  
## [50] 0.9103036  27  
## [51] 0.6243833  23  
## [52] 1.1681238  19  
## [53] 1.1791587  22  
## [54] 0.9471794  29  
## [55] 0.8745245  41  
## [56] 1.2327569  23  
## [57] 0.9953937  20  
## [58] 0.6858885  21  
## [59] 0.7377624  36  
## [60] 1.2614041  35  
## [61] 0.9881545  26  
## [62] 1.1543596  37  
## [63] 0.5840619  19  
## [64] 0.8361307  28  
## [65] 1.2835340  35  
## [66] 1.2117837  40  
## [67] 0.8316354  37  
## [68] 0.7628930  50  
## [69] 1.3470995  29  
## [70] 1.1052303  46  
## [71] 1.4333670  24  
## [72] 0.9501486  35  
## [73] 0.8361307  64  
## [74] 1.1944725  24  
## [75] 1.3935512  36  
## [76] 1.2580671  65  
## [77] 0.5225817  19  
## [78] 0.9546375  58  
## [79] 1.4149905  44  
## [80] 0.7838726  51  
## [81] 0.8828710  68  
## [82] 1.1091530  26  
## [83] 1.0107075  44  
## [84] 0.8028067 106  
## [85] 0.8825824  95  
## [86] 0.8985568  95  
## [87] 0.5500860  70

Output di atas memberikan hasil hanya untuk Coffee sebagai rhs

Output-output item Coffee dapat menjadi bahan pertimbangan toko untuk membuat bundle khusus Coffe yang memanfaatkan performa penjualan Coffee sebagai produk terlaris untuk mendongrak penjualan produk lainnya

Kesimpulan

Kesimpulan Output:
1. Coffee menempati urutan pertama produk terlaris diikuti oleh Bread dan Tea
2. Sandwich dapat dibundle dengan bundle 1 = (Coffee, Coke, Sandwich), bundle 2 = (Coffee, Truffles, Sandwich), dan bundle 3 = (Coke, Sandwich) untuk menaikkan performa penjualan karena asosiasi produk tersebut 3-4x lebih tinggi condong ke Sandwich dibanding produk lain
3. Bundle lain seperti (Hot chocolate, Tea, Cake) yang memiliki kecondongan 1.8x lebih besar dan (Soup, Tea) yang memiliki kecondongan 2.4x lebih besar juga dapat dijadikan bundle
4. Coffee dapat dibundle dengan produk dengan performa penjualan yang kurang optimal untuk meningkatkan performa produk terkait

Kesimpulan Packages:
1. Package arules merupakan package powerfull untuk analisis MBA di R
2. Package arules hanya bisa dipakai menggunakan file berformat txt dan csv
3. Jika format file belum sesuai perlu penyesuaian terlebih dahulu sebelum bisa menggunakan arules
4. Perlu mengecek nama item di data awal apakah memiliki tanda baca yang bisa menyebabkan perhitungan package arules terganggu