hi welcome back in this video i will discuss how to apply a priori algorithm to generate strong association rules for the given data set this is the solved example number two the link for other solved example is given in the description below this is the data set given to us consisting of five transaction ids and in each and every transaction the customer buys few products like bread butter and milk beer cookies diapers and so on here what we need to do is uh we need to apply a priori algorithm to generate a strong association rules given the minimum support of 40 and the minimum confidence of 70 in this case first what we need to do is we need to generate the frequent item sets once you generate the frequent item sets we can generate the association rules uh with this particular minimum confidence so first what we do is we will try to generate the frequent item sets a step by step for that reason first we need to generate the item sets and then we need to find the qualified frequent item sets that is the item set which is having minimum support so i will explain how to do it step by step in this case we have five unique products here that is bread butter milk diaper and beers so we will write those particular thing in the first column of this table as one item set then we count the number of times a particular product was bought for example bread bread was bought once twice thrice here so that is three in this case similarly butter butter was bought first time second time and then somewhere here it's a third time so it is three year similarly we need to count the number of times a particular item was bought and then we need to write in the second column that is the support count so this is a one item set table from here we need to generate the one frequent item sets for that reason first we need to do some simple calculation the minimum support given to us is 40 so the minimum support count is equivalent to minimum support that is 40 percent multiplied by item set count that is how many items are there there are five items so the answer is 200 percent that is nothing but two two should be the minimum support count then only you can say that one item set is a one frequent item set so in this case except this cookies all are one frequent item sets those i have written in this particular table that is nothing but one frequent item set now if we look at this particular one frequent item set we have five unique items again we need to generate two item sets here so these are the five items we have so two item sets are like bread butter bread diaper bread milk bread beer that's a first five combinations next one is butter diaper butter milk butter beer the next are diaper milk diaper beer and the last one is milk beer so those are the combinations i have written here once you write this particular combinations we need to find or can say that we need to count how many number of times these two items were bought together bread and butter if you see here it is bought first time in this first transaction second time it was bought and then in the fourth transaction also these two items were bought together so the answer is three in this case similarly bread diaper bread diaper was not bought here i think in the fourth transaction bread is present and diapers is present so it is bought only one time bread and milk bread and milk is present in the first one bread and milk is present in the fourth transaction so it is two similarly we have to find the support count for each and every item that is nothing but how many number of times these two items were bought together and then we need to select the two item sets which are having minimum support count of for two or more so in this case we have only four possibilities that is bread milk bread butter buttermilk and diaper beer in this case so these are the four possibilities now from this particular two frequent item sets we need to generate three frequent item sets for that reason first we need to write three item sets so first we identify what are the unique items are present here bread butter milk diaper and beer all five are unique items here from this particular five unique items we need to generate three item sets in this case i will show you one example how can you do this one is bread we can start with bread here bread butter milk bread butter diaper bread butter beer so bread and butter is over so bread milk diaper bread milk beer bread and milk is over bread diaper beer so bread butter bread milk bread diaper all are over now i will come with this one butter milk diaper butter milk beer and then butter diaper beer that's a ninth possibility and the tenth possibility is a milk diaper beer here so totally we have 10 possibilities for this particular 10 possibilities we have to again count the minimum support for example how many number of times these items were bought that is nothing but the support count bread milk butter bread milk butter is present here this is the first time bread milk butter is present one more time here so it is two similarly if you go with the second one bread butter diaper bread butter diaper is present in the fourth transaction you can see here bread butter diaper is present anywhere else it is not present so it is only one similarly we have to do it for all combinations and then write that particular support count in the second column next we have to select the three frequent item set which satisfies the minimum support of 2 in this case we have only one that is a bread butter milk with a support count of 2 in this case now coming back to the next one that is so once you find the free three frequent item set we need to check whether it is possible to write four frequent item sets in this three frequent item set we have only three items so definitely it is not possible to write four frequent item sets so we have to stop here and that is generating the frequent item sets now we need to write the association rules and select only those association rules which are strong based on the confidence percentage now uh if you want to generate the what we can say that the strong association rules we have to follow this particular procedure first we need to note what is the minimum confidence given the minimum confidence in this case is 70 percent so if you want to calculate the confidence of a particular rule let us say that x tends to y it is nothing but the number of times both the products were bought together divided by the number of times the first item was bought together what so in this case uh how many number of times x and y brought together divided by the number of time x was bought here so first i will write down the frequent item sets in this case we have four two frequent item sets are there and one three frequent item set is present so i have listed all those particular things over here next i will start with one frequent item set and then i will generate association rule so first one is this that is a bread and butter so bread and butter the rules can be bread butter or butter bread these are the two possibilities now i will check how many number of times bread and butter was bought together bread and butter was put together three times and how many number of times bread appears bread appears three times so 3 by 3 is equal to 100 it is a strong rule in this case the other side is what butter bread butter bread is bought three times and how many number of times butter appears butter was appearing three times it means it was bought three times so three by three is equal to hundred again it is a strong rule here coming back to the next one that is bread milk bread milk is the one possibility milk bread is another possibility bread milk how many number of times it was brought together bread milk is bought together two times how many number of times bread appears is it is three times so two by three 67 percent it is not a strong rule in this case other side is milk bread milk bread is again bought two times milk appears 2 times 2 by 2 is equal to 100 percent is a strong rule coming back to the next one that is uh butter milk here so buttermilk or milk butter butter milk is bought together two times butter appears three times two by three sixty seven percent it is not a strong rule milk butter is other possibility milk butter is brought together two times milk appears two times so two by two it is a strong rule in this case coming back to the next one that is diaper beer this is the next one so the first rule is diapers beer second rule is beer diapers diapers beer is bought together two times diapers appears three times 67 percent it is not a strong rule beer diapers beer diaper is bought together two times beer appears two times two by two which is 100 it's a strong rule in this case coming back to the last one we have left with only one frequent item set that is bread butter milk here we have to use a simple logic to generate the different association rules so what we do here is we will write two at a time on the left hand side or one at a time on the left hand side any one is perfectly fine so bread butter remaining is milk here so how many times all three were brought together all the time it is two only bread and butter three times so two by three 67 percent not a strong rule so other side of this one is what milk bread butter or any order you can write but in this case i have written this butter this side so it will become bread milk butter this are more one more course possibility all three were brought together two times and the bread and milk were bought together two times so that is nothing but two by two hundred percent and the next time what we can do is we can bring this particular butter they said bread this side that's one more possibility okay so milk butter bread is the one more possibility two times all three were bought milk and butter were bought together uh milk and butter two times so it will be a two by two again here strong rule strong rule now the next one is what bread butter milk so the opposite of this one so two by three it's not a strong rule next one is i can bring this particular butter this side bread this side and the last time i will bring milk this side and then the butter this side so that is one more thing these two are not a strong rules but the last one is a strong rule in this case so this is how actually you can generate the association rules and then you can check whether association rule is a strong or not by considering this particular confidence value so this is a very simple process with which you will be able to generate the frequent item sets and then you can generate the association rules and then select the association rule based on the minimum confidence in this case i hope the concept is clear if you like the video do like and share with your friends press the subscribe button for more videos press the bell icon for regular updates thank you for watching