Source: Akash Notes Folder.
Major stuff: Apriori Algo, FP Growth Algo Box plot, theory Z Score, Confidence calc Smoothing... Binning Numerical
Follow the lecture order: market basket model -> support/confidence -> frequent itemsets -> Apriori -> FP-growth -> rule generation -> interestingness. For every algorithm, learn the input, the repeated step, the pruning principle, and what to write in a numerical answer.
1. Market basket analysis
Market basket analysis studies a supermarket-like transaction database to discover products that occur together. Association-rule mining was proposed by Agrawal et al. in 1993 and is used for information-driven marketing, catalog design, store layout, cross-selling, and customer segmentation.
Example: if {bread, salami} appears in three baskets and {bread, salami, ham} in two, the rule {bread, salami} -> {ham} has confidence .
A rule does not claim that buying bread causes buying ham. It says the two occurred together frequently enough in the recorded transactions to be a useful recommendation or placement candidate.
2. The market-basket model
- : a large set of binary items.
- A transaction is a small subset of , e.g. one customer’s bill.
- : the transaction database.
- An itemset is any subset of .
The model deliberately ignores some real-world details, such as quantity purchased and price paid. The lecture assumes categorical item data; numeric data usually needs preprocessing/discretization first.
3. Support, confidence, and the mining task
For itemset :
An association rule has the form , where .
Support measures how common the combined itemset is in the whole database. Confidence measures the fraction of transactions containing that also contain .
For a result to be statistically meaningful, the lecture cautions that its support count should normally be at least a few hundred in a database of several thousand transactions.
Given , , minsup, and minconf, the task is to find all rules whose support is at least minsup and confidence is at least minconf. Such rules are called strong association rules.
(a) Write a short note on market basket analysis. (b) How to compute confidence for an association rule ?
Market basket analysis treats one bill/customer visit as a transaction and each product as an item. It finds frequently co-purchased items and rules such as {bread, salami} -> {ham}. Uses include recommendation, cross-selling, promotion, catalog design, store layout, and customer segmentation.
To compute confidence, count transactions containing both and and divide by transactions containing :
If 30 baskets contain bread and 18 contain both bread and butter, .
Define support and confidence. In 50 transactions, 40 contain milk, 30 bread and 20 both: find support and confidence of milk → bread.
For , support is the proportion of all transactions containing both and ; confidence is the proportion of transactions containing that also contain .
Here , and . Thus support of milk → bread is and confidence is . The 30 bread transactions are relevant to the reverse rule or lift, not the denominator of this confidence.
4. Frequent itemsets and anti-monotonicity
An itemset is frequent when its support meets minsup. If , every transaction containing contains , therefore:
This is the anti-monotone, downward-closure, or Apriori property:
- every subset of a frequent itemset is frequent;
- every superset of an infrequent itemset is infrequent and can be discarded without counting it.
Without this property, items create possible itemsets, which is computationally impractical.
Association-rule mining therefore has two phases: first find frequent itemsets ; then enumerate each nonempty binary partition as . All rules from one itemset have the same support , but not necessarily the same confidence.
Explain in detail about association-rules mining task. Define confidence of an association rule. Discuss about the anti-monotone property of support.
Association-rule mining takes item set , transaction database , minsup, and minconf; it returns every where , , and .
Confidence is .
For , . Hence every subset of a frequent itemset is frequent; equivalently, if an itemset is infrequent, every superset is infrequent. Apriori uses this to prune candidates before expensive database counting.
5. Apriori algorithm
Let be frequent itemsets of size and candidate itemsets of size .
L1 = frequent 1-itemsets
for k = 2 while L(k-1) is not empty:
Ck = join(L(k-1), L(k-1))
prune c if any (k-1)-subset of c is not in L(k-1)
scan D and count every candidate c contained in transaction T
Lk = {c in Ck | count(c) >= minsup count}
return union of all LkJoin and prune
Join sorted -itemsets that agree on their first items. {1,2,3} and {1,2,4} generate {1,2,3,4}. Prune it if any 3-subset is absent from . This directly applies anti-monotonicity.
To count candidates efficiently, a hash tree stores candidate itemsets at leaves. When scanning a transaction, generate its relevant -subsets and traverse hash branches rather than checking every candidate against every transaction.
Limitations
- A huge number of candidates can be generated.
- The full database is scanned repeatedly.
- Pattern matching many candidates to every transaction is costly.
Illustrate the Apriori algorithm with a suitable example. Are there any limitations of Apriori algorithm?
Let and minsup count = 2.
- .
- ; each has support 3, so .
- ; all its 2-subsets are frequent, so it survives pruning. Its support is 2, hence .
- No larger candidate exists. All frequent itemsets are the union of .
For a rule, . Limitations are massive candidate generation, repeated scans, and expensive candidate matching.
2024 CT2 Q1(b): Find frequent itemsets and strong rules using Apriori for the six transactions below, with minimum support 30% and confidence 40%.
2022 CO3 Q3(a): Apply Apriori and FP-growth to the printed transactions with minimum support 30% and confidence 60%, compare their efficiency, and list strong rules matching the printed metarule.
2024 CT2: Six transactions and 30% minimum support require a support count of at least . Count candidates and prune itemsets with count below 2.
| Frequent itemset | Count |
|---|---|
| {Potato}, {Rice}, {Toothpaste}, {Bread}, {Milk}, {Sugar} | 2, 3, 4, 3, 2, 3 respectively |
| {Rice, Toothpaste} | 3 |
| {Bread, Sugar}, {Bread, Toothpaste}, {Bread, Milk}, {Milk, Sugar} | 2 each |
| {Bread, Milk, Sugar} | 2 |
All other candidates fail minimum count. Each frequent pair gives two strong rules: confidence is at least 40%. For example, Rice → Toothpaste has support and confidence ; Toothpaste → Rice has confidence .
The triple gives six rules: Bread → {Milk, Sugar} and Sugar → {Bread, Milk} each have confidence ; Milk → {Bread, Sugar} has confidence ; each two-item antecedent implies the remaining item with confidence . Each triple rule has support .
2022 question: The wording says five transactions, but the table lists eight. Assuming all eight printed rows are used, the minimum count is . The frequent itemsets found by either Apriori or FP-growth are:
| Size | Frequent itemsets and counts |
|---|---|
| 1 | A:5, B:6, C:3, D:6, E:4 |
| 2 | AB:4, AD:4, AE:4, BC:3, BD:4, BE:3, DE:3 |
| 3 | ABD:3, ABE:3, ADE:3 |
No 4-itemset reaches count 3. Apriori generates and tests candidates level by level; FP-growth compresses the ordered transactions into an FP-tree and mines conditional pattern bases. They must produce the same support counts for the same input. The tree often saves candidate generation, but actual runtime depends on the data.
The printed metarule requires two antecedent items and one consequent item. Every listed triple has support . The nine qualifying rules are , , , , , , , , and . Their confidences are 75%, 75%, 75%, 75%, 75%, 100%, 75%, 75%, and 100%, respectively. If the instructor instead intends only rows T1–T5, the minimum count is 2. The frequent sets and counts become:
- Singletons: A:4, B:4, C:2, D:4, E:3.
- Pairs: AB:4, AC:2, AD:3, AE:3, BC:2, BD:3, BE:3, CE:2, DE:2.
- Triples: ABC:2, ABD:3, ABE:3, ACE:2, ADE:2, BCE:2, BDE:2.
- Four-item sets: ABCE:2 and ABDE:2. No five-item set is frequent.
Under this alternative, use each triple to generate its three two-item → one-item rules and retain confidence at least 60%: all 21 candidate rules qualify except (50%). State which interpretation is used.
6. FP-growth
FP-growth removes Apriori’s costly candidate-generation stage.
- First database scan: count items, discard infrequent items, and order the frequent items by descending support in header list .
- Second scan: order each filtered transaction according to and insert it into an FP-tree. Shared prefixes share nodes; node counts are incremented.
- Header-table node links connect all tree nodes carrying the same item.
- Mine from the least frequent item upward. Its prefix paths form the conditional pattern base.
- Construct its conditional FP-tree and recursively mine it. A single path directly yields all combinations on that path.
For the lecture example with minsup = 3, the first scan gives the header list . Mining the conditional bases yields the maximal frequent itemsets and . FP-growth avoids candidate generation and is typically about an order of magnitude faster than Apriori on this example type.
Common transaction prefixes are stored once with counts. Conditional prefix paths let FP-growth examine only the data relevant to a suffix item.
Discuss about maximal frequent item set. Explain mining association rules FP-growth algorithm with minimum support threshold of 3.
, , , , , .
A maximal frequent itemset is frequent and has no frequent immediate superset. It compactly represents frequent itemsets but does not retain support counts of all subsets.
With minsup = 3, supports are F1:5, C1:5, N1:4, B1:4, S1:2; remove S1 and use header order F1,C1,N1,B1.
| Transaction | Filtered, ordered transaction |
|---|---|
F1,C1,N1,B1 | |
C1,B1 | |
F1,C1,N1 | |
F1,B1 | |
F1,C1,N1,B1 | |
F1,C1,N1 |
The FP-tree is:
root
├─ F1:5
│ ├─ C1:4 -> N1:4 -> B1:2
│ └─ B1:1
└─ C1:1 -> B1:1Conditional bases: for N1, F1,C1:4, yielding {F1,N1}:4, {C1,N1}:4, {F1,C1,N1}:4; for C1, F1:4, yielding {F1,C1}:4. The other frequent pairs are {F1,B1}:3 and {C1,B1}:3. Hence maximal frequent itemsets are {F1,C1,N1}:4, {F1,B1}:3, and {C1,B1}:3.
2026 CT1 Q3(b): For the five transactions shown below, use FP-growth to find all frequent itemsets with minimum support count 3.
Count the items: cold appears in (4); fever in (4); difficulty breathing appears twice; sore throat and running nose appear once each. Remove the infrequent items.
Using the tie order cold, fever, the filtered transactions are cold, cold fever, cold fever, fever, cold fever. The FP-tree has root → cold:4 → fever:3 and root → fever:1.
The frequent one-item patterns are {cold}:4 and {fever}:4. The conditional pattern base for fever contains cold:3, so {cold, fever}:3 is also frequent. These are all the frequent nonempty itemsets.
7. Apriori versus FP-growth
| Aspect | Apriori | FP-growth |
|---|---|---|
| Candidates | Generates candidates level-wise | No candidate generation |
| Database access | Repeated full scans | Two scans to build FP-tree; recursive conditional mining |
| Main structure | Candidate set/hash tree | FP-tree, header table, node links |
| Strength | Simple to understand/implement | Usually faster for dense/large data |
| Weakness | Candidate explosion and repeated scans | More complex tree/conditional-tree construction |
Find frequent itemsets and strong association rules using Apriori for T100 {M,O,N,K,E,Y}, T200 {D,O,N,K,E,Y}, T300 {M,A,K,E}, T400 {M,U,C,K,Y}, T500 {C,O,O,K,I,E}, with support = 30% and confidence = 40%. Compare Apriori and FP-growth algorithms.
There are five transactions, so minsup count = ceil(0.30 × 5) = 2. T500 prints the item O twice. Count it once because support counts transactions that contain the item.
: {K}:5, {E}:4, {M}:3, {O}:3, {Y}:3, {N}:2, {C}:2; prune D,A,U,I (count 1).
: {KE}:4; {MK,OK,OE,KY}:3; {ME,MY,ON,OY,NK,NE,NY,KC,EY}:2.
: {MKE}, {MKY}, {ONK}, {ONE}, {ONY}, {OKE}, {OKY}, {OEY}, {NKE}, {NKY}, {NEY}, {KEY}, each with support 2.
: {ONKE}, {ONKY}, {ONEY}, {OKEY}, {NKEY}, each support 2. : {ONKEY}:2.
Examples of strong rules: M -> K = 3/3 = 100%, E -> K = 4/4 = 100%, K -> E = 4/5 = 80%, O -> E = 3/3 = 100%, N -> O = 2/2 = 100%, C -> K = 2/2 = 100%, MK -> E = 2/3 = 66.7%, and ON -> KEY = 2/2 = 100%. Retain every rule whose calculated confidence is at least 40%.
Apriori uses join-prune and repeated scans; FP-growth uses a compressed prefix tree and conditional pattern bases, avoids candidates, and is normally faster on dense/large transaction data.
8. Rule generation from frequent itemsets
From a frequent -itemset , every nonempty proper subset gives rule : nontrivial rules. They all share but have different confidences.
If :
Therefore if a rule fails minimum confidence, rule candidates with a larger consequent below it in the level-wise rule-generation tree can be pruned.
How are frequent itemsets mined using vertical data format? How does anti-monotonicity help? If a frequent itemset contains 500 items, how many nonempty subsets can be frequent?
Intersect item transaction-ID sets to obtain support; prune candidates with an infrequent subset. All 2^500 − 1 nonempty subsets are frequent, including the original set (or 2^500 − 2 proper nonempty subsets).
9. Maximal and closed frequent itemsets
- Maximal frequent: no frequent immediate superset. It is a compact representation, but loses subset support information.
- Closed: no immediate superset has exactly the same support count.
- Closed frequent: both closed and frequent; it retains enough information to determine support of non-closed frequent sets.
Relationship: maximal frequent ⊆ closed frequent ⊆ frequent.
10. Evaluating association rules
Relaxing support/confidence can create enormous numbers of rules, so interestingness matters.
- Objective measures: statistics derived from data - support, confidence, correlation, and lift.
- Subjective measures: novelty, usefulness, actionability, visual inspection, templates, and filtering obvious rules.
Why confidence alone can mislead
For rule :
lift = 1: independent;lift > 1: positive correlation;lift < 1: negative correlation.
If 80% of everyone drinks coffee but only 75% of tea drinkers drink coffee, Tea -> Coffee has apparently high confidence (75%) but lift below 1: tea actually lowers the baseline coffee probability. A strong rule is not automatically an interesting rule.
Use the supplied contingency tables to examine hot dogs versus hamburgers or games versus videos. Check the paper’s support and confidence thresholds, independence, lift and chi-square; explain whether a strong rule is misleading.
2021 hot dogs → hamburgers: The four counts are 2000 (both), 500 (hamburgers only), 1000 (hot dogs only), and 1500 (neither), out of 5000. Support is and confidence is , so the rule meets 25% support and 50% confidence. Since , lift is : a positive association. The expected counts under independence are 1500, 1000, 1500 and 1000, giving with one degree of freedom.
2022 hot dogs → hamburgers: Its table differs: the four corresponding counts are 200, 500, 1000, 2500, total 4200. Support is and confidence is , so the rule is not strong at the stated 25% and 50% thresholds. Lift is 1 and : the printed table indicates independence. Do not reuse the 2021 counts for the 2022 question.
Determine whether game and video purchases are independent using lift and chi-square. Is game → video strong at minimum support 30% and confidence 55%?
The table has 4,000 who buy both, 3,500 video only, 2,000 game only and 500 neither, for 10,000 transactions. Thus , , and .
Support is and confidence of game → video is . Both thresholds are met, so the rule is strong by support and confidence.
However, lift is . Expected counts under independence are 4,500, 3,000, 1,500 and 1,000. Hence with one degree of freedom. The purchases are negatively associated, not independent: video is less common among game buyers than in the population overall. High confidence alone is misleading here.
Limits of lift and additional objective measures
Lift/interest factor is not inversion-invariant: it can rate a pair differently from the equivalent relationship between both items being absent. In the lecture comparison, but , even though the contingency tables have the same association structure under inversion. Thus lift alone can be misleading.
For a binary contingency table, the phi correlation coefficient is:
The IS measure combines interest and support:
It is mathematically equivalent to cosine similarity for binary variables.
Two useful properties for an objective measure are:
- Inversion property: its value is unchanged when is exchanged with and with .
- Null-addition property: its value is unchanged when increases—adding transactions containing neither item should not change their association.

























