liveBook · Manning

Apriori algorithm

As explained in Data Without Labels

Apriori is an association-rule-mining algorithm that discovers frequent itemsets by generating candidates level by level and pruning them using the downward-closure property of support.

Apriori discovers useful relationships among items in transactional data, supporting market-basket analysis for product placement, marketing, and pricing decisions. section 4.11

It searches bottom-up: generate frequent itemset candidates at one level, calculate their support, then expand surviving combinations until all items are exhausted. Rules separate antecedents from consequents, such as {bread} -> {milk}. section 4.4

A practical Python workflow includes:

  • Load the transaction CSV with pandas, inspect .info() and .head(), and correct accidental header handling with header=None. section 4.4.1
  • Convert the dataframe into a list of lists because the Apriori implementation expects one inner list per transaction. section 4.4.1
  • Run apyori with minimum support, confidence, lift, and rule-length thresholds; convert the result to a list for inspection. section 4.4.1
  • Print item pairs alongside support, confidence, and lift to interpret the generated rules. section 4.4.1

Bread, milk, eggs, and cheese

Starting with bread at level 1, Apriori evaluates {bread, milk}, {bread, eggs}, and {bread, cheese}, then larger combinations such as {bread, eggs, milk} -> {cheese}. section 4.4

Threshold tuning

On the store dataset, minimum support values of 50%, 25%, and 10% with minimum lift 4 produce no rules; lowering minimum lift to 2 produces 200 rules. section 4.4.1

Apriori can become slow and memory-intensive because it generates many candidate subsets and scans the database repeatedly. Minimum support limits candidate growth, while ECLAT and FP-growth offer alternative frequent-itemset strategies. section 4.4.2

How Data Without Labels covers it

How deep it goes
Walks through layered candidate generation and Python execution, but defers detailed algorithmic optimization and large-scale handling.
Examples
Uses bread, milk, eggs, and cheese combinations plus a store CSV to demonstrate support, thresholds, and printed rules.
What it assumes
Assumes transactional rows and basic pandas handling while teaching data reshaping and association-rule metrics through the workflow.
What you can do after
Apply it via the apyori library to prepare transactions, tune thresholds, and inspect support, confidence, and lift.
How it connects
Connects association rules with support, confidence, lift, conviction, ECLAT, FP-growth, and sequence rule mining.

Also explained in

Compare how 2 books explain Apriori algorithm →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Without Labels. The section links point to the parts of the book it draws on.