apriori algorithm example



Examples

1)  Given the following data , apply Apriori algorithm. Min support = 50% and confidence = 70%
     Database D.

TIDSup
1001 3 4
2002 3 5
3001 2 3 5
4002 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.
        
 C=
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)

L
ItemsetSup
{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 = 
ItemsetSup
{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 

 L
ItemsetSup
{1 3}2
{2 3}2
{2 5}3
{3 5}2

Step 6 : generate candidate Cfrom 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 = 
ItemsetSup
{1 3 5}1
{2 3 5}2
{1 2 3}1

Step 8 : Compare candidate (C3) support count with the minimum support count

 L=  
ItemsetSup
{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 ruleSupportConfidenceConfidence %
2^3 => 522/2 = 1100%
3^5 => 222/2 = 1100%
2^5 => 322/3 = 0.6666%
2 => 3^522/3 = 0.6666%
3 => 2^522/3 = 0.6666%
5 => 2^322/3 = 0.6666%

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




Comments

Post a Comment

Popular Posts