SlideShare a Scribd company logo
1 of 41
Analyzing Consumer Behaviour
using
Market Basket Analysis
Data Science Using R and Excel
Association Rule Mining
• An observant Wal-Mart store manager discovered a strong association between a
brand of babies nappies (diapers) and a brand of beer. Analysis of purchases revealed
that they were made by men, on Friday evenings mainly between 6pm and 7pm. The
supermarket figured out the following rationale:
• Because packs of diapers are very large, the wife, who in most cases made the household
purchases, left the diaper purchase to her husband.
• Being the end of the working week, the husband and father also wanted to get some beer in for
the weekend.
Beer & Nappies
• They put the premium beer display next to the diapers
• The result was that the fathers buying diapers and who also usually bought beer now
bought the premium beer (the up-sell) as it was so conveniently placed next to the
diapers
• Significantly, the men that did not buy beer before began to purchase it because it was so
visible and handy - just next to the nappies (the cross-sell).
• Beer sales skyrocketed
What did the supermarket do with this knowledge?
What is consumer behavior ?
•A consumer activity in deciding to
purchase, use, as well as consume the
purchased goods and services.
What is Market Basket Analysis ?
• Identifies customers purchasing habits.
• It provides insight into the combination of products within a customers
'basket’.
• The term 'basket' normally applies to a single order.
• However, the analysis can be applied to other variations.
• We often compare all orders associated with a single customer.
• Ultimately, the purchasing insights provide the potential to create cross sell
propositions:
• Which product combinations are bought
• When they are purchased; and in
• What sequence
What is Association Rule Mining ?
• Recent research has positioned association mining as one of the most
popular tools in retail analytics.
• A data mining technique which generates rules in the form of X ⇒ Y ,
where X and Y are two non-overlapping discrete sets.
• A rule is considered as significant if it is satisfied by at least a certain
percentage of cases (minimum support) and its confidence is above a
certain threshold (minimum confidence).
• Conventional association mining considers “positive” relations in the form
of X ⇒ Y .
• However, negative associations in the form of X ⇒ ¬Y , where ¬Y represents
the negation (absence) of Y , can also be discovered through association
mining.
How does it help ?
How does it help ?
How does it help ?
How does it help ?
How does it help ?
• Developing this understanding enables businesses to promote their
most profitable products.
• It can also encourage customers to buy items that might have
otherwise been overlooked or missed.
• Market basket analysis delivers the "Amazon effect" to your business.
How does it help ?
• Changing the store layout according to trends
• Customer behavior analysis
• Catalogue design
• Cross marketing on online stores
• What are the trending items customers buy ?
• Customized emails with add-on sales
ID ITEMS
1 {Bread, Milk}
2 {Bread, Diapers, Beer, Eggs}
3 {Milk, Diapers, Beer, Cola}
4 {Bread, Milk, Diapers, Beer}
5 {Bread, Milk, Diapers, Cola}
An illustration
The Association rule
ANTECEDENT CONSEQUENT
A B=> [Support, Confidence]
{BEER}{DIAPER} -> [ Support = 60% , Confidence = 75 % ]
In 60 % of cases Diaper and Beer are sold together. In 75 % of cases when someone purchases a
Diaper , a Beer is also purchased.
ID Apples Bread Cheese Dates Eggs Fish Grapes Honey Ice-Cream
1 1 1 1 1 1
2 1 1 1
3 1 1 1
4 1 1 1
5 1 1
6 1 1
7 1 1 1
8 1 1
9 1 1
10 1 1
11 1 1
12 1
13 1 1
14 1 1
15 1 1
16 1
17 1 1
18 1 1 1 1 1
19 1 1 1 1 1
20 1
Software used
• MS Excel
• Tableau
• Hadoop
• R Studio
• A very useful practical application
• Rule – If a basket contains apples and cheese, then it is likely to contain
bread
• It is important to talk of a measure at this point – Support
• Support – Given an itemset L, the support of L is the percentage of
transactions that contain L.
• Example – Support of {eggs} is 25%, support of {apples, bread} is 15%, support of
{eggs, grapes} is 10%
• Point to ponder – if the support of an itemset with one item, let us say X is p%, then
the support for an itemset which has X as one of the items will always be less than or
equal to p%.
Discovering Rules in a Market Basket
• Rule – If a basket contains X, it is likely to contain Y.
• X – apples, Y – bread. So, the rule that is being mentioned is that if a
customer buys apples he is likely to buy bread.
• The rule is depicted as {apples}  {bread}
• X could be {apples, bread}, Y – {dates}. Therefore, the rule is, if a
customer buys apples and breads he is likely to buy dates.
• It is depicted as {apples, bread}  {dates}
Discovering Rules
Measures of Rules - Confidence
•Confidence of a rule, {X} -> {Y}
• When the if part is true, how often is the then part true? Accuracy if you will.
• If {bread, eggs, milk} has a support of 0.2 and {bread, eggs} also has a support of 0.2, the
confidence of the rule {bread, eggs} -> {milk} is 1, i.e., 100% of time a customer buys bread and
eggs, milk is bought as well. The rule is therefore correct for 100% of the transactions.
Measures of Rules - Lift
•Lift of a rule, {X} -> {Y}
• How many times more often X and Y occur together than expected (if they are statistically independent of
each other)? Really related or coincidental?
• Lift is 1 if {X} and {Y} are statistically independent of one another. A lift of {X} -> {Y} greater than 1 indicates
that there is some usefulness to the rule.
• A larger value of lift suggests a greater strength of the association between X and Y
• 1000 transactions, {milk, eggs} - 300, {milk}- 500, {eggs} - 400, Lift (milk->eggs) = 0.3/0.5*0.4 = 1.5
Measures of Rules - Leverage
•Leverage of a rule, {X} -> {Y}
• How many times more often X and Y occur together than expected (if they are statistically independent of
each other)? Really related or coincidental?
Leverage ( X -> Y) = Support(X*Y) — Support (X) x Support (Y)
• Leverage is 0 if {X} and {Y} are statistically independent of one another.
• A leverage of {X} -> {Y} greater than 0 indicates that there is some usefulness to the rule.
• A larger value of lift indicates a stronger relationship between X and Y
• 1000 transactions, {milk, eggs} - 300, {milk}- 500, {eggs} - 400, Leverage (milk->eggs) = 0.3 - 0.5*0.4 = 0.1
• Confidence, Lift, Leverage – why so many?
• Confidence can identify trustworthy rules
• It cannot tell you if the rule is coincidental
• Lift and Leverage helps identify interesting rules and filters the
ones which are coincidental.
Measures of Rules
• Apriori is generally invoked with a minimum support threshold – let us say, 0.1
Apriori Algorithm (Itemset Lattice)
ϕ
A B C D
AB AC AD BC BD CD
ABC ABD ACD BCD
ABCD
• Apriori is generally invoked with a minimum support threshold – let
us say, 0.1
• Rules based on the frequent itemsets:
• {B}{C}
• {C}{B}
• {B}{D}
• {D}{B}
• {C}{D}
• {D}{C}
• {B}{CD}
• {C}{BD}
• {D}{BC}
Apriori Algorithm - Rules
Association rule mining example using Excel : Step 1
Total
2928
Items Support
vegetables 0.606557377
baby 0.271174863
fruit 0.296789617
milk 0.303620219
dvds 0.211065574
meat 0.24931694
COUNTIF(INDIRECT(vegetables)
,1)/total
Association rule mining example using Excel : Step 2
X Y
vegetables milk
if veg then milk
Vegetables-->Milk
Support (Vegetables ^ Milk) Support (Vegetables) Confidence Suport (Milk) Lift
0.184084699 0.606557377 0.303490991 0.303620219 0.999574378
COUNTIFS(INDIRECT(vegetables),1,INDIRECT(milk),1)/total
Support (Vegetables ^ Milk)
Support (Vegetables)
Confidence
Support (Milk)
Association rule mining example using Excel : Step 3
0.99957438 vegetables baby fruit milk dvds meat
vegetables 1.00 0.96 0.99 1.00 0.96 1.01
baby 0.96 1.00 1.05 1.00 1.40 1.01
fruit 0.99 1.05 1.00 1.00 1.03 0.90
milk 1.00 1.00 1.00 1.00 0.98 1.06
dvds 0.96 1.40 1.03 0.98 1.00 0.96
meat 1.01 1.01 0.90 1.06 0.96 1.00
CREATING A LIFT TABLE
Association rule mining example using R
Output
 transdata<-read.csv("Transactions.csv")
 MyTransaction<-as(transdata,"transactions")
 itemsets<-apriori(MyTransaction,parameter = list(minlen=1,maxlen=1, support=0.05,target="frequent
itemsets"))
 inspect(head(sort(itemsets,by="support")))
Apriori Example
Apriori Example
Apriori Example (Coding in R)
Apriori Example (Coding in R)
library(arules)
library(arulesViz)
library(tidyverse)
library(readxl)
library(knitr)
library(ggplot2)
library(lubridate)
library(plyr)
library(dplyr)
Apriori Example (Coding in R)
retail <- read_excel("Online Retail.xlsx")
retail
retail <- retail[complete.cases(retail), ]
retail %>% mutate(Description = as.factor(Description))
retail %>% mutate(Country = as.factor(Country))
retail$Date <- as.Date(retail$InvoiceDate)
TransTime<- format(retail$InvoiceDate,"%H:%M:%S")
InvoiceNo <- as.numeric(as.character(retail$InvoiceNo))
#Bind new columns TransTime and InvoiceNo into dataframe retail
cbind(retail,TransTime)
cbind(retail,InvoiceNo)
glimpse(retail)
library(plyr)
transactionData <- ddply(retail,c("InvoiceNo","Date"), function(df1)paste(df1$Description, collapse = ","))
transactionData
Apriori Example
Apriori Example
Apriori Example
Apriori Example
The interpretation is straight forward:
•100% customers who bought “WOBBLY CHICKEN” also bought “DECORATION”.
•100% customers who bought “DECOUPAGE” also bought “GREETING CARD”.
Apriori Example
Apriori Example
Apriori Example
Parallel coordinates plot for 20 rules
3 2 1 rhs
HOOK
WOBBLYCHICKEN
METAL
PARTYPIZZA DISH GREEN POLKADOT
CHILDS GARDEN SPADE BLUE
CHOCOLATE SPOTS
ART LIGHTS
WRAP
PARTYPIZZA DISH PINK POLKADOT
Position
The RHS is the
Consequent or the
item we propose the
customer will buy;
the positions are in
the LHS where 2 is
the most recent
addition to our
basket and 1 is the
item we previously
had.

More Related Content

What's hot

Market Basket Analysis in SAS
Market Basket Analysis in SASMarket Basket Analysis in SAS
Market Basket Analysis in SASAndrew Kramer
 
Market basket analysis using apriori algorithm on
Market basket analysis using apriori algorithm onMarket basket analysis using apriori algorithm on
Market basket analysis using apriori algorithm onMadhu Kiran
 
Business Intelligence & Predictive Analytic by Prof. Lili Saghafi
Business Intelligence & Predictive Analytic by Prof. Lili SaghafiBusiness Intelligence & Predictive Analytic by Prof. Lili Saghafi
Business Intelligence & Predictive Analytic by Prof. Lili SaghafiProfessor Lili Saghafi
 
Association rule mining
Association rule miningAssociation rule mining
Association rule miningUtkarsh Sharma
 
Predictive Analytics - An Overview
Predictive Analytics - An OverviewPredictive Analytics - An Overview
Predictive Analytics - An OverviewMachinePulse
 
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...Simplilearn
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data miningKamal Acharya
 
Business analytics
Business analyticsBusiness analytics
Business analyticsDinakar nk
 
Data Mining in Marketing
Data Mining in MarketingData Mining in Marketing
Data Mining in MarketingShweta Metar
 
Telecom Churn Prediction Presentation
Telecom Churn Prediction PresentationTelecom Churn Prediction Presentation
Telecom Churn Prediction PresentationPinintiHarishReddy
 
Data mining introduction
Data mining introductionData mining introduction
Data mining introductionBasma Gamal
 
Churn Analysis in Telecom Industry
Churn Analysis in Telecom IndustryChurn Analysis in Telecom Industry
Churn Analysis in Telecom IndustrySatyam Barsaiyan
 

What's hot (20)

Market Basket Analysis in SAS
Market Basket Analysis in SASMarket Basket Analysis in SAS
Market Basket Analysis in SAS
 
Market basket analysis using apriori algorithm on
Market basket analysis using apriori algorithm onMarket basket analysis using apriori algorithm on
Market basket analysis using apriori algorithm on
 
Assosiate rule mining
Assosiate rule miningAssosiate rule mining
Assosiate rule mining
 
Business Intelligence & Predictive Analytic by Prof. Lili Saghafi
Business Intelligence & Predictive Analytic by Prof. Lili SaghafiBusiness Intelligence & Predictive Analytic by Prof. Lili Saghafi
Business Intelligence & Predictive Analytic by Prof. Lili Saghafi
 
Data mining
Data miningData mining
Data mining
 
Association rule mining
Association rule miningAssociation rule mining
Association rule mining
 
Predictive analytics
Predictive analytics Predictive analytics
Predictive analytics
 
Predictive Analytics - An Overview
Predictive Analytics - An OverviewPredictive Analytics - An Overview
Predictive Analytics - An Overview
 
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data mining
 
Text mining
Text miningText mining
Text mining
 
Business analytics
Business analyticsBusiness analytics
Business analytics
 
Data Mining in Marketing
Data Mining in MarketingData Mining in Marketing
Data Mining in Marketing
 
Telecom Churn Prediction Presentation
Telecom Churn Prediction PresentationTelecom Churn Prediction Presentation
Telecom Churn Prediction Presentation
 
Business Analytics
 Business Analytics  Business Analytics
Business Analytics
 
Retail Analytics
Retail AnalyticsRetail Analytics
Retail Analytics
 
Data mining introduction
Data mining introductionData mining introduction
Data mining introduction
 
Churn Analysis in Telecom Industry
Churn Analysis in Telecom IndustryChurn Analysis in Telecom Industry
Churn Analysis in Telecom Industry
 
Data Mining: Association Rules Basics
Data Mining: Association Rules BasicsData Mining: Association Rules Basics
Data Mining: Association Rules Basics
 
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
 

Similar to Market Basket Analysis

Lect6 Association rule & Apriori algorithm
Lect6 Association rule & Apriori algorithmLect6 Association rule & Apriori algorithm
Lect6 Association rule & Apriori algorithmhktripathy
 
6. Association Rule.pdf
6. Association Rule.pdf6. Association Rule.pdf
6. Association Rule.pdfJyoti Yadav
 
What is FP Growth Analysis and How Can a Business Use Frequent Pattern Mining...
What is FP Growth Analysis and How Can a Business Use Frequent Pattern Mining...What is FP Growth Analysis and How Can a Business Use Frequent Pattern Mining...
What is FP Growth Analysis and How Can a Business Use Frequent Pattern Mining...Smarten Augmented Analytics
 
MODULE 5 _ Mining frequent patterns and associations.pptx
MODULE 5 _ Mining frequent patterns and associations.pptxMODULE 5 _ Mining frequent patterns and associations.pptx
MODULE 5 _ Mining frequent patterns and associations.pptxnikshaikh786
 
AssociationRule.pdf
AssociationRule.pdfAssociationRule.pdf
AssociationRule.pdfWailaBaba
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligenceGeo Marian
 
Association 04.03.14
Association   04.03.14Association   04.03.14
Association 04.03.14rahulmath80
 
Association Rule mining
Association Rule miningAssociation Rule mining
Association Rule miningMegha Sharma
 
2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_Rules2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_RulesFEG
 
Data Science - Part VI - Market Basket and Product Recommendation Engines
Data Science - Part VI - Market Basket and Product Recommendation EnginesData Science - Part VI - Market Basket and Product Recommendation Engines
Data Science - Part VI - Market Basket and Product Recommendation EnginesDerek Kane
 
Rules of data mining
Rules of data miningRules of data mining
Rules of data miningSulman Ahmed
 
Association rule Intuition
Association rule  IntuitionAssociation rule  Intuition
Association rule IntuitionRahul Tiwari
 
What goes with what (Market Basket Analysis)
What goes with what (Market Basket Analysis)What goes with what (Market Basket Analysis)
What goes with what (Market Basket Analysis)Kumar P
 
Instacart Market Basket Analysis
Instacart Market Basket AnalysisInstacart Market Basket Analysis
Instacart Market Basket AnalysisSharanya Prathap
 
Market Basket Analysis of bakery Shop
Market Basket Analysis of bakery ShopMarket Basket Analysis of bakery Shop
Market Basket Analysis of bakery ShopVarunSahdev2
 

Similar to Market Basket Analysis (20)

Lect6 Association rule & Apriori algorithm
Lect6 Association rule & Apriori algorithmLect6 Association rule & Apriori algorithm
Lect6 Association rule & Apriori algorithm
 
6. Association Rule.pdf
6. Association Rule.pdf6. Association Rule.pdf
6. Association Rule.pdf
 
What is FP Growth Analysis and How Can a Business Use Frequent Pattern Mining...
What is FP Growth Analysis and How Can a Business Use Frequent Pattern Mining...What is FP Growth Analysis and How Can a Business Use Frequent Pattern Mining...
What is FP Growth Analysis and How Can a Business Use Frequent Pattern Mining...
 
MODULE 5 _ Mining frequent patterns and associations.pptx
MODULE 5 _ Mining frequent patterns and associations.pptxMODULE 5 _ Mining frequent patterns and associations.pptx
MODULE 5 _ Mining frequent patterns and associations.pptx
 
Unit 4_ML.pptx
Unit 4_ML.pptxUnit 4_ML.pptx
Unit 4_ML.pptx
 
AssociationRule.pdf
AssociationRule.pdfAssociationRule.pdf
AssociationRule.pdf
 
Business intelligence
Business intelligenceBusiness intelligence
Business intelligence
 
Apriori Algorithm.pptx
Apriori Algorithm.pptxApriori Algorithm.pptx
Apriori Algorithm.pptx
 
Association 04.03.14
Association   04.03.14Association   04.03.14
Association 04.03.14
 
BAS 250 Lecture 4
BAS 250 Lecture 4BAS 250 Lecture 4
BAS 250 Lecture 4
 
Association Rule mining
Association Rule miningAssociation Rule mining
Association Rule mining
 
2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_Rules2023 Supervised_Learning_Association_Rules
2023 Supervised_Learning_Association_Rules
 
Data Science - Part VI - Market Basket and Product Recommendation Engines
Data Science - Part VI - Market Basket and Product Recommendation EnginesData Science - Part VI - Market Basket and Product Recommendation Engines
Data Science - Part VI - Market Basket and Product Recommendation Engines
 
Rules of data mining
Rules of data miningRules of data mining
Rules of data mining
 
Data mining arm-2009-v0
Data mining arm-2009-v0Data mining arm-2009-v0
Data mining arm-2009-v0
 
Association rule Intuition
Association rule  IntuitionAssociation rule  Intuition
Association rule Intuition
 
What goes with what (Market Basket Analysis)
What goes with what (Market Basket Analysis)What goes with what (Market Basket Analysis)
What goes with what (Market Basket Analysis)
 
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
 
Instacart Market Basket Analysis
Instacart Market Basket AnalysisInstacart Market Basket Analysis
Instacart Market Basket Analysis
 
Market Basket Analysis of bakery Shop
Market Basket Analysis of bakery ShopMarket Basket Analysis of bakery Shop
Market Basket Analysis of bakery Shop
 

Recently uploaded

DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home ServiceSapana Sha
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 

Recently uploaded (20)

DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
Decoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in ActionDecoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in Action
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 

Market Basket Analysis

  • 1. Analyzing Consumer Behaviour using Market Basket Analysis Data Science Using R and Excel Association Rule Mining
  • 2.
  • 3. • An observant Wal-Mart store manager discovered a strong association between a brand of babies nappies (diapers) and a brand of beer. Analysis of purchases revealed that they were made by men, on Friday evenings mainly between 6pm and 7pm. The supermarket figured out the following rationale: • Because packs of diapers are very large, the wife, who in most cases made the household purchases, left the diaper purchase to her husband. • Being the end of the working week, the husband and father also wanted to get some beer in for the weekend. Beer & Nappies
  • 4. • They put the premium beer display next to the diapers • The result was that the fathers buying diapers and who also usually bought beer now bought the premium beer (the up-sell) as it was so conveniently placed next to the diapers • Significantly, the men that did not buy beer before began to purchase it because it was so visible and handy - just next to the nappies (the cross-sell). • Beer sales skyrocketed What did the supermarket do with this knowledge?
  • 5. What is consumer behavior ? •A consumer activity in deciding to purchase, use, as well as consume the purchased goods and services.
  • 6. What is Market Basket Analysis ? • Identifies customers purchasing habits. • It provides insight into the combination of products within a customers 'basket’. • The term 'basket' normally applies to a single order. • However, the analysis can be applied to other variations. • We often compare all orders associated with a single customer. • Ultimately, the purchasing insights provide the potential to create cross sell propositions: • Which product combinations are bought • When they are purchased; and in • What sequence
  • 7. What is Association Rule Mining ? • Recent research has positioned association mining as one of the most popular tools in retail analytics. • A data mining technique which generates rules in the form of X ⇒ Y , where X and Y are two non-overlapping discrete sets. • A rule is considered as significant if it is satisfied by at least a certain percentage of cases (minimum support) and its confidence is above a certain threshold (minimum confidence). • Conventional association mining considers “positive” relations in the form of X ⇒ Y . • However, negative associations in the form of X ⇒ ¬Y , where ¬Y represents the negation (absence) of Y , can also be discovered through association mining.
  • 8. How does it help ?
  • 9. How does it help ?
  • 10. How does it help ?
  • 11. How does it help ?
  • 12. How does it help ? • Developing this understanding enables businesses to promote their most profitable products. • It can also encourage customers to buy items that might have otherwise been overlooked or missed. • Market basket analysis delivers the "Amazon effect" to your business.
  • 13. How does it help ? • Changing the store layout according to trends • Customer behavior analysis • Catalogue design • Cross marketing on online stores • What are the trending items customers buy ? • Customized emails with add-on sales
  • 14. ID ITEMS 1 {Bread, Milk} 2 {Bread, Diapers, Beer, Eggs} 3 {Milk, Diapers, Beer, Cola} 4 {Bread, Milk, Diapers, Beer} 5 {Bread, Milk, Diapers, Cola} An illustration
  • 15. The Association rule ANTECEDENT CONSEQUENT A B=> [Support, Confidence] {BEER}{DIAPER} -> [ Support = 60% , Confidence = 75 % ] In 60 % of cases Diaper and Beer are sold together. In 75 % of cases when someone purchases a Diaper , a Beer is also purchased.
  • 16. ID Apples Bread Cheese Dates Eggs Fish Grapes Honey Ice-Cream 1 1 1 1 1 1 2 1 1 1 3 1 1 1 4 1 1 1 5 1 1 6 1 1 7 1 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 13 1 1 14 1 1 15 1 1 16 1 17 1 1 18 1 1 1 1 1 19 1 1 1 1 1 20 1
  • 17. Software used • MS Excel • Tableau • Hadoop • R Studio
  • 18. • A very useful practical application • Rule – If a basket contains apples and cheese, then it is likely to contain bread • It is important to talk of a measure at this point – Support • Support – Given an itemset L, the support of L is the percentage of transactions that contain L. • Example – Support of {eggs} is 25%, support of {apples, bread} is 15%, support of {eggs, grapes} is 10% • Point to ponder – if the support of an itemset with one item, let us say X is p%, then the support for an itemset which has X as one of the items will always be less than or equal to p%. Discovering Rules in a Market Basket
  • 19. • Rule – If a basket contains X, it is likely to contain Y. • X – apples, Y – bread. So, the rule that is being mentioned is that if a customer buys apples he is likely to buy bread. • The rule is depicted as {apples}  {bread} • X could be {apples, bread}, Y – {dates}. Therefore, the rule is, if a customer buys apples and breads he is likely to buy dates. • It is depicted as {apples, bread}  {dates} Discovering Rules
  • 20. Measures of Rules - Confidence •Confidence of a rule, {X} -> {Y} • When the if part is true, how often is the then part true? Accuracy if you will. • If {bread, eggs, milk} has a support of 0.2 and {bread, eggs} also has a support of 0.2, the confidence of the rule {bread, eggs} -> {milk} is 1, i.e., 100% of time a customer buys bread and eggs, milk is bought as well. The rule is therefore correct for 100% of the transactions.
  • 21. Measures of Rules - Lift •Lift of a rule, {X} -> {Y} • How many times more often X and Y occur together than expected (if they are statistically independent of each other)? Really related or coincidental? • Lift is 1 if {X} and {Y} are statistically independent of one another. A lift of {X} -> {Y} greater than 1 indicates that there is some usefulness to the rule. • A larger value of lift suggests a greater strength of the association between X and Y • 1000 transactions, {milk, eggs} - 300, {milk}- 500, {eggs} - 400, Lift (milk->eggs) = 0.3/0.5*0.4 = 1.5
  • 22. Measures of Rules - Leverage •Leverage of a rule, {X} -> {Y} • How many times more often X and Y occur together than expected (if they are statistically independent of each other)? Really related or coincidental? Leverage ( X -> Y) = Support(X*Y) — Support (X) x Support (Y) • Leverage is 0 if {X} and {Y} are statistically independent of one another. • A leverage of {X} -> {Y} greater than 0 indicates that there is some usefulness to the rule. • A larger value of lift indicates a stronger relationship between X and Y • 1000 transactions, {milk, eggs} - 300, {milk}- 500, {eggs} - 400, Leverage (milk->eggs) = 0.3 - 0.5*0.4 = 0.1
  • 23. • Confidence, Lift, Leverage – why so many? • Confidence can identify trustworthy rules • It cannot tell you if the rule is coincidental • Lift and Leverage helps identify interesting rules and filters the ones which are coincidental. Measures of Rules
  • 24. • Apriori is generally invoked with a minimum support threshold – let us say, 0.1 Apriori Algorithm (Itemset Lattice) ϕ A B C D AB AC AD BC BD CD ABC ABD ACD BCD ABCD
  • 25. • Apriori is generally invoked with a minimum support threshold – let us say, 0.1 • Rules based on the frequent itemsets: • {B}{C} • {C}{B} • {B}{D} • {D}{B} • {C}{D} • {D}{C} • {B}{CD} • {C}{BD} • {D}{BC} Apriori Algorithm - Rules
  • 26. Association rule mining example using Excel : Step 1 Total 2928 Items Support vegetables 0.606557377 baby 0.271174863 fruit 0.296789617 milk 0.303620219 dvds 0.211065574 meat 0.24931694 COUNTIF(INDIRECT(vegetables) ,1)/total
  • 27. Association rule mining example using Excel : Step 2 X Y vegetables milk if veg then milk Vegetables-->Milk Support (Vegetables ^ Milk) Support (Vegetables) Confidence Suport (Milk) Lift 0.184084699 0.606557377 0.303490991 0.303620219 0.999574378 COUNTIFS(INDIRECT(vegetables),1,INDIRECT(milk),1)/total Support (Vegetables ^ Milk) Support (Vegetables) Confidence Support (Milk)
  • 28. Association rule mining example using Excel : Step 3 0.99957438 vegetables baby fruit milk dvds meat vegetables 1.00 0.96 0.99 1.00 0.96 1.01 baby 0.96 1.00 1.05 1.00 1.40 1.01 fruit 0.99 1.05 1.00 1.00 1.03 0.90 milk 1.00 1.00 1.00 1.00 0.98 1.06 dvds 0.96 1.40 1.03 0.98 1.00 0.96 meat 1.01 1.01 0.90 1.06 0.96 1.00 CREATING A LIFT TABLE
  • 29. Association rule mining example using R Output  transdata<-read.csv("Transactions.csv")  MyTransaction<-as(transdata,"transactions")  itemsets<-apriori(MyTransaction,parameter = list(minlen=1,maxlen=1, support=0.05,target="frequent itemsets"))  inspect(head(sort(itemsets,by="support")))
  • 33. Apriori Example (Coding in R) library(arules) library(arulesViz) library(tidyverse) library(readxl) library(knitr) library(ggplot2) library(lubridate) library(plyr) library(dplyr)
  • 34. Apriori Example (Coding in R) retail <- read_excel("Online Retail.xlsx") retail retail <- retail[complete.cases(retail), ] retail %>% mutate(Description = as.factor(Description)) retail %>% mutate(Country = as.factor(Country)) retail$Date <- as.Date(retail$InvoiceDate) TransTime<- format(retail$InvoiceDate,"%H:%M:%S") InvoiceNo <- as.numeric(as.character(retail$InvoiceNo)) #Bind new columns TransTime and InvoiceNo into dataframe retail cbind(retail,TransTime) cbind(retail,InvoiceNo) glimpse(retail) library(plyr) transactionData <- ddply(retail,c("InvoiceNo","Date"), function(df1)paste(df1$Description, collapse = ",")) transactionData
  • 38. Apriori Example The interpretation is straight forward: •100% customers who bought “WOBBLY CHICKEN” also bought “DECORATION”. •100% customers who bought “DECOUPAGE” also bought “GREETING CARD”.
  • 41. Apriori Example Parallel coordinates plot for 20 rules 3 2 1 rhs HOOK WOBBLYCHICKEN METAL PARTYPIZZA DISH GREEN POLKADOT CHILDS GARDEN SPADE BLUE CHOCOLATE SPOTS ART LIGHTS WRAP PARTYPIZZA DISH PINK POLKADOT Position The RHS is the Consequent or the item we propose the customer will buy; the positions are in the LHS where 2 is the most recent addition to our basket and 1 is the item we previously had.