Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Things that go together
A supermarket wants to know which products are bought together, so it can place them nearby or bundle them. Looking through thousands of receipts, you might notice that coffee, milk and sugar often appear on the same receipt. Apriori finds all such groups systematically. It uses a simple observation: if a pair of items is rare, any larger group containing that pair must be at least as rare, so there is no need to count it.
Maintenance and alarm logs are transactions too: which fault codes, warnings and part replacements occur together on the same flight or work order? Frequent co-occurrence patterns point to common causes, cascading failures or documentation habits. The same tools mine software crash reports, test failures and configuration combinations.
- 1. Support of an itemset is…
- 2. If {coffee, milk} is rare, then {coffee, milk, sugar} is…
- 3. Apriori finds itemsets…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Support, confidence and lift by hand
Take five baskets: (bread, milk), (bread, diapers, beer, eggs), (milk, diapers, beer, cola), (bread, milk, diapers, beer) and (bread, milk, diapers, cola).
Support. support(X) = fraction of baskets containing X:
- support(diapers) = 4/5 = 0.8;
- support(beer) = 0.6;
- support(beer, diapers) = 0.6.
Confidence. confidence(A → B) = support(A ∪ B)/support(A), an estimate of P(B | A):
- beer → diapers: 0.6/0.6 = 1;
- diapers → beer: 0.6/0.8 = 0.75.
Lift. lift(A → B) = confidence/support(B) = P(A, B)/(P(A)P(B)). For beer → diapers, 1/0.8 = 1.25. Lift is symmetric in A and B; 1 means independence.
Other measures.
- Leverage: P(A, B) − P(A)P(B) = 0.6 − 0.48 = 0.12.
- Conviction: (1 − P(B))/(1 − conf). For diapers → beer, (1 − 0.6)/(1 − 0.75) = 1.6; it is infinite for a rule that is never violated.
The steps in plain English (Apriori):
- Count every single item; keep those with support ≥ s.
- Join frequent k-itemsets that share k − 1 items into (k + 1)-candidates.
- Prune candidates with any infrequent k-subset, which cannot be frequent.
- Count the survivors in one scan of the data; keep the frequent ones; repeat until no candidates remain.
- For each frequent itemset, emit the rules A → (itemset − A) with confidence ≥ c, then rank by lift or another interest measure.
- 1. confidence(A → B) estimates…
- 2. A lift of 1 means…
- 3. Apriori prunes a candidate when…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.Cost, and the confidence trap
Downward closure. If X ⊆ Y then support(Y) ≤ support(X), because every basket containing Y also contains X. So all subsets of a frequent itemset are frequent, and no superset of an infrequent itemset can be frequent. That justifies Apriori’s pruning.
Cost. With d items there are 2^d − 1 possible itemsets, 1.1 × 10¹⁵ for d = 50. Apriori counts only candidates whose subsets are all frequent, but it needs one full data scan per level, and the candidate counts grow rapidly as the threshold falls. Long frequent patterns are expensive: a frequent itemset of size m has 2^m − 1 frequent subsets, all of which must be found.
The confidence trap. Confidence ignores how common B is anyway. If bread appears in 60% of baskets, then any A → bread rule has confidence about 0.6 even when A and bread are unrelated. Such rules pass a confidence threshold and fill the output with noise. Lift, leverage or conviction measure the gain over the base rate.
Exercise 1 (the five baskets, minimum support 0.6):
- 8 frequent itemsets, identical to a brute-force search over all 63 itemsets;
- only 13 candidates counted;
- beer → diapers: support 0.6, confidence 1.00, lift 1.25;
- 8 rules with confidence ≥ 0.7.
from mlxtend.frequent_patterns import apriori, association_rules
freq = apriori(onehot_df, min_support=0.02, use_colnames=True)
rules = association_rules(freq, metric="lift", min_threshold=1.2)- 1. Apriori scans the data…
- 2. A rule A → staple has high confidence mostly because…
- 3. How many frequent subsets does a frequent itemset of size 10 imply?
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Correctness. By downward closure, every frequent (k + 1)-itemset is a join of two frequent k-itemsets sharing k − 1 items, and survives pruning. So Apriori finds all frequent itemsets and nothing else.
Complexity. Counting dominates. With hash trees or tries, each scan checks each transaction against the candidates it can contain. Worst-case output size is exponential, and enumerating frequent itemsets is #P-hard in general. Practical cost depends on the data’s density and the threshold.
Interestingness and statistics.
- Lift is unstable for rare items.
- Leverage and conviction behave differently near independence.
- Fisher’s exact or χ² tests check whether a co-occurrence exceeds chance.
- With thousands of candidate rules, multiple-testing corrections (Bonferroni, false discovery rate) or holdout validation (Webb, 2007) are essential to avoid “discovering” noise.
Condensed representations. Closed itemsets (no superset with the same support) and maximal itemsets (no frequent superset) summarise the frequent set without losing support information, in the closed case, or keep only its border, in the maximal case.
Interview questions.
- Why do association rules often look obvious or useless? Confidence rewards popular consequents, and low thresholds generate thousands of redundant rules. Rank by lift or leverage, test significance, and remove rules implied by simpler ones.
- Apriori or FP-Growth? FP-Growth for large or dense data, since it avoids candidate generation and makes only two scans. Apriori is simpler and fine for sparse data with high thresholds.
- 1. A closed itemset has…
- 2. With thousands of candidate rules, significance needs…
- 3. Lift is unstable for…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Candidate explosion and noisy rules
History.
- R. Agrawal, T. Imieliński and A. Swami (1993) introduced association rule mining.
- R. Agrawal and R. Srikant (1994) introduced Apriori.
- J. Han, J. Pei and Y. Yin (2000) introduced FP-Growth.
- M. Zaki (2000) introduced Eclat.
- G. Webb (2007) introduced statistically sound rule discovery.
Exercise 2. 2000 synthetic baskets over 50 items with Zipf-like popularity. Item 0 is a staple in 60% of baskets, and three planted patterns, items (1, 7, 12), (20, 25) and (30, 33, 38), each appear together in 8% of baskets.
| minimum support | candidates counted | frequent itemsets | largest frequent size |
|---|---|---|---|
| 0.10 | 156 | 22 | 2 |
| 0.05 | 536 | 75 | 4 |
| 0.02 | 1478 | 217 | 5 |
| 0.01 | 2485 | 585 | 5 |
At support ≥ 0.02 and confidence ≥ 0.5 there were 170 rules:
-
78 had lift below 1.2;
-
79 predicted the staple item, with a mean lift of just 1.03;
-
all 3 planted patterns were found, with a mean lift of 5.54.
-
Lowering the threshold tenfold multiplied the candidate count by 16 and the frequent itemsets by 27, and every level needs another full data scan.
-
Nearly half the confident rules were the confidence trap: “X → staple” with lift about 1, carrying no information beyond the staple’s popularity.
-
Ranking by lift separated the planted associations cleanly (5.5 against 1.0). A lift or leverage filter, plus a significance test, is the minimum for usable output.
Association rules in AI, robotics and aerospace
- Maintenance logs: co-occurring fault codes and part replacements reveal cascades and common root causes, which become candidates for reliability engineering.
- Alarm flood analysis: frequent alarm combinations in control rooms and cockpits identify redundant or consequential alarms to suppress or group.
- Test and configuration mining: combinations of software modules or settings that co-occur with failures in large regression suites.
References
- R. Agrawal, R. Srikant (1994). “Fast algorithms for mining association rules.” Proc. VLDB.
- R. Agrawal, T. Imieliński, A. Swami (1993). “Mining association rules between sets of items in large databases.” Proc. ACM SIGMOD.
- P.-N. Tan, V. Kumar, J. Srivastava (2002). “Selecting the right interestingness measure for association patterns.” Proc. ACM KDD.
- G. I. Webb (2007). “Discovering significant patterns.” Machine Learning 68(1).