Professional Documents
Culture Documents
Tutorial 04
Tutorial 04
1
Review Questions
◦ Question 1: Data Mining and Metrics
Algorithm Questions
◦ Question 2: Applying Apriori Algorithm
◦ Question 3: Finding Association Rules
2
3
What is an Association Rule?
4
What is an Association Rule?
An association rule states that: given a set of
records, each of which contain some number of
items from a given collection, there will be a
dependency rule that will predict the occurrence of
an item based on the occurrences of other items in
the transaction. In other words, if it has been
found in all transactions that coke is always
bought with milk, then there will be a rule that
states {milk} -> {coke} (however, not the other way
around since not all milk is bought with coke).
5
What are the metrics for evaluating
association rules?
6
What are the metrics for evaluating
association rules?
The association rule evaluation metrics are
“Support” (s) and “Confidence” (c). Support is
the fractions of the transactions that contain
both X and Y. Confidence measures how often
items in Y appears in transactions that contain
X.
7
What are the metrics for
evaluating association rules?
8
9
Apply the Apriori algorithm to find all itemsets with
support >= 0.2 from the following data:
10
Apriori Principle Step 1: Count up the occurrences
of 1 item:
Itemset Count
Milk 5
Bread 4
Eggs 4
Juice 3
Butter 2
Coffee 3
Cookies 2
11
Apriori Principle Step 2: Look for frequent
occurrences of 2 items (in bold, not strikethrough):
Itemset Count
Milk, Bread 4
Milk, Eggs 3
Milk, Juice 1
Milk, Cookies 1
Bread, Eggs 3
Bread, Cookies 1
Eggs, Coffee 1
Eggs, Cookies 1
Juice, Butter 1
Juice, Coffee 1
Butter, Cookies 1
12
Apriori Principle Step 3: Look for frequent
occurrences of 3 items (in bold, not strikethrough):
Itemset Count
Milk, Bread, Eggs 3
13
Using the data set in question 2 ({Milk, Bread,
Eggs}), find all the association rules with support
>= 0.2 and confidence >= 0.8.
14
Association Rules for {Milk, Bread, Eggs}:
Transaction Items in
{Milk, Bread} -> {Eggs} Transaction
Support = 1 Milk, Bread, Eggs
Confidence = 2 Milk, Juice
3 Juice, Butter
4 Milk, Bread, Eggs
{Milk Eggs} -> {Bread} 5 Coffee, Eggs
Support = 6 Coffee
Confidence = 7 Coffee, Juice
8 Milk, Bread,
Cookies, Eggs
{Eggs, Bread} -> {Milk} 9 Cookies, Butter
Support = 10 Milk, Bread
Confidence =
15
Association Rules for {Milk, Bread, Eggs}:
Transaction Items in
{Milk, Bread} -> {Eggs} Transaction
Support = 3/10 = 0.3 1 Milk, Bread, Eggs
Confidence = 3/4 = 0.75 2 Milk, Juice
3 Juice, Butter
4 Milk, Bread, Eggs
{Milk Eggs} -> {Bread} 5 Coffee, Eggs
Support = 6 Coffee
Confidence = 7 Coffee, Juice
8 Milk, Bread,
Cookies, Eggs
{Eggs, Bread} -> {Milk} 9 Cookies, Butter
Support = 10 Milk, Bread
Confidence =
16
Association Rules for {Milk, Bread, Eggs}:
Transaction Items in
{Milk, Bread} -> {Eggs} Transaction
Support = 3/10 = 0.3 1 Milk, Bread, Eggs
Confidence = 3/4 = 0.75 2 Milk, Juice
3 Juice, Butter
4 Milk, Bread, Eggs
{Milk Eggs} -> {Bread} 5 Coffee, Eggs
Support = 3/10 = 0.3 6 Coffee
Confidence = 3/3 = 1 7 Coffee, Juice
8 Milk, Bread,
Cookies, Eggs
{Eggs, Bread} -> {Milk} 9 Cookies, Butter
Support = 10 Milk, Bread
Confidence =
17
Association Rules for {Milk, Bread, Eggs}:
Transaction Items in
{Milk, Bread} -> {Eggs} Transaction
Support = 3/10 = 0.3 1 Milk, Bread, Eggs
Confidence = 3/4 = 0.75 2 Milk, Juice
3 Juice, Butter
4 Milk, Bread, Eggs
{Milk Eggs} -> {Bread} 5 Coffee, Eggs
Support = 3/10 = 0.3 6 Coffee
Confidence = 3/3 = 1 7 Coffee, Juice
8 Milk, Bread,
Cookies, Eggs
{Eggs, Bread} -> {Milk} 9 Cookies, Butter
Support = 3/10 = 0.3 10 Milk, Bread
Confidence = 3/3 = 1
18
Association Rules for {Milk, Bread}:
Transaction Items in
19
Association Rules for {Milk, Bread}:
Transaction Items in
20
Association Rules for {Milk, Bread}:
Transaction Items in
21
Association Rules for {Milk, Eggs}:
Transaction Items in
22
Association Rules for {Milk, Eggs}:
Transaction Items in
23
Association Rules for {Milk, Eggs}:
Transaction Items in
24
Association Rules for {Bread Eggs}:
Transaction Items in
25
Association Rules for {Bread Eggs}:
Transaction Items in
26
Association Rules for {Bread Eggs}:
Transaction Items in
27
Therefore, the only Association Rules that satisfy the
restriction of having support >= 2 and confidence
>= 0.8 is:
28
29