Apriori Algorithm
Apriori Algorithm is a foundational method in data mining used for discovering frequent itemsets and generating association rules. Its significance lies in its ability to identify relationships between items in large datasets which is particularly valuable in market basket analysis.
For example, if a grocery store finds that customers who buy bread often also buy butter, it can use this information to optimize product placement or marketing strategies.
How the Apriori Algorithm Works?
The Apriori Algorithm operates through a systematic process that involves several key steps:
- Identifying Frequent Itemsets: The algorithm begins by scanning the dataset to identify individual items (1-item) and their frequencies. It then establishes a minimum support threshold, which determines whether an itemset is considered frequent.
- Creating Possible item group: Once frequent 1-itemgroup(single items) are identified, the algorithm generates candidate 2-itemgroup by combining frequent items. This process continues iteratively, forming larger itemsets (k-itemgroup) until no more frequent itemgroup can be found.
- Removing Infrequent Item groups: The algorithm employs a pruning technique based on the Apriori Property, which states that if an itemset is infrequent, all its supersets must also be infrequent. This significantly reduces the number of combinations that need to be evaluated.
- Generating Association Rules: After identifying frequent itemsets, the algorithm generates association rules that illustrate how items relate to one another, using metrics like support, confidence, and lift to evaluate the strength of these relationships.
Key Metrics of Apriori Algorithm
- Support: This metric measures how frequently an item appears in the dataset relative to the total number of transactions. A higher support indicates a more significant presence of the itemset in the dataset. Support tells us how often a particular item or combination of items appears in all the transactions (“Bread is bought in 20% of all transactions.”)
- Confidence: Confidence assesses the likelihood that an item Y is purchased when item X is purchased. It provides insight into the strength of the association between two items.
- Confidence tells us how often items go together. (“If bread is bought, butter is bought 75% of the time.”)
- Lift: Lift evaluates how much more likely two items are to be purchased together compared to being purchased independently. A lift greater than 1 suggests a strong positive association. Lift shows how strong the connection is between items. (“Bread and butter are much more likely to be bought together than by chance.”)
Lets understand the concept of apriori Algorithm with the help of an example. Consider the following dataset and we will find frequent itemsets and generate association rules for them:

Transactions of a Grocery Shop
Step 1 : Setting the parameters
- Minimum Support Threshold: 50% (item must appear in at least 3/5 transactions). This threeshold is formulated from this formula:
[Tex]\text{Support}(A) = \frac{\text{Number of transactions containing itemset } A}{\text{Total number of transactions}} [/Tex]
- Minimum Confidence Threshold: 70% ( You can change the value of parameters as per the usecase and problem statement ). This threeshold is formulated from this formula:
[Tex]\text{Confidence}(X \rightarrow Y) = \frac{\text{Support}(X \cup Y)}{\text{Support}(X)} [/Tex]
Step 2: Find Frequent 1-Itemsets
Lets count how many transactions include each item in the dataset (calculating the frequency of each item).

Frequent 1-Itemsets
All items have support% ≥ 50%, so they qualify as frequent 1-itemsets. if any item has support% < 50%, It will be ommited out from the frequent 1- itemsets.
Step 3: Generate Candidate 2-Itemsets
Combine the frequent 1-itemsets into pairs and calculate their support.
For this usecase, we will get 3 item pairs ( bread,butter) , (bread,ilk) and (butter,milk) and will calculate the support similiar to step 2

Candidate 2-Itemsets
Frequent 2-itemsets:
- {Bread, Butter}, {Bread, Milk} both meet the 50% threshold but {butter,milk} doesnt meet the threeshold, so will be ommited out.
Step 4: Generate Candidate 3-Itemsets
Combine the frequent 2-itemsets into groups of 3 and calculate their support.
for the triplet, we have only got one case i.e {bread,butter,milk} and we will calculate the support.
Candidate 3-Itemsets
Since this does not meet the 50% threshold, there are no frequent 3-itemsets.
Step 5: Generate Association Rules
Now we generate rules from the frequent itemsets and calculate confidence.
Rule 1: If Bread → Butter (if customer buys bread, the customer will buy butter also)
- Support of {Bread, Butter} = 3.
- Support of {Bread} = 4.
- Confidence = 3/4 = 75% (Passes threshold).
Rule 2: If Butter → Bread (if customer buys butter, the customer will buy bread also)
- Support of {Bread, Butter} = 3.
- Support of {Butter} = 3.
- Confidence = 3/3 = 100% (Passes threshold).
Rule 3: If Bread → Milk (if customer buys bread, the customer will buy milk also)
- Support of {Bread, Milk} = 3.
- Support of {Bread} = 4.
- Confidence = 3/4 = 75% (Passes threshold).
The Apriori Algorithm, as demonstrated in the bread-butter example, is widely used in modern startups like Zomato, Swiggy, and other food delivery platforms. These companies use it to perform market basket analysis, which helps them identify customer behavior patterns and optimize recommendations.
Applications of Apriori Algorithm
Below are some applications of Apriori algorithm used in today’s companies and startups
- E-commerce: Used to recommend products that are often bought together, like laptop + laptop bag, increasing sales.
- Food Delivery Services: Identifies popular combos, such as burger + fries, to offer combo deals to customers.
- Streaming Services: Recommends related movies or shows based on what users often watch together, like action + superhero movies.
- Financial Services: Analyzes spending habits to suggest personalized offers, such as credit card deals based on frequent purchases.
- Travel & Hospitality: Creates travel packages (e.g., flight + hotel) by finding commonly purchased services together.
- Health & Fitness: Suggests workout plans or supplements based on users’ past activities, like protein shakes + workouts.
For implementing apriori algorithm, please refer to Apriori algorithm in Python
Get IBM Certification and a 90% fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.
Master Machine Learning, Data Science & AI with this complete program and also get a 90% refund. What more motivation do you need? Start the challenge right away!

