You are on page 1of 30

Market Basket

Analysis
Prepared by: Amna Altaf
Market Basket Analysis
• A technique which identifies the strength of association between pairs of
products purchased together and identify patterns of co-occurence.

• It makes if-then scenario rules, for example


 If item A is purchased then item B is likely to be purchased

• The rules are probabilistic (i.e. they are derived from the frequencies of co-
occurence in the observation)
Market Basket Analysis
Advantages of Market Basket Analysis
• It is mostly used in
Behavior Analysis
Recommendation Engines
Bundle Pricing
Product Placement
How Market Basket Analysis Work?
• Consider an example of market basket analysis for a super market
• What you need- Data at transaction level
• This lists all items bought by a customer in a single
purchase.
• This technique determines relationships of what products were
purchased with which other product(s)
How Market Basket Analysis Work?
• The relationships are then used to build profiles containing IF-
THEN rules of the items purchased.

• If (A) Then (B)


i.e. if item A is purchased then there is a possibility of B being
purchased.
IF (A) THEN (B)
• IF is condition part
• The If part of the rule is known as antecedent.

• Then is the result part


• Then part of the rule is known as consequent.
Association Rules
• The association rules has three measures that express the degree
of confidence in the rule
• Support
• Confidence
• Lift
Definitions
• Item: attribute=value pair or simply value

• Itemset I : a subset of possible items


• Example: I = {A,B,E}

• Transaction: (TID, itemset)


• TID is transaction ID
Support
• First measure is called as support
• It is a measure of how frequently the collection of items occur
together as a percentage of all transactions.
• Fraction of transactions that contain both A and B.
A B
Support 
Total _ Transactions
Confidence
• Confidence provides the reliability measure of the rule.

• We have a strong rule if


𝑆𝑢𝑝𝑝𝑜𝑟𝑡(𝐼)
• 𝑆𝑢𝑝𝑝𝑜𝑟𝑡(𝑆)
≥ 𝐶𝑜𝑛𝑓𝑖𝑑𝑒𝑛𝑐𝑒
Tr_ID Transactions

1 Milk Egg Bread Butter


Example 2 Milk Butter Egg Ketchup

3 Bread Butter Ketchup

Min_Support= 33% 4 Milk Bread Butter


Confidence= 60% 5 Bread Butter Cookies
6 Milk Bread Butter Cookies
7 Milk Cookies
8 Milk Bread Butter
9 Bread Butter Egg Cookies
10 Milk Butter Bread
11 Milk Bread Butter
12 Milk Bread Cookies Ketchup
Example
1-Item Set Frequency Support
Milk 9 9/12= 0.75
Bread 10 10/12=0.83
Butter 10 10/12=0.83
Egg 3 3/12= 0.25 Frequent 1-Item Set Frequency
Ketchup 3 3/12= 0.25 Milk 9
Cookies 5 5/12=0.41 Bread 10
Butter 10
Cookies 5
Example
2-Item Sets Frequency Support
Milk, Bread 7 7/12=0.58
Milk, Butter 7 7/12= 0.58
Milk, Cookies 3 3/12= 0.25
Frequent 2-Item Set Frequency
Bread, Butter 9 9/12=0.75
Milk, Bread 7
Bread, Cookies 3 3/12= 0.25
Milk, Butter 7
Butter, Cookies 4 4/12=0.33
Bread, Butter 9
Bread, Cookies 4
Example
3-Item Sets Frequency Support

Milk, Bread, 6 6/12= 0.5


Butter
Milk, Bread, 1 1/12=0.083
Cookies
Frequent 3-Item Set Frequency
Bread, Butter, 3 3/12= 0.25
Cookies Milk, Bread, Butter 6
Milk, Butter, 2 2/12= 0.16
Cookies
Association Rule Mining-Subset Creation

Frequent 3-Item Set= I=>{Milk, Bread, Butter}

Non empty subsets are


S={{Milk},{Bread},{Butter}, {Milk, Bread},{Milk, Butter}, {Bread, Butter}}

How to form association rule…?


Association Rule Mining-Subset Creation

For every non-empty subset S of I, the association rule is,

S(I-S)

We have a strong rule


If support (I)/support(S)>=min_confidence
Association Rule Mining-Subset Creation

Non empty subsets are


▪ {{Milk},{Bread},{Butter}, {Milk, Bread},{Milk, Butter}, {Bread, Butter}}
▪ Min_Support= 30% Confidence= 60%

Rule 1: {Milk} {Bread, Butter} {S=50%, C=66.67%}


▪ Support= 6/12= 50%
▪ Confidence= Support =>{Milk, Bread, Butter}/ Support {Milk} = 6/9 =
66%>=60%
▪ Valid
Association Rule Mining-Subset Creation

• Lift- Confidence/Sup(I-S)
6
Lift  9  0.88
9
12

• As 0.88 < 1 so this rule will not have any impact on cross selling of
items.
Association Rule Mining-Subset Creation

Rule 2: {Bread} {Milk, Butter} {S=50%, C=60%}


▪ Support= 6/12= 50%
▪ Confidence= Support =>{Milk, Bread, Butter}/ Support {Bread}=
6/10 = 60%>=60%
▪ Valid
Association Rule Mining-Subset Creation

• Lift- Confidence/Sup(I-S)
6
Lift  10  1.02
7
12
• As 1.02> 1 so this rule will have an impact on cross selling of items.
Association Rule Mining-Subset Creation

Rule 3: {Butter} {Milk, Bread} {S=50%, C=60%}


▪ Support= 6/12= 50%
▪ Confidence= Support =>{Milk, Bread, Butter}/ Support {Butter}=
6/10 = 60%>=60%
▪ Valid
Association Rule Mining-Subset Creation

• Lift- Confidence/Sup(I-S)
6
Lift  10  1.02
7
12
• As 1.02> 1 so this rule will have an impact on cross selling of items.
Association Rule Mining-Subset Creation

Rule 4: {Milk , Bread} {Butter} {S=50%, C=60%}


▪ Support= 6/12= 50%
▪ Confidence= Support =>{Milk, Bread, Butter}/ Support {Milk,
Bread}= 6/7 = 85.7%>60%
▪ Valid
Association Rule Mining-Subset Creation

• Lift- Confidence/Sup(I-S)
6
Lift  7  1.02
10
12

• As 1.02> 1 so this rule will have an impact on cross selling of items.


Association Rule Mining-Subset Creation

Rule 5: {Milk, Butter} {Bread} {S=50%, C=60%}


▪ Support= 6/12= 50%
▪ Confidence= Support =>{Milk, Bread, Butter}/ Support {Milk,
Butter}= 6/7 = 85%>=60%
▪ Valid
Association Rule Mining-Subset Creation

• Lift- Confidence/Sup(I-S)
6
Lift  7  1.02
10
12

• As 1.02> 1 so this rule will have an impact on cross selling of items.


Association Rule Mining-Subset Creation

Rule 6: {Bread, Butter} {Milk} {S=50%, C=60%}


▪ Support= 6/12= 50%
▪ Confidence= Support =>{Milk, Bread, Butter}/ Support {Bread,
Butter}= 6/9 = 66.67%>=60%
▪ Valid
Association Rule Mining-Subset Creation

• Lift- Confidence/Sup(I-S)
6
Lift  9  0.88
9
12

• As 0.88< 1 so this rule will not have any impact on cross selling of
items.
Applications of Market Basket Analysis
• Retail/ Super Markets
• Telecom- Analyze various services offered by telecom companies
and what customers are purchasing.
• Banks/ Credit card companies
• Insurance companies
• Medical

You might also like