![]() |
VOOZH | about |
Apriori Algorithm is a frequent itemset mining algorithm used for market basket analysis. It helps to find associations or relationships between items in large transactional datasets. A common real-world application is product recommendation where items are suggested to users based on their shopping cart contents.
Before we begin we need to import the necessary Python libraries like Pandas , Numpy and mlxtend.
We start by loading a popular groceries dataset. This dataset contains customer transactions with details like customer ID, transaction date, and the item purchased. you can download the dataset from here.
Output:
We group items purchased together by the same customer on the same day to form one transaction.
Output:
Apriori needs data in True/False format like Did the item appear in the basket?. We use Transaction Encoder for this:
Now we find frequent itemsets combinations of items that often occur together. Here min_support=0.01 means itemsets that appear in at least 1% of transactions. This gives us common combinations of items.
Output:
Total Frequent Itemsets: 69
Now we find rules like If bread and butter are bought, milk is also likely to be bought.
Output:
Letβs see which items are most frequently bought:
Output:
As shown in the above output Whole milk is the most frequently bought item, followed by other vegetables, rolls/bun and soda.