Apriori Algorithm
Apriori Algorithm
REG NO : 36823024
COURSE : MCA
SUBJECT : DATA ANALYTICS
ACTIVITY : 15
Apriori algorithm
The Apriori algorithm is a popular method used in data mining for mining
frequent itemsets and discovering association rules. It is particularly well-
known in the field of market basket analysis, where it helps find patterns
of items frequently purchased together.
Key Concepts:
1. Frequent Itemsets: These are sets of items that frequently appear
together in transactions. For example, in a supermarket, "milk" and
"bread" might be frequent itemsets if they are often bought
together.
2. Association Rules: These are implications of the form A → B,
meaning that if item A is bought, item B is also likely to be bought.
The goal is to find rules with high support, confidence, and lift.
Code:
Interpretation:
The bar plot visualizes the top 10 frequent itemsets from a dataset,
ranked by their support values. Support indicates how frequently each
itemset appears in the dataset (in this case, it looks like there are fewer
than 10 itemsets, so all are displayed).
1. frozenset({'bread'}):
o Support: Close to 0.85 (85%).
o Interpretation: Bread appears in around 85% of the
transactions. This is the most frequent item in the dataset.
2. frozenset({'butter'}):
o Support: Approximately 0.7 (70%).
o Interpretation: Butter appears in about 70% of the
transactions. It is the second most common item.
3. frozenset({'milk'}):
o Support: Around 0.65 (65%).
o Interpretation: Milk is present in approximately 65% of the
transactions, making it another frequent item.
4. frozenset({'butter', 'bread'}):
o Support: Close to 0.6 (60%).
o Interpretation: Both butter and bread are bought together in
about 60% of the transactions. This indicates a strong co-
occurrence between these two items.
5. frozenset({'cheese'}):
o Support: Around 0.45 (45%).
o Interpretation: Cheese appears in 45% of the transactions.
Though not as frequent as bread or butter, it is still relatively
common.
6. frozenset({'milk', 'bread'}):
o Support: Approximately 0.4 (40%).
o Interpretation: Milk and bread are purchased together in
about 40% of transactions. This indicates another frequent
combination.
Inference:
• Bread is the most frequent item and is found in almost 85% of the
transactions, indicating its strong dominance in the dataset.
• Butter and milk are also frequent individual items, appearing in
70% and 65% of transactions, respectively.
• Itemsets like 'butter & bread' and 'milk & bread' show that these
combinations of items are common in transactions, possibly
indicating complementary or related products.
• Cheese appears less frequently than other items, but it still shows
a reasonable support (about 45%).