Back to the 2020 paper

Module 2: Data Mining Fundamentals and Association Rule Mining

20206m

Write and explain pseudocode for a priori algorithm. Explain the terms:

(i) support count;
(ii) confidence.

Worked SolutionAI Assisted

Apriori Algorithm — Pseudocode & Key Terms

Pseudocode

Algorithm Apriori(D, min_sup):
    Input:  D = transaction database, min_sup = minimum support threshold
    Output: L = all frequent itemsets in D

    L1 = {frequent 1-itemsets found by scanning D}
    k = 2
    while (L(k-1) is not empty):
        Ck = apriori_gen(L(k-1))          // candidate generation
        for each transaction t in D:
            Ct = subset(Ck, t)             // candidates contained in t
            for each candidate c in Ct:
                c.count++
        Lk = { c in Ck | c.count >= min_sup }
        L = L ∪ Lk
        k = k + 1
    return L

Function apriori_gen(L(k-1)):
    Ck = ∅
    // Join step: join L(k-1) with itself
    for each pair (p, q) in L(k-1) x L(k-1):
        if p and q share the first (k-2) items:
            c = p ∪ {last item of q}
            // Prune step: remove candidates with an infrequent subset
            if all (k-1)-subsets of c are in L(k-1):
                Ck = Ck ∪ {c}
    return Ck

Explanation

  1. First pass: count individual items to find frequent 1-itemsets (L1).
  2. Iterative passes: for k = 2, 3, ..., generate candidate k-itemsets (Ck) by joining frequent (k-1)-itemsets that share a common (k-2)-item prefix.
  3. Prune step: discard any candidate whose any (k-1)-subset is not frequent (using the apriori property: all subsets of a frequent itemset must be frequent).
  4. Count & filter: scan the database, count support for surviving candidates, keep only those meeting min_sup → Lk.
  5. Repeat until no new frequent itemsets are found.

Key Terms

(i) Support Count
The number of transactions in the database that contain a given itemset:
support_count(X)=∣{t∈D:X⊆t}∣support\_count(X) = |\{t \in D : X \subseteq t\}|
Support (as a fraction) = support_count / |D|. It measures how frequently an itemset appears.

(ii) Confidence
For a rule A⇒BA \Rightarrow B, confidence measures how reliably B follows when A is present:
confidence(A⇒B)=support_count(A∪B)support_count(A)confidence(A \Rightarrow B) = \frac{support\_count(A \cup B)}{support\_count(A)}
It is the conditional probability P(B∣A)P(B \mid A) — the fraction of transactions containing A that also contain B.

Support: "How often does this itemset occur overall?"
Confidence: "Given the antecedent occurred, how often does the consequent follow?"

Similar questions

Data MiningConsider a database D, consisting of 15 transactions. Suppose minimum support count is 2 (i.e., min_sup = 20%) and minimum confidence required is 70%. Find out the frequent item set using a priori algorithm. Explain each step with diagram: | A1 | A2 | A3 | A4 | A5 | A6 | A7 | A8 | A9 | |:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:| | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 |20208mData MiningConsider the 5 transactions given below. If minimum support is 30% and minimum confidence is 80% determine the frequent itemsets and association rules using apriori algorithm. | Transaction | Items | | :---: | --- | | T1 | Bread, Jelly, Butter | | T2 | Bread, Butter | | T3 | Bread, Milk, Butter | | T4 | Coke, Bread | | T5 | Coke, Milk |20239mData MiningSupport of an itemset represents (i) Probability that the consequent occurs given the antecedent (ii) Number of attributes in the database (iii) Frequency with which the itemset occurs in the database (iv) Number of rules generated20262mDesign & Analysis of AlgorithmsWrite short notes on: Approximation algorithms20227m
Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.