Market Basket Analysis(MBA) is one of the key techniques used by large retailers to uncover associations between items. It works by looking for combinations of items that occur together frequently in transactions.
In retail store, most purchases are bought on impulse, MBA gives clues to the store owners as to what a customer might have bought if the idea had occurred to them hence, it’s MBA can be used in deciding the location and promotion of goods inside the store.
If as has been observed, purchasers of yogurt are more likely to buy a short cake, then high margin short cakes can be placed near the yogurt aisle. The outcome of this type of technique in simple terms is a set of rules that can be understood as “if this, then that”
Imagine 10000 receipts sitting on your table. Each receipt represents a transaction with items that were purchased. The receipt is a representation of stuff that went into a customer's basket — and therefore 'Market Basket Analysis
load the libraries to use
library(arules)
Warning: package 'arules' was built under R version 4.2.3
Loading required package: Matrix
Warning: package 'Matrix' was built under R version 4.3.1
Attaching package: 'arules'
The following objects are masked from 'package:base':
abbreviate, write
library(datasets)
#load the data setdata("Groceries")
lets explore the data before making any rules
#create an item frequency plot the top 20 itemsitemFrequencyPlot(Groceries, topN =20, type ="absolute")
we set the minimum support to 0.001
confidence of 0.8
show the top 5 rules
#Get the rulesrules <-apriori(Groceries, parameter =list(support =0.001, conf =0.8))
Warning in apriori(Groceries, parameter = list(supp = 0.001, conf = 0.8, :
Mining stopped (maxlen reached). Only patterns up to a length of 3 returned!