Apriori

Every subset of a frequent itemset is frequent, so grow candidates level by level and prune any with an infrequent subset.

16 min read1383 wordscore2 viewsupdated 2026-10-07

Definition

Apriori finds every frequent itemset in a database of transactions — every set of items that appears together in at least a fraction σ\sigma of the baskets — by searching level by level: frequent 1-itemsets, then 2-itemsets built from them, then 3-itemsets, and so on. It then turns frequent itemsets into association rules A⇒CA \Rightarrow C such as {Bread, Jam} ⇒ {Butter}, kept when their confidence is high enough.

At a glance

Task
Unsupervised pattern mining: frequent itemsets and association rules
Input → output
a list of transactions (sets of items) → all itemsets with support ≥σ\ge\sigma, plus rules with confidence ≥γ\ge\gamma
Learns
no parameters — it enumerates patterns; the "model" is the list of itemsets and rules with their support, confidence and lift
Training cost
one database scan per level; total work ≈∑k∣Ck∣⋅n\approx \sum_k |C_k|\cdot n subset tests — exponential in the worst case, practical when σ\sigma keeps ∣Ck∣|C_k| small
Prediction cost
look up rules whose antecedent is contained in a basket: O(#rules)O(\#\text{rules}) subset checks, or a hash lookup
Hyperparameters
minimum support σ\sigma, minimum confidence γ\gamma, maximum itemset length; ranking metric (lift, leverage, conviction)
Assumes
items are binary (present / absent) — no quantities, no order; patterns worth knowing are frequent

The problem

A shop logs millions of baskets and wants to know which products are bought together — to place them on the same shelf, bundle them, or recommend one when the other is in the cart. With dd products there are 2d−12^d-1 possible itemsets. Counting all of them is hopeless: for d=100d=100 that is about 1.27×10301.27\times10^{30} sets, and even the pairs alone for a 10,000-product catalogue number 49,995,000 — each one needing a pass over the data to count.

Supervised methods do not help: there is no label to predict, and we want every strong co-occurrence, not one decision function. What we need is an exact way to skip the overwhelming majority of itemsets without counting them — while still guaranteeing that every frequent one is found.

The idea

If {Bread, Jam, Milk} appears in at least 3 baskets, then {Jam, Milk} certainly appears in at least those same 3 baskets — a basket that contains the bigger set contains every part of it. Turned around: if {Jam, Milk} is rare, every set that contains it is at least as rare. So once we learn that one small itemset is infrequent, we can delete its entire family of supersets from the search, unseen.

Apriori exploits this level by level. Count single items; keep the frequent ones. Build 2-item candidates only from frequent items; count them; keep the frequent ones. Build 3-item candidates only from frequent pairs — and before counting, throw away any candidate that has an infrequent pair inside it. Repeat until no candidates remain. Each level needs one scan of the database, and the name says it all: knowledge from the previous level is used a priori to prune the next.

Vocabulary

Item
one product / event / token, e.g. Bread
Transaction (basket)
one set of items bought together, t⊆It\subseteq I; the database DD is a list of nn of them
Itemset, k-itemset
any set of items X⊆IX\subseteq I; a kk-itemset has exactly kk items
Support count
σ(X)\sigma(X) = number of transactions that contain all of XX
Support
s(X)=σ(X)/ns(X)=\sigma(X)/n, the fraction of baskets containing XX
Frequent itemset
an itemset with s(X)≥s(X)\ge the minimum support; LkL_k = all frequent kk-itemsets
Candidate set
CkC_k = the kk-itemsets Apriori will actually count at level kk
Downward closure (Apriori property)
every subset of a frequent itemset is frequent; equivalently, every superset of an infrequent itemset is infrequent
Rule A ⇒ C
antecedent AA and consequent CC, disjoint itemsets: baskets with AA tend to contain CC
Lattice
all 2d−12^d-1 itemsets arranged by size, with an edge from each set to its supersets one item bigger

The math

Let D={t1,…,tn}D=\{t_1,\dots,t_n\} be the transactions over item set II. The support of an itemset counts the transactions that cover it:

s(X)=σ(X)n=∣{ t∈D:X⊆t }∣ns(X)=\frac{\sigma(X)}{n}=\frac{\big|\{\,t\in D : X\subseteq t\,\}\big|}{n}
XX
an itemset
σ(X)\sigma(X)
support count: number of transactions containing every item of X
nn
number of transactions
T(X)T(X)
below: the set {t:X⊆t}\{t: X\subseteq t\} of transactions covering XX (its tidset)

Deriving the Apriori property. Take X⊆YX\subseteq Y. Any transaction that contains YY contains every item of YY, hence every item of XX. So the covering sets are nested, and their sizes follow:

X⊆Y  ⟹  T(Y)⊆T(X)  ⟹  s(Y)≤s(X)X\subseteq Y\;\Longrightarrow\;T(Y)\subseteq T(X)\;\Longrightarrow\;s(Y)\le s(X)
T(⋅)T(\cdot)
set of transactions covering an itemset
s(Y)≤s(X)s(Y)\le s(X)
support is anti-monotone: adding items can never raise it

The contrapositive is the pruning rule: if s(X)<σmin⁡s(X)<\sigma_{\min} then s(Y)<σmin⁡s(Y)<\sigma_{\min} for every Y⊇XY\supseteq X. Hence a kk-itemset can only be frequent if all kk of its (k−1)(k-1)-subsets are in Lk−1L_{k-1}, and the candidates at level kk can be restricted to:

Ck={ p∪{qk−1}  :  p,q∈Lk−1,  p1..k−2=q1..k−2,  pk−1<qk−1}  ∖  {c:∃ s⊂c, ∣s∣=k−1, s∉Lk−1}C_k=\Big\{\,p\cup\{q_{k-1}\}\;:\;p,q\in L_{k-1},\;p_{1..k-2}=q_{1..k-2},\;p_{k-1}<q_{k-1}\Big\}\;\setminus\;\Big\{c : \exists\, s\subset c,\ |s|=k-1,\ s\notin L_{k-1}\Big\}
p1..k−2p_{1..k-2}
the first k−2 items of p, with items kept in one fixed (e.g. alphabetical) order
p∪{qk−1}p\cup\{q_{k-1}\}
join: two frequent (k−1)-sets with the same prefix give one k-set
∖{… }\setminus\{\dots\}
prune: drop candidates that have an infrequent (k−1)-subset

The join is complete: any frequent kk-itemset {x1<⋯<xk}\{x_1<\dots<x_k\} has the two frequent subsets {x1,…,xk−2,xk−1}\{x_1,\dots,x_{k-2},x_{k-1}\} and {x1,…,xk−2,xk}\{x_1,\dots,x_{k-2},x_k\}, which share their first k−2k-2 items — so it is always generated. And it never generates the same candidate twice, because the shared prefix and the two last items determine the pair.

Rules. From a frequent itemset XX and a non-empty proper subset AA, form A⇒CA\Rightarrow C with C=X∖AC=X\setminus A. Its strength is measured by:

conf⁡(A⇒C)=s(A∪C)s(A)=P^(C∣A),lift⁡(A⇒C)=conf⁡(A⇒C)s(C)=s(A∪C)s(A) s(C)\operatorname{conf}(A\Rightarrow C)=\frac{s(A\cup C)}{s(A)}=\hat P(C\mid A),\qquad \operatorname{lift}(A\Rightarrow C)=\frac{\operatorname{conf}(A\Rightarrow C)}{s(C)}=\frac{s(A\cup C)}{s(A)\,s(C)}
conf⁡\operatorname{conf}
fraction of baskets with A that also contain C — an estimate of P(C | A)
lift⁡\operatorname{lift}
how much more often A and C co-occur than if they were independent; 1 = independent, > 1 = positive association
s(C)s(C)
baseline rate of the consequent
lev⁡(A⇒C)=s(A∪C)−s(A) s(C),conv⁡(A⇒C)=1−s(C)1−conf⁡(A⇒C)\operatorname{lev}(A\Rightarrow C)=s(A\cup C)-s(A)\,s(C),\qquad \operatorname{conv}(A\Rightarrow C)=\frac{1-s(C)}{1-\operatorname{conf}(A\Rightarrow C)}
lev⁡\operatorname{lev}
leverage: excess co-occurrence over independence, in absolute support units
conv⁡\operatorname{conv}
conviction: how much more often the rule would be wrong if A and C were independent; ∞ for a rule that is never wrong

Rule generation has its own anti-monotone property. For a fixed itemset XX, conf⁡(X∖C⇒C)=s(X)/s(X∖C)\operatorname{conf}(X\setminus C\Rightarrow C)=s(X)/s(X\setminus C). Moving an item from the antecedent to the consequent makes the antecedent smaller, so its support grows (Apriori property) and the confidence can only fall. If {B,J}⇒{U}\{B,J\}\Rightarrow\{U\} fails the confidence threshold, so do {B}⇒{J,U}\{B\}\Rightarrow\{J,U\} and {J}⇒{B,U}\{J\}\Rightarrow\{B,U\} — consequents can be grown level by level too.

What the two thresholds do

Minimum support σ
sets the pruning power. Lowering it can only add frequent itemsets (the set {X:s(X)≥σ}\{X: s(X)\ge\sigma\} grows as σ\sigma falls), and the number of candidates — and runtime — grows roughly exponentially as patterns get longer. Raising it removes rare but possibly interesting combinations.
Minimum confidence γ
only filters rules after mining; it costs nothing at the expensive itemset stage. High γ\gamma keeps reliable rules, but confidence ignores the base rate s(C)s(C), so it must be read together with lift.
Maximum length
stops the level loop at kmax⁡k_{\max}; caps the worst case at ∑k≤kmax⁡(dk)\sum_{k\le k_{\max}}\binom{d}{k} candidates.

Worked example: ten breakfast baskets

Five items — Bread, bUtter, Jam, Milk, Eggs — in ten baskets. Minimum support is 30% (a count of 3), minimum confidence 0.7. Items are kept in the fixed order B < U < J < M < E for the join.

BasketItemsLetters
T1Bread, Butter, JamB U J
T2Bread, Butter, JamB U J
T3Bread, Butter, Jam, EggsB U J E
T4Bread, Butter, MilkB U M
T5Bread, Butter, MilkB U M
T6Bread, MilkB M
T7Butter, Milk, EggsU M E
T8Jam, MilkJ M
T9Bread, MilkB M
T10Butter, JamU J
The transactions. Highlighted: the three baskets containing {Bread, Butter, Jam}, the only frequent 3-itemset.

Apriori by hand (minimum support count 3)

  1. 1Scan 1, count items. B 7, U 7, J 5, M 6, E 2. Eggs falls below 3, so L1={B,U,J,M}L_1=\{B,U,J,M\} — and the 15 larger itemsets containing E are dead without being looked at.
  2. 2Join L1L_1. Every pair of frequent items: C2={BU,BJ,BM,UJ,UM,JM}C_2=\{BU, BJ, BM, UJ, UM, JM\} — 6 candidates instead of the 10 possible pairs. At k=2k=2 the prune step removes nothing (both 1-subsets are in L1L_1 by construction).
  3. 3Scan 2, count pairs. BU 5, BJ 3, BM 4, UJ 4, UM 3, JM 1. So L2={BU,BJ,BM,UJ,UM}L_2=\{BU,BJ,BM,UJ,UM\}; only Jam + Milk is rare.
  4. 4Join L2L_2 (same first item): BU+BJ → BUJ, BU+BM → BUM, BJ+BM → BJM, UJ+UM → UJM.
  5. 5Prune. BJM contains JM and UJM contains JM — not in L2L_2, so both are deleted without counting. C3={BUJ,BUM}C_3=\{BUJ, BUM\}.
  6. 6Scan 3. BUJ 3 (T1, T2, T3), BUM 2 (T4, T5). L3={BUJ}L_3=\{BUJ\}.
  7. 7Join L3L_3. A single itemset has no partner, so C4=∅C_4=\varnothing and the search stops after 3 scans. In total 13 itemsets were counted out of 31, and 10 are frequent.
Level kJoinedPrunedCounted (support)Frequent Lₖ
150B 7 · U 7 · J 5 · M 6 · E 2B, U, J, M
260BU 5 · BJ 3 · BM 4 · UJ 4 · UM 3 · JM 1BU, BJ, BM, UJ, UM
342 (BJM, UJM)BUJ 3 · BUM 2BUJ
40——∅ → stop
Level by level. Pruned = generated by the join but removed by the subset check before the scan.

Rules. Each frequent itemset of size ≥2\ge 2 yields candidate rules. From BUJ (support 3): BJ⇒UBJ\Rightarrow U has confidence 3/3=1.003/3=1.00; UJ⇒BUJ\Rightarrow B 3/4=0.753/4=0.75; BU⇒JBU\Rightarrow J and J⇒BUJ\Rightarrow BU 3/5=0.603/5=0.60; B⇒UJB\Rightarrow UJ and U⇒BJU\Rightarrow BJ 3/7=0.433/7=0.43. From the pairs: J⇒UJ\Rightarrow U 4/5=0.804/5=0.80, B⇒UB\Rightarrow U and U⇒BU\Rightarrow B 5/7=0.715/7=0.71, everything else below 0.7. Five rules pass:

RuleSupportConfidenceLiftLeverageConviction
{Bread, Jam} ⇒ {Butter}0.301.0001.4290.09∞
{Jam} ⇒ {Butter}0.400.8001.1430.051.50
{Butter, Jam} ⇒ {Bread}0.300.7501.0710.021.20
{Bread} ⇒ {Butter}0.500.7141.0200.011.05
{Butter} ⇒ {Bread}0.500.7141.0200.011.05
All rules with confidence ≥ 0.7, sorted by lift (values from mlxtend, below). s(Butter) = s(Bread) = 0.7.

A new basket. A customer has {Bread, Jam} in the cart. The applicable rules are those whose antecedent is inside the cart and whose consequent is not: {B,J}⇒{U}\{B,J\}\Rightarrow\{U\} (confidence 1.00, lift 1.43) is the strongest, so we recommend Butter. Note the bottom two rows: Bread ⇒ Butter has 71% confidence, which sounds strong, but its lift is 1.02 — Butter is in 70% of all baskets anyway, so knowing Bread is there tells us almost nothing.

▸ apriori · 10 baskets · minsup 3step 1/24
min supportB Bread · U Butter · J Jam · M Milk · E Eggs
k=1k=2k=3k=4k=5BUJMEBUBJBMBEUJUMUEJMJEMEBUJBUMBUEBJMBJEBMEUJMUJEUMEJMEBUJMBUJEBUMEBJMEUJMEBUJME
▢ candidate■ frequent■ counted, infrequent⊠ pruned, never countedfaded: never generated
T1BUJ
T2BUJ
T3BUJE
T4BUM
T5BUM
T6BM
T7UME
T8JM
T9BM
T10UJ
counted 0/31pruned 0frequent 0rules —
  1. 1L₁ ← items with count ≥ minsup
  2. 2for k = 2, 3, … while Lₖ₋₁ ≠ ∅:
  3. 3 Cₖ ← join pairs of Lₖ₋₁ that
  4. 4 share their first k−2 items
  5. 5 drop c ∈ Cₖ with an infrequent
  6. 6 (k−1)-subset
  7. 7 scan: count(c) for every c ∈ Cₖ
  8. 8 Lₖ ← { c : count(c) ≥ minsup }
  9. 9for each frequent X and A ⊂ X:
  10. 10 keep A → X∖A if s(X)/s(A) ≥ minconf

10 baskets over 5 items, so there are 2⁵ − 1 = 31 possible itemsets. Minimum support = 3 baskets (30%); minimum confidence = 0.7.

fig.Apriori on the ten baskets, drawn on the lattice of all 31 itemsets (rows k = 1…5). With min support 3/10: Eggs (2) fails at k = 1 and its 15 supersets fade; the join proposes 6 pairs, JM (1) fails; the join proposes 4 triples, BJM and UJM are crossed out by the subset check before counting, BUJ (3) survives and BUM (2) fails; C₄ is empty. 13 of 31 itemsets are counted, 10 are frequent, and 5 rules reach confidence 0.7 — the basket {Bread, Jam} gets Butter from BJ → U (1.00, lift 1.43). Switch min support: at 2/10 Apriori counts 17 itemsets and finds 13 frequent ones; at 4/10 it counts 11 and finds 7.

The algorithm, step by step

Apriori(D, σ, γ)

  1. 1Level 1. One scan of DD counts every item; L1L_1 = items with count ≥σn\ge\sigma n.
  2. 2Join. For k=2,3,…k=2,3,\dots: sort each itemset in Lk−1L_{k-1} by a fixed item order; merge every pair that agrees on its first k−2k-2 items into a kk-itemset.
  3. 3Prune. Delete any candidate with a (k−1)(k-1)-subset not in Lk−1L_{k-1} (store Lk−1L_{k-1} in a hash set, so each check is kk lookups).
  4. 4Count. One scan of DD: for every transaction, increment every candidate it contains (a hash tree or trie over CkC_k finds them without testing all candidates).
  5. 5Filter. Lk={c∈Ck:σ(c)≥σn}L_k=\{c\in C_k:\sigma(c)\ge\sigma n\}. Stop when LkL_k (or Ck+1C_{k+1}) is empty.
  6. 6Rules. For each frequent XX with ∣X∣≥2|X|\ge2 and each non-empty A⊂XA\subset X, output A⇒X∖AA\Rightarrow X\setminus A if σ(X)/σ(A)≥γ\sigma(X)/\sigma(A)\ge\gamma. All supports are already known — no more scans.

Complexity

Database scans
kmax⁡+1k_{\max}+1 at most, where kmax⁡k_{\max} is the length of the longest frequent itemset
Counting
level kk costs about n⋅min⁡ ⁣(∣Ck∣,(wk))n\cdot\min\!\big(|C_k|,\binom{w}{k}\big) subset tests, ww = average basket width; this dominates
Candidate generation
O(∣Lk−1∣2⋅k)O(|L_{k-1}|^2\cdot k) for the join, O(∣Ck∣⋅k)O(|C_k|\cdot k) hash lookups for the prune
Memory
all of CkC_k with counters must fit in memory; ∣C2∣=(∣L1∣2)|C_2|=\binom{|L_1|}{2} is usually the peak
Worst case
a frequent itemset of length mm forces all 2m−22^m-2 of its proper subsets to be frequent — e.g. 210−2=10222^{10}-2=1022 for m=10m=10 — so long patterns are inherently expensive

Variants and practical tuning

VariantChangeHelps when
AprioriTidafter scan 1, replace each transaction by the candidates it containslater levels: the encoded database shrinks fast
DHP (hash-based)while counting items, hash all pairs into buckets; a pair in a light bucket can't be frequentC₂ is huge — the usual bottleneck
Transaction reductiondrop baskets that contain no frequent k-itemset from later scansmany short baskets
Partitioningmine each chunk locally; any globally frequent set is frequent in some chunk; one verification scandata does not fit in memory; 2 scans total
Sampling (Toivonen)mine a sample at a lowered threshold, then verify on the full dataapproximate answers are fine, scans are costly
FP-Growth / Eclatno level-wise candidate generation at alllow support, dense data, long patterns
Classic refinements of Apriori and where the work goes.

Tuning in practice

Start high, lower slowly
begin with a support that yields a few hundred itemsets (e.g. 1–5% of baskets for retail) and halve it while runtime and output size stay manageable
Rank by lift, not confidence
filter by a modest confidence, then sort by lift or leverage; drop rules with lift ≤ 1
Cap the length
max_len=3 or 4 is often enough for actionable rules, and caps the worst case
Aggregate items
rare SKUs never reach support; mining at the category level (all jams → Jam) finds patterns hidden at product level
Check stability
re-mine on a different month or a bootstrap sample; rules that vanish were noise

In code

python
1import numpy as np
2from itertools import combinations
3
4def apriori(X, items, min_support):
5 """X: boolean (n_transactions, n_items). Returns {itemset (tuple of col idx): support count}."""
6 n = X.shape[0]
7 min_count = int(np.ceil(min_support * n))
8 counts = X.sum(axis=0)
9 L = {(j,): int(c) for j, c in enumerate(counts) if c >= min_count}
10 frequent, k, counted = dict(L), 2, X.shape[1]
11 while L:
12 prev = sorted(L)
13 # join: two (k-1)-itemsets sharing their first k-2 items
14 cands = [a + (b[-1],) for a, b in combinations(prev, 2) if a[:-1] == b[:-1]]
15 # prune: every (k-1)-subset must be frequent
16 prevset = set(prev)
17 cands = [c for c in cands if all(s in prevset for s in combinations(c, k - 1))]
18 counted += len(cands)
19 # count: a transaction contains c iff all its columns are 1
20 L = {}
21 for c in cands:
22 s = int(X[:, list(c)].all(axis=1).sum())
23 if s >= min_count:
24 L[c] = s
25 frequent.update(L)
26 k += 1
27 return frequent, counted
28
29def rules(frequent, n, min_conf):
30 out = []
31 for iset, s in frequent.items():
32 for r in range(1, len(iset)):
33 for A in combinations(iset, r):
34 C = tuple(i for i in iset if i not in A)
35 conf = s / frequent[A]
36 if conf >= min_conf:
37 lift = conf / (frequent[C] / n)
38 out.append((A, C, s / n, conf, lift))
39 return out
40
41items = ["Bread", "Butter", "Jam", "Milk", "Eggs"]
42baskets = ["BUJ", "BUJ", "BUJE", "BUM", "BUM", "BM", "UME", "JM", "BM", "UJ"]
43code = {"B": 0, "U": 1, "J": 2, "M": 3, "E": 4}
44X = np.zeros((len(baskets), len(items)), dtype=bool)
45for i, b in enumerate(baskets):
46 X[i, [code[ch] for ch in b]] = True
47
48freq, counted = apriori(X, items, min_support=0.3)
49print("candidates counted:", counted, "of", 2 ** len(items) - 1) # 13 of 31
50for iset, s in sorted(freq.items(), key=lambda kv: (len(kv[0]), kv[0])):
51 print([items[j] for j in iset], s) # ... ['Bread', 'Butter', 'Jam'] 3
52for A, C, sup, conf, lift in rules(freq, len(baskets), 0.7):
53 print([items[j] for j in A], "->", [items[j] for j in C], f"sup={sup:.2f} conf={conf:.3f} lift={lift:.3f}")
54# ['Bread', 'Jam'] -> ['Butter'] sup=0.30 conf=1.000 lift=1.429 (and 4 more)
From scratch with NumPy: level-wise join, subset prune, boolean-matrix counting, and rules. Prints 13 candidates counted, the 10 frequent itemsets and the 5 rules.
python
1import pandas as pd
2from mlxtend.preprocessing import TransactionEncoder
3from mlxtend.frequent_patterns import apriori, association_rules
4
5baskets = [
6 ["Bread", "Butter", "Jam"], ["Bread", "Butter", "Jam"], ["Bread", "Butter", "Jam", "Eggs"],
7 ["Bread", "Butter", "Milk"], ["Bread", "Butter", "Milk"], ["Bread", "Milk"],
8 ["Butter", "Milk", "Eggs"], ["Jam", "Milk"], ["Bread", "Milk"], ["Butter", "Jam"],
9]
10te = TransactionEncoder()
11X = pd.DataFrame(te.fit(baskets).transform(baskets), columns=te.columns_) # one-hot booleans
12
13freq = apriori(X, min_support=0.3, use_colnames=True) # optionally max_len=3
14print(freq.sort_values("support", ascending=False).to_string(index=False))
15
16rules = association_rules(freq, metric="confidence", min_threshold=0.7)
17print(rules[["antecedents", "consequents", "support", "confidence", "lift", "leverage", "conviction"]]
18 .sort_values("lift", ascending=False).round(3).to_string(index=False))
19# antecedents consequents support confidence lift leverage conviction
20# (Jam, Bread) (Butter) 0.3 1.000 1.429 0.09 inf
21# (Jam) (Butter) 0.4 0.800 1.143 0.05 1.50
22# (Jam, Butter) (Bread) 0.3 0.750 1.071 0.02 1.20
23# (Bread) (Butter) 0.5 0.714 1.020 0.01 1.05
24# (Butter) (Bread) 0.5 0.714 1.020 0.01 1.05
The same baskets with mlxtend: 10 frequent itemsets and the 5-rule table above, including leverage and conviction.

Use when

  • +You need every frequent itemset exactly, with an easy-to-explain algorithm and output ("bought together in 30% of baskets").
  • +Support is moderately high and patterns are short — sparse retail baskets, click sets, symptom lists.
  • +Data lives in a database where one scan per level is cheap (SQL GROUP BY per level works).
  • +You want the candidate counts and supports themselves, e.g. to compute any rule metric afterwards.

Avoid when

  • −Minimum support must be very low (rare but valuable items) — candidate sets explode.
  • −Data is dense or patterns are long: all 2^m − 2 subsets of a long pattern must be generated and counted.
  • −The database is huge and each scan is expensive — FP-Growth needs two scans, Eclat one.
  • −Items have quantities, order or time — use sequential pattern mining or a supervised model instead.

Where it's used

Market-basket analysis

Shelf placement, bundles and "frequently bought together" in retail and e-commerce.

Recommendation seeds

Rules with high lift give cheap, explainable item-to-item recommendations.

Medical and pharmacovigilance data

Co-occurring diagnoses, or drug combinations that appear with adverse events more than expected.

Web usage and log mining

Pages visited in one session, or alarm codes that fire together in system logs.

Check yourself

In some database, {A, C} has support 0.3, {A} 0.4 and {C} 0.5. What are the confidence and lift of A ⇒ C?

Check yourself

L₂ = {AB, AC, AD, BC, CD} (items ordered A < B < C < D). Which candidates survive the join and prune into C₃?

Check yourself

Apriori finds that {Jam, Milk} appears in only 1 of 10 baskets (min count 3). What can it conclude about {Bread, Jam, Milk} without scanning?

Check yourself

{Bread, Jam} ⇒ {Butter} has confidence 1.0. Without any counting, what do we know about {Jam} ⇒ {Bread, Butter}?

Remember

  • ✓Support is anti-monotone: X⊆Y⇒s(Y)≤s(X)X\subseteq Y\Rightarrow s(Y)\le s(X). Every superset of an infrequent itemset is infrequent.
  • ✓Apriori is level-wise: join frequent (k−1)(k-1)-itemsets sharing k−2k-2 items, prune any candidate with an infrequent subset, then count the survivors in one scan.
  • ✓On the 10-basket example it counts 13 of 31 itemsets in 3 scans and finds 10 frequent ones; BJM and UJM are pruned without counting.
  • ✓Rules come from frequent itemsets for free: confidence = s(A∪C)/s(A). Always check lift, because confidence ignores how common the consequent already is.
  • ✓Minimum support controls the cost; low support or long patterns blow up candidate sets — then use FP-Growth or Eclat.
← back to ML Algorithms roadmap