Source: Akash Notes Folder.
Major stuff: Apriori Algo, FP Growth Algo Box plot, theory Z Score, Confidence calc Smoothing... Binning Numerical

How to use this note

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 .

Lecture figure - market basket example

Plain meaning

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 .

Lecture figure - itemset support

Lecture figure - association-rule support and confidence

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.

PYQ - 2026, CO3(a)-(b)

(a) Write a short note on market basket analysis. (b) How to compute confidence for an association rule ?

2026 semester CO3(a) and (b), market baskets and rule confidence

Answer

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, .

PYQ — 2026 CT1 Q3(a); 2024 CT2 Q1(a)

Define support and confidence. In 50 transactions, 40 contain milk, 30 bread and 20 both: find support and confidence of milk → bread.

Original question from the supplied paper

Additional original question

Answer

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.

PYQ - 2025, CO3(a)

Explain in detail about association-rules mining task. Define confidence of an association rule. Discuss about the anti-monotone property of support.

2025 semester CO3(a), association rules and support

Answer

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 Lk

Join 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.

Lecture figure - hash tree for candidate itemsets

Limitations

  1. A huge number of candidates can be generated.
  2. The full database is scanned repeatedly.
  3. Pattern matching many candidates to every transaction is costly.
PYQ - 2025, CO3(c)

Illustrate the Apriori algorithm with a suitable example. Are there any limitations of Apriori algorithm?

2025 semester CO3(c), Apriori

Answer

Let and minsup count = 2.

  1. .
  2. ; each has support 3, so .
  3. ; all its 2-subsets are frequent, so it survives pruning. Its support is 2, hence .
  4. 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.

PYQ — 2024 CT2 Q1(b); 2022 semester CO3 Q3(a)

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.

2022 semester CO3 Q3(a), including all eight printed transactions and the metarule

Additional original question

Answer

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 itemsetCount
{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:

SizeFrequent itemsets and counts
1A:5, B:6, C:3, D:6, E:4
2AB:4, AD:4, AE:4, BC:3, BD:4, BE:3, DE:3
3ABD: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.

  1. First database scan: count items, discard infrequent items, and order the frequent items by descending support in header list .
  2. Second scan: order each filtered transaction according to and insert it into an FP-tree. Shared prefixes share nodes; node counts are incremented.
  3. Header-table node links connect all tree nodes carrying the same item.
  4. Mine from the least frequent item upward. Its prefix paths form the conditional pattern base.
  5. 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.

flowchart TD R((root)) --> F[F:4] F --> C[C:3] C --> A[A:3] A --> M[M:2] M --> P[P:2] C --> B[B:1] B --> M2[M:1]

Lecture figure - FP-tree construction

Lecture figure - conditional pattern bases and FP-trees

Why the tree helps

Common transaction prefixes are stored once with counts. Conditional prefix paths let FP-growth examine only the data relevant to a suffix item.

PYQ - 2025, CO3(b)

Discuss about maximal frequent item set. Explain mining association rules FP-growth algorithm with minimum support threshold of 3.

, , , , , .

2025 semester CO3(b), FP-growth and all six transactions

Answer

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.

TransactionFiltered, 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:1

Conditional 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.

PYQ — 2026 CT1 Q3(b)

2026 CT1 Q3(b): For the five transactions shown below, use FP-growth to find all frequent itemsets with minimum support count 3.

Original question from the supplied paper

Answer

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

AspectAprioriFP-growth
CandidatesGenerates candidates level-wiseNo candidate generation
Database accessRepeated full scansTwo scans to build FP-tree; recursive conditional mining
Main structureCandidate set/hash treeFP-tree, header table, node links
StrengthSimple to understand/implementUsually faster for dense/large data
WeaknessCandidate explosion and repeated scansMore complex tree/conditional-tree construction
PYQ - 2026, CO3(c)-(d)

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.

2026 semester CO3, including the full transaction table for part (c)

Answer

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.

Lecture figure - level-wise rule-generation pruning

PYQ — 2021 CT Set 4 CO3; 2022 semester CO3 Q3(b)(iii)

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?

2021 class test Set 4, CO3

2022 semester CO3 Q3(b)(iii)

Answer

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.

Lecture figure - maximal frequent itemsets

Lecture figure - closed versus maximal frequent itemsets

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.

Lecture figure - contingency table

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.

Lecture figure - limitation of confidence

Lecture figure - lift / interest factor

PYQ — 2021 CT Sets 1–4 CO3; 2022 semester CO3 Q3(b)

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 class test Set 1, CO3, including the contingency table

2021 class test Set 2, CO3, including the contingency table

2021 class test Set 3, CO3, including the contingency table

2021 class test Set 4, CO3, including the contingency table

2022 semester CO3 Q3(b), including the contingency table

Answer

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.

PYQ — 2021 CT Sets 3 and 4 CO3

Determine whether game and video purchases are independent using lift and chi-square. Is game → video strong at minimum support 30% and confidence 55%?

2021 game and video contingency-table question

2021 game-to-video association-rule question

Answer

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.