formallyapriori takes collection of sets (that isyour shopping basketsand returns sets that are very frequent as subsets (that isitems that together are part of many shopping basketsthe algorithm works according to the bottom-up approachstarting with the smallest candidates (those composed of one single element)it builds upadding one element at time we need to define the minimum support we are looking forminsupport support is the number of times that set of products was purchased together the goal of apriori is to find itemsets with high support logicallyany itemset with more than minimal support can only be composed of items that themselves have at least minimal supportvalid set( for , in counts items(if ( >minsupport)our initial itemsets are singletons (sets with single elementin particularall singletons that have at least minimal support are frequent itemsets itemsets [frozenset([ ]for in validnow our iteration is very simple and is given as followsnew_itemsets [for iset in itemsetsfor in validif not in isetwe create new possible set which is the same as the previous#with the addition of newset (ell|set([v_])loop over the dataset to count the number of times newset appears this step is slow and not used proper implementation c_newset for in datasetif issuperset( )c_newset + if c_newset minsupportnewsets append(newset