what is apriori algorithm
Apriori is a classic algorithm in data mining that finds frequent itemsets and builds association rules from transactional data, like market basket records where each transaction is a list of items a customer bought.
Quick Scoop
Think of a supermarket’s receipts: each receipt is one “transaction” and the products are “items”. Apriori scans all these transactions to discover patterns such as “people who buy bread and butter often also buy milk”.
It does this in two big stages:
- Frequent itemset mining
- It first counts single items (1-itemsets) and keeps only those that appear often enough, based on a user-chosen minimum support threshold (e.g., must appear in at least 20% of transactions).
* It then combines these frequent items to form larger sets (2-itemsets, 3-itemsets, …), but prunes any candidate whose smaller subsets are not frequent. This pruning uses the **Apriori property** :
* If an itemset is frequent, all its subsets must be frequent.
* If an itemset is infrequent, all its supersets are infrequent.
* This step repeats (k-itemsets → k+1-itemsets) until no more frequent itemsets can be found.
- Association rule generation
- From each frequent itemset, the algorithm generates rules of the form X→YX\rightarrow YX→Y, like {bread, butter}→{milk}\{\text{bread, butter}\}\rightarrow \{\text{milk}\}{bread, butter}→{milk}, meaning “if a basket contains bread and butter, it tends to also contain milk”.
* It evaluates rules using:
* **Support** : how often XXX and YYY occur together in all transactions.
* **Confidence** : how often YYY appears when XXX appears.
* **Lift** : how much more likely YYY is given XXX compared to YYY occurring at random.
* Only rules with confidence (and sometimes lift) above chosen thresholds are kept as strong patterns.
A tiny story-style example
Imagine a small shop with these five transactions:
- T1: Bread, Butter
- T2: Bread, Milk
- T3: Bread, Butter, Milk
- T4: Butter, Cheese
- T5: Bread, Butter, Cheese
If we set minimum support to “must appear in at least 3 of 5 transactions”:
- Frequent 1-itemsets might be: {Bread}, {Butter} (they appear often enough).
- From these, candidate 2-itemset {Bread, Butter} is formed and also turns out to be frequent.
- Then a rule like {Bread} → {Butter} might have high confidence: a high fraction of baskets with bread also contain butter, so the shop learns this is a strong association.
Where Apriori is used today
Apriori is widely used as an unsupervised learning method for association rule learning in:
- Market basket analysis in retail and ecommerce (product bundling, cross-selling, recommendation).
- Recommendation systems beyond retail (e.g., movies or content that co-occur in user histories).
- Healthcare and disease pattern mining (co-occurring symptoms or medications).
- IT operations analytics and log pattern mining (recurring combinations of events in logs).
Modern libraries (for example, in Python) still provide Apriori implementations, though for very large datasets newer algorithms or optimized variants are often preferred.
TL;DR: Apriori is an unsupervised machine learning algorithm that scans transactional data to find frequently co-occurring groups of items and then turns them into interpretable “if X, then Y” association rules using support, confidence, and lift.
Information gathered from public forums or data available on the internet and portrayed here.