using the fp growth algorithm now we have all the pieces required to perform our rule-mining but before proceedingwe want to take care of one more important aspect of the analysis we saw in the earlier section how only handful of items are responsible for bulk of our sales so we want to prune our dataset to reflect this information for this we have created function prune_dataset (check out the notebook)which will help us reduce the size of our dataset based on our requirements the function can be used for performing two types of pruningpruning based on percentage of total salesthe parameter total_sales_perc will help us select the number of items that will explain the required percentage of sales the default value is or pruning based on ranks of itemsanother way to perform the pruning is to specify the starting and the ending rank of the items for which we want to prune our dataset by defaultwe will only look for transactions which have at least two itemsas transactions with only one item are counter to the whole concept of association rule-mining the following code snippet will help us select only that subset of data which explain of the total sales by leveraging our pruning function output_dfitem_counts prune_dataset(input_df=grocery_dflength_trans= ,total_sales_perc= print(output_df shapeprint(list(output_df columns)( ['whole milk''other vegetables''rolls/buns''soda''yogurt''bottled water''root vegetables''tropical fruit''shopping bags''sausage''pastry''citrus fruit''bottled beer'so we find out that we have only items responsible for of sales and transactions that have those items along with other items and we can also see what those items are the next step is to convert this selected data into the required table data structure input_assoc_rules output_df domain_grocery domain([discretevariable make(name=item,values=[' '' ']for item in input_assoc_rules columns]data_gro_ orange data table from_numpy(domain=domain_groceryx=input_assoc_rules as_matrix()ynonedata_gro_ _enmapping onehot encode(data_gro_ include_class=falsethe new addition to the previous code is the last line this is required for coding our input so that the entire domain is represented as binary variables this will complete all the parsing and data manipulation required for our rule-mining phewthe final step is creating our rules we need to specify two pieces of information for generating our rulessupport and confidence we have already defined both of them conceptually earlierso we will not be defining them again an important piece of information is to start with higher supportas lower support will mean higher number of frequent itemsets and hence longer execution time we will specify minsupport of -- transactions at least--and see the number of frequent itemsets that we get before we specify confidence and generate our rules min_support print("num of required transactions "int(input_assoc_rules shape[ ]*min_support)num_trans input_assoc_rules shape[ ]*min_support itemsets dict(frequent_itemsets(data_gro_ _enmin_support=min_support)