chapter 05 association rule mining - sherbold.github.ioΒ Β· example for generating rules β’ support...
Post on 02-Feb-2021
6 Views
Preview:
TRANSCRIPT
-
Chapter 05
Association Rule Mining
Dr. Steffen Herbold
herbold@cs.uni-goettingen.de
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
-
Outline
β’ Overview
β’ The Apriori Algorithm
β’ Summary
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
-
Example of Association Rules
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Items already in basket Available items Item likely to be added+
-
The General Problem
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Set of Transactions
β’ item1,item2,item3
β’ item2,item4
β’ item1,item5
β’ item6,item7
β’ item2,item3,item4,item7
β’ item2,item3,item4,item8
β’ item2,item4,item5
β’ item2,item3,item4
β’ item4,item5
β’ β¦
Association
Rule Mining
Association Rules
β’ item2 β item3
β’ item2 β item4
β’ item2,item3 β item4
β’ β¦
Rules describe
βinteresting relationshipsβ
-
The Formal Problem
β’ Itemsβ’ πΌ = {π1, π2, β¦ , ππ}
β’ Transactionsβ’ π = {π‘1, β¦ , π‘π} with π‘π β πΌ
β’ Rulesβ’ π β π such that π, π β πΌ and π β© π = β
β’ π is also called antecedent or left-hand-side
β’ π is also called consequent or right-hand-side
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
How do you
get good
rules?
-
Defining βInteresting Relationshipsβ
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Set of Transactions
β’ item1,item2,item3
β’ item2,item4
β’ item1,item5
β’ item6,item7
β’ item2,item3,item4,item7
β’ item2,item3,item4,item8
β’ item2,item4,item5
β’ item2,item3,item4
β’ item4,item5
β’ β¦
item2, item3,
item4 occur often
together
Interesting == often together
-
Outline
β’ Overview
β’ The Apriori Algorithm
β’ Summary
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
-
Support and Frequent Item Sets
β’ Supportβ’ Percentage of occurances of an itemset πΌπ
β’ π π’πππππ‘ πΌπ =| π‘βπβΆπΌπβπ‘ |
|π|
β’ Frequent item setβ’ Itemsets that appear together βoften enoughβ
β’ Defined using a threshold
β’ πΌπ β πΌ is frequent if π π’πππππ‘ πΌπ β₯ ππππ π’ππ
β’ Rules can be generated by splitting itemsetsβ’ πΌπ = π βͺ π
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
-
Example for Generating Rules
β’ support ππ‘ππ2, ππ‘ππ3, ππ‘ππ4 =3
10β₯ 0.3
β’ Eight possible rules: β’ β β {ππ‘ππ2, ππ‘ππ3, ππ‘ππ4}
β’ {ππ‘ππ2} β {ππ‘ππ3, ππ‘ππ4}
β’ {ππ‘ππ3} β {ππ‘ππ2, ππ‘ππ4}
β’ {ππ‘ππ4} β {ππ‘ππ2, ππ‘ππ3}
β’ {ππ‘ππ2, ππ‘ππ3} β {ππ‘ππ4}
β’ {ππ‘ππ2, ππ‘ππ4} β {ππ‘ππ3}
β’ {ππ‘ππ3, ππ‘ππ4} β {ππ‘ππ2}
β’ ππ‘ππ2, ππ‘ππ3, ππ‘ππ4 β β
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Set of Transactions
β’ item1,item2,item3
β’ item2,item4
β’ item1,item5
β’ item6,item7
β’ item2,item3,item4,item7
β’ item2,item3,item4,item8
β’ item2,item4,item5
β’ item2,item3,item4
β’ item4,item5
β’ item6,item7
ππππ π’ππ = 0.3
Are all rules
interesting?
-
Confidence, Lift, and Leverage
β’ Confidenceβ’ Percentage of transactions that contain the antecedent, which also
contain consequent
β’ ππππππππππ π β π =π π’πππππ‘(πβͺπ)
π π’πππππ‘(π)=
| π‘βπ:πβͺπβπ |
| π‘βπ:πβπ |
β’ Liftβ’ Ratio of the probability of π and π together and independently
β’ ππππ‘ π β Y =π π’πππππ‘(πβͺπ)
π π’πππππ‘ π β π π’πππππ‘(π)
β’ Leverageβ’ Difference in the probability of π and π together and independently
β’ πππ£πππππ π β π = π π’πππππ‘ π βͺ π β π π’πππππ‘ π₯ β π π’πππππ‘(π)
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Usually, lift favors itemsets with lower
support, leverage with higher support
-
Confidence for the Example Rules
β’ ππππππππππ β β ππ‘ππ2, ππ‘ππ3, ππ‘ππ4 =0.3
1= 0.3
β’ ππππππππππ ππ‘ππ2 β ππ‘ππ3, ππ‘ππ4 =0.3
0.6= 0.5
β’ ππππππππππ ππ‘ππ3 β ππ‘ππ2, ππ‘ππ4 =0.3
0.4= 0.75
β’ ππππππππππ ππ‘ππ4 β ππ‘ππ2, ππ‘ππ3 =0.3
0.6= 0.5
β’ ππππππππππ ππ‘ππ2, ππ‘ππ3 β ππ‘ππ4 =0.3
0.4= 0.75
β’ ππππππππππ ππ‘ππ2, ππ‘ππ4 β ππ‘ππ3 =0.3
0.5= 0.6
β’ ππππππππππ ππ‘ππ3, ππ‘ππ4 β ππ‘ππ2 =0.3
0.3= 1
β’ ππππππππππ ππ‘ππ2, ππ‘ππ3, ππ‘ππ4 β β =0.3
0.3= 1
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Set of Transactions
β’ item1,item2,item3
β’ item2,item4
β’ item1,item5
β’ item6,item7
β’ item2,item3,item4,item7
β’ item2,item3,item4,item8
β’ item2,item4,item5
β’ item2,item3,item4
β’ item4,item5
β’ item6,item7
-
Lift for the Example Rules
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
β’ ππππ‘ β β ππ‘ππ2, ππ‘ππ3, ππ‘ππ4 =0.3
1β 0.3= 1
β’ ππππ‘ ππ‘ππ2 β ππ‘ππ3, ππ‘ππ4 =0.3
0.6β 0.3= 1.66
β’ ππππ‘ ππ‘ππ3 β ππ‘ππ2, ππ‘ππ4 =0.3
0.4β 0.5= 1.5
β’ ππππ‘ ππ‘ππ4 β ππ‘ππ2, ππ‘ππ3 =0.3
0.6β 0.4= 1.25
β’ ππππ‘ ππ‘ππ2, ππ‘ππ3 β ππ‘ππ4 =0.3
0.4β 0.6= 1.25
β’ ππππ‘ ππ‘ππ2, ππ‘ππ4 β ππ‘ππ3 =0.3
0.5β 0.4= 1.5
β’ ππππ‘ ππ‘ππ3, ππ‘ππ4 β ππ‘ππ2 =0.3
0.3β 0.6= 1.66
β’ ππππ‘ ππ‘ππ2, ππ‘ππ3, ππ‘ππ4 β β =0.3
0.3β 1= 1
Set of Transactions
β’ item1,item2,item3
β’ item2,item4
β’ item1,item5
β’ item6,item7
β’ item2,item3,item4,item7
β’ item2,item3,item4,item8
β’ item2,item4,item5
β’ item2,item3,item4
β’ item4,item5
β’ item6,item7
-
Overview of Scores for Example
Rule Confidence Lift Leverage
β β ππ‘ππ2, ππ‘ππ3, ππ‘ππ4 0.30 1.00 0.00
ππ‘ππ2 β ππ‘ππ3, ππ‘ππ4 0.50 1.66 0.12
ππ‘ππ3 β ππ‘ππ2, ππ‘ππ4 0.75 1.50 0.10
ππ‘ππ4 β ππ‘ππ2, ππ‘ππ3 0.50 1.25 0.06
ππ‘ππ2, ππ‘ππ3 β ππ‘ππ4 0.75 1.25 0.06
ππ‘ππ2, ππ‘ππ4 β ππ‘ππ3 0.60 1.50 0.10
ππ‘ππ3, ππ‘ππ4 β ππ‘ππ2 1.00 1.66 0.12
ππ‘ππ2, ππ‘ππ3, ππ‘ππ4 β β 1.00 1.00 0.00
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Perfect confidence, but
no gain over randomness
Perfect confidence, and
1.66 times more likely
than randomness
-
Itemsets and Rules = Exponential
β’ Number of itemset is exponentialβ’ All possible itemsets are the powerset π« of πΌ
β’ π« πΌ = 2|πΌ|
β’ Still exponential if we restrict the sizeβ’ |πΌ| itemsets with π = 1 items
β’πΌ β ( πΌ β1)
2itemsets with π = 2 items
β’|πΌ|π
=πΌ !
πΌ βπ !π!itemsets with π items
β’ Number of rules per itemset is exponentialβ’ Possible antecedents of itemset π are the powerset π« of π
β’ π« π = 2|π|
β’ Example: πΌ = 100, π = 3β’ 161,700 possible itemsets
β’ 1,293,600 possible rules
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
How do we
restrict the
search space?
-
Pruning the Search Space
β’ Apriori Propertyβ’ All subsets of frequent itemsets are also frequent
β’ π π’πππππ‘ πβ² β₯ π π’πππππ‘ π for all πβ² β π, π β πΌ
β’ βGrowβ itemsets and prune search space by applying Apriori property
β’ Start with itemsets of size k = 1
β’ Drop all itemsets that do not have minimal support
β’ Build all combinations of size k + 1
β’ Repeat untilβ’ No itemsets with minimal support are found
β’ A threshold for π is reached
β’ Still has exponential complexity, but better bounded
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
-
Example for Growing Itemsets (k=1)
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Set of Transactions
β’ item1,item2,item3
β’ item2,item4
β’ item1,item5
β’ item6,item7
β’ item2,item3,item4,item7
β’ item2,item3,item4,item8
β’ item2,item4,item5
β’ item2,item3,item4
β’ item4,item5
β’ item6,item7
ππππ π’ππ = 0.3
Rule Support
{ππ‘ππ1} 0.2
{ππ‘ππ2} 0.6
{ππ‘ππ3} 0.4
{ππ‘ππ4} 0.5
{ππ‘ππ5} 0.3
{ππ‘ππ6} 0.2
{ππ‘ππ7} 0.3
{ππ‘ππ8} 0.1
Drop
Drop
Drop
-
Example for Growing Itemsets (k=2)
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Set of Transactions
β’ item1,item2,item3
β’ item2,item4
β’ item1,item5
β’ item6,item7
β’ item2,item3,item4,item7
β’ item2,item3,item4,item8
β’ item2,item4,item5
β’ item2,item3,item4
β’ item4,item5
β’ item6,item7
ππππ π’ππ = 0.3
Rule Support
{ππ‘ππ2, item3} 0.4
{ππ‘ππ2, item4} 0.5
{ππ‘ππ2, item5} 0.1
{ππ‘ππ2, item7} 0.1
{ππ‘ππ3, item4} 0.3
{ππ‘ππ3, item5} 0.0
{ππ‘ππ3, item7} 0.1
β¦ β¦
Drop
Drop
Drop
Drop
Drop
-
Example for Growing Itemsets (k=3)
β’ Found the following frequent itemsetswith at least two items:
β’ ππ‘ππ2, ππ‘ππ3 , ππ‘ππ2, ππ‘ππ4 , ππ‘ππ3, ππ‘ππ4
β’ {ππ‘ππ2, ππ‘ππ3, ππ‘ππ4}
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
Set of Transactions
β’ item1,item2,item3
β’ item2,item4
β’ item1,item5
β’ item6,item7
β’ item2,item3,item4,item7
β’ item2,item3,item4,item8
β’ item2,item4,item5
β’ item2,item3,item4
β’ item4,item5
β’ item6,item7
ππππ π’ππ = 0.3
Rule Support
{ππ‘ππ2, item3, item4} 0.3
Only itemset
remaining, growing
terminates.
-
Candidates for Rules
β’ Usually, not all possible rules are considered
β’ Two common restrictions:β’ No empty antecedents and consequents
β’ π β β and π β β
β’ Only one item as consequentβ’ π = 1
β’ Example:
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
β β {ππ‘ππ2, ππ‘ππ3, ππ‘ππ4}{ππ‘ππ2} β {ππ‘ππ3, ππ‘ππ4}{ππ‘ππ3} β {ππ‘ππ2, ππ‘ππ4}{ππ‘ππ4} β {ππ‘ππ2, ππ‘ππ3}{ππ‘ππ2, ππ‘ππ3} β {ππ‘ππ4}{ππ‘ππ2, ππ‘ππ4} β {ππ‘ππ3}{ππ‘ππ3, ππ‘ππ4} β {ππ‘ππ2}ππ‘ππ2, ππ‘ππ3, ππ‘ππ4 β β
-
Evaluating Association Rules
β’ Use different criteria, not just support and confidenceβ’ Lift and leverage can tell you if rules are coincidental
β’ Validate if rules hold on test dataβ’ Check if the rules would also be found on the test data
β’ For basket prediction, use incomplete itemsets on test dataβ’ Example: remove item4 from all itemsets and see if the rules would
correctly predict where it is associated
β’ Manually inspect rulesβ’ Do they make sense?
β’ Ask domain experts
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
-
Outline
β’ Overview
β’ The Apriori Algorithm
β’ Summary
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
-
Summary
β’ Associations are interesting relationships between items
β’ Interesting usually means appear together and not coincidental
β’ Number of possible itemsets/rules exponentialβ’ Apriori property for bounding itemsets
β’ Restrictions on rule structures
β’ Test data and manual inspections for validation
Introduction to Data Science
https://sherbold.github.io/intro-to-data-science
top related