Apriori Algorithm

The foundational algorithm for discovering frequent itemsets and association rules in transaction data.

The Apriori Algorithm is the foundational algorithm for Market Basket Analysis, designed to efficiently discover frequent itemsets and generate association rules from large transactional datasets.

The key insight — the Apriori principle: If an itemset is infrequent, all its supersets must also be infrequent. This means if {Cap} doesn't meet the minimum support threshold, you don't need to check {Cap, T-Shirt}, {Cap, T-Shirt, Sunglasses}, etc. This pruning step makes the algorithm practical on real-world data.

How it works

  1. Pass 1: Count individual item frequencies and filter by minimum support
  2. Pass 2: Generate candidate pairs from frequent items, count, and filter
  3. Pass 3: Generate candidate triples from frequent pairs, count, and filter
  4. Continue until no more frequent itemsets are found
  5. Generate rules: From each frequent itemset, create association rules that meet the minimum confidence threshold

Limitations and alternatives

The Apriori algorithm requires multiple passes over the data and can generate a large number of candidate itemsets. For large-scale e-commerce datasets, alternatives like FP-Growth (which compresses the database into a tree structure) can be significantly faster. However, Apriori remains widely used due to its simplicity and interpretability.

See Apriori Algorithm working on your data.

Affinsy turns these analytics concepts into actionable insights for your store, no data-science degree required.