✍ 06: Frequent Pattern Mining — Exercise¶
Tip
Practice — try each question first, then expand the answer to check your reasoning. This case study mines the Epub dataset (R's arules package): 15,729 sessions, 936 unique documents, each transaction being the set of documents downloaded in one session.
📊 Q1. Mining at support thresholds 0.001, 0.005, and 0.01 produced 561, 67, and 19 frequent itemsets respectively. Why does raising the support threshold shrink the itemset count so quickly?¶
Show answer
Support = (transactions containing the itemset) / (total transactions). With 15,729 sessions and 936 documents, most document combinations are downloaded together only a handful of times — the dataset is **sparse**. Raising the minimum support threshold prunes out every itemset that doesn't clear that bar, and because popularity is so skewed (a few documents dominate, most are rare), even a small threshold increase eliminates the long tail of rare combinations. This matches the anti-monotone (downward-closure) property: if an itemset doesn't meet minimum support, none of its supersets can either.🔗 Q2. Mining association rules at (support, confidence) = (0.001, 0.3), (0.001, 0.5), (0.001, 0.7), and at support 0.005 or 0.01 for any confidence, produced 30, 13, 4, 0, and 0 rules. What does this tell you about the relationship between confidence and rule count, and between support and rule count?¶
Show answer
- **Confidence vs. rule count** (support fixed at 0.001): 30 → 13 → 4 as confidence rises 0.3 → 0.5 → 0.7. Higher confidence is a stricter requirement (rule must hold true more often), so fewer rules survive — but the ones that do are more reliable. - **Support vs. rule count**: at support 0.005 or 0.01, **zero** rules survive at any confidence. Association rule mining requires the underlying itemset to already be frequent enough to generate a rule from; since so few itemsets clear 0.005+ support (only 67 and 19 respectively, from Q1), there's little left to build multi-item rules from. Together this shows a classic tradeoff: low support + low confidence = many rules (including noise); higher thresholds trade quantity for reliability, but too high a threshold here loses everything.📈 Q3. The strongest rules found were {doc_6e7, doc_6e8} → {doc_6e9} (confidence 0.81, lift 454.75), {doc_6e7, doc_6e9} → {doc_6e8} (confidence 0.85, lift 417.80), and {doc_6e8, doc_6e9} → {doc_6e7} (confidence 0.89, lift 402.09). Why does a lift over 400 matter more here than the confidence values?¶
Show answer
**Lift** = confidence / P(consequent) = how much more likely the consequent is *given* the antecedent, compared to its baseline popularity. A lift of ~400+ means these three documents co-occur **hundreds of times more often** than random chance would predict — an extremely strong, almost certainly non-coincidental relationship (e.g., a multi-part document or a tightly bundled reading set). Confidence alone (0.81–0.89) sounds good but doesn't rule out the possibility that the consequent is just a generally popular document; lift is what confirms the relationship is specific to that antecedent, not just general popularity.💡 Q4. In R, how would you generate frequent itemsets across three support thresholds and association rules across three support/confidence combinations, then find the top rules by lift?¶
Show answer
library(arules)
data("Epub")
support_values <- c(0.001, 0.005, 0.01)
for (supp in support_values) {
itemsets <- apriori(Epub, parameter = list(supp = supp, target = "frequent itemsets"))
print(paste("Support:", supp, "-> itemsets:", length(itemsets)))
}
confidence_values <- c(0.3, 0.5, 0.7)
all_rules <- list()
for (supp in support_values) {
for (conf in confidence_values) {
rules <- apriori(Epub, parameter = list(supp = supp, conf = conf, minlen = 2))
all_rules[[paste0("supp_", supp, "_conf_", conf)]] <- rules
}
}
best <- all_rules[["supp_0.001_conf_0.3"]]
inspect(head(sort(best, by = "lift"), 10))
📚 All Exercises · Next: Chapter 07 — Classification ➡️