apriori algorithm example
Examples
1) Given the following data , apply Apriori algorithm. Min support = 50% and confidence = 70%
Database D.
| TID | Sup |
|---|---|
| 100 | 1 3 4 |
| 200 | 2 3 5 |
| 300 | 1 2 3 5 |
| 400 | 2 5 |
SOLUTION
Support (S) = (50/100) * 4
where min support = 50% and no of rows in database D is 4
Therefore S=2
Step 1 : Scan database D for count of each candidate which are present in "Items" column in the question. The candidate list is {1,2,3,4,5} and find the support. here support(S) = 2.
C1 =
| Itemset | Sup |
|---|---|
| {1} | 2 |
| {2} | 3 |
| {3} | 3 |
| {4} | 1 |
| {5} | 3 |
Step 2 : Compare candidate support count with minimum support count (i.e 50% in our case)
L1 =
| Itemset | Sup |
|---|---|
| {1} | 2 |
| {2} | 3 |
| {3} | 3 |
| {5} | 3 |
Step 3 : Generate candidate C2 from L1
C2 =
| Itemset |
|---|
| {1 2} |
| {1 3} |
| {1 5} |
| {2 3} |
| {2 5} |
| {3 5} |
Step 4 : Scan database D for count of each candidate in C2 and find the support
C2 =
| Itemset | Sup |
|---|---|
| {1 2} | 1 |
| {1 3} | 2 |
| {1 5} | 1 |
| {2 3} | 2 |
| {2 5} | 3 |
| {3 5} | 2 |
Step 5 : Compare candidate (C2) support count with the minimum support count
L2 =
| Itemset | Sup |
|---|---|
| {1 3} | 2 |
| {2 3} | 2 |
| {2 5} | 3 |
| {3 5} | 2 |
Step 6 : generate candidate C3 from L2
C3 =
| Itemset |
|---|
| {1 3 5} |
| {2 3 5} |
| {1 2 3} |
Step 7 :Scan database D for count of each candidate in C3
C3 =
| Itemset | Sup |
|---|---|
| {1 3 5} | 1 |
| {2 3 5} | 2 |
| {1 2 3} | 1 |
Step 8 : Compare candidate (C3) support count with the minimum support count
L3 =
| Itemset | Sup |
|---|---|
| {2 3 5} | 2 |
Step 9 : So data contain the frequent itemset (2,3,5)
Therefore the association rule that can be generated from L3 are as shown below with the support and confidence .
| Association rule | Support | Confidence | Confidence % |
|---|---|---|---|
| 2^3 => 5 | 2 | 2/2 = 1 | 100% |
| 3^5 => 2 | 2 | 2/2 = 1 | 100% |
| 2^5 => 3 | 2 | 2/3 = 0.66 | 66% |
| 2 => 3^5 | 2 | 2/3 = 0.66 | 66% |
| 3 => 2^5 | 2 | 2/3 = 0.66 | 66% |
| 5 => 2^3 | 2 | 2/3 = 0.66 | 66% |
If the minimum confidence threshold is 70% (Given), then only the first and second rules above are output, since these are the only ones generated that are strong
Final rules are :
Rule 1 : 2^3=>5 and Rule 2 : 3^5=>2
---------------------------------------------------------------------------------------------------------------
NOTE : FOR ANY QUERIES COMMENT YOUR DOUBTS BELOW IN COMMENT BOX.
---------------------------------------------------------------------------------------------------------------
FOR MORE EXAMPLE ON APRIORI ALGORITHM VISIT YOUTUBE LINK IN THE DESCRIPTION BELOW :
https://www.youtube.com/watch?v=JZepOmvB514
please ask doubts freely
ReplyDeleteHmmm, 1->3 has 2/3 support and 2/3 confidence?
Delete