refer to the following codedef rules_from_itemset(itemsetdataset)itemset frozenset(itemsetnr_transactions float(len(dataset)for item in itemsetantecendent itemset-consequent base acountantecedent count acount ccount consequent count ccount for in datasetif item in dbase + if issuperset(itemset)ccount + if issuperset(antecedent)acount + base /nr_transactions p_y_given_x ccount/acount lift p_y_given_x base print('rule { -{ has lift { }format(antecedentconsequent,lift)this is slow-running codewe iterate over the whole dataset repeatedly better implementation would cache the counts for speed you can download such an implementation from the book' websiteand it does indeed run much faster some of the results are shown in the following tableantecedent consequent consequent count antecedent count antecedent and consequent count lift ( % ( % ( % counts are the number of transactionsthey include the followingthe consequent alone (that isthe base rate at which that product is boughtall the items in the antecedent all the items in the antecedent and the consequent