WhatsApp Chat Sentiment Analysis in R

Market Basket Analytics: Learn How to Perform Market Basket Analysis in R

Market Basket Analysis | Marketing Analytics

Market basket analysis is a technique used in Data mining and Data science to detect association between goods, services or any other form of transaction done by the customers. It is also commonly termed as Association analysis and Frequent items mining. For example customers usually buy different goods and put them in a basket before checking out at the counter and from the data generated through the billing counter a marketer can utilise the data to find associations and relationship between different goods and use the same insights to take pricing, promotions and other marketing decisions.

Some Essentials of Market Basket Analysis:

Lift Ratio - The lift ratio calculates the efficiency of the rule in finding consequences, compared to a random selection of transactions. A Lift ratio of greater than one generally suggests some applicability of the rule.

Support - The support provides the probability in favour of the event under analysis. A support of less than 50% is not considered to be good while 70% and above is fairly good and above 90% shows a strong association between two products.

Confidence - the probability that a transaction that contains the items on the left hand side of the rule (Bread) also contains the item on the right hand side (Butter). The higher the confidence, the greater the likelihood that the item on the right hand side will be purchased.

Applications of Market Basket Analysis

Product bundling: One of the widely used technique by retailers to maximise their profits by selling two or more products together in a package which would cost more if bought separately. McDonald’s has pioneered this technique and has been using it globally to maximise its revenue.

Recommendation system: It is already being used by almost all the E-retailers like Amazon, Flipkart, Alibaba and Netflix to increase share of wallet by recommending or showcasing related products to the user whenever they land on a specific page or try to buy a product.

Cross-Selling: Just like recommendation system used by the online retailers, cross selling is one of the major technique used by brick and mortar stores to increase the revenue by selling more products by recommending products which a customer might be interested in if he/she buys a specific product. for instance recommending to buy butter when a customer buys bread.

Store Layout: Market basket analysis can be used to design and place products in the stores as per the product relatedness and help customers find products which are bought together without ant difficulty.

Promotions: Retailers come out with multiple promotions which includes selling two or more products at a discounted rate or giving away complimentary products with specify products. effective promotions can be designed if we use market basket analysis to recognise relation between different products and analyse the buying behaviour of the customers.

How to perform Market Basket Analysis in R

Download R file

# Set Working Directory as per your preference


#Install and Load required packages


#Download and Read groceries.csv file 

>Groceries <- read.transactions("groceries.csv")

#Set the minimum support to 0.001 and confidence to 0.8 and see the top 5 rules

>rules <- apriori(Groceries, parameter = list(supp = 0.001, conf = 0.8)) 

>rules<-sort(rules, by="confidence", decreasing=TRUE)


Eliminate the repeated rules
>subset.matrix <- is.subset(rules, rules)
>subset.matrix[lower.tri(subset.matrix, diag=T)] <- NA

>subset.matrix <- as.data.frame(subset.matrix)
>redundant <- colSums(subset.matrix, na.rm=T) >= 1

>rules.pruned <- rules[!redundant]

Business Problem: What customers buy when they buy Whole Milk?

>rules<-apriori(data=Groceries, parameter=list(supp=0.001,conf = 0.08), 
appearance = list(default="lhs",rhs="whole milk"),
control = list(verbose=F))
>rules<-sort(rules, decreasing=TRUE,by="confidence")

>plot(rules,method="graph",shading="confidence", control = list(verbose = TRUE))




write to us at info@planetanalytics.in 
stay connected to Planet Analytics