Scalable Analytics: Chapter 3
Association Rule Discovery and the Market-Basket Model
Goal of Supermarket Shelf Management: To identify items that are purchased together by a sufficiently large number of customers to optimize product placement and inventory.
Methodology: Sales data collected via barcode scanners is processed to find dependencies among various items.
The Market-Basket Model Components:
Items: A large set of distinct products (e.g., milk, coke, bread).
Baskets: A large set of transactions, where each basket is a small subset of the total item set.
Input Example Table:
TID 1: {Bread, Coke, Milk}
TID 2: {Beer, Bread}
TID 3: {Beer, Coke, Diaper, Milk}
TID 4: {Beer, Bread, Diaper, Milk}
TID 5: {Coke, Diaper, Milk}
Output Association Rule Examples:
Broad Applications of Large-Scale Analytics
Market Baskets: Large chain stores maintain terabytes (TB) of data regarding customer purchasing habits.
Plagiarism Detection:
Items: Sentences.
Baskets: Documents containing those specific sentences.
Medical Research:
Items: Prescription drugs and observed side effects.
Baskets: Patients.
Goal: Identifying side-effect patterns occurring across different patients.
Abstract Mapping: Frequent itemset mining describes a general many-to-many mapping or association between two distinct categories of data.
Defining Frequent Itemsets and Association Rules
Frequent Itemsets: The simplest analytical question is identifying sets of items that appear together in baskets frequently.
Support: The support for itemset is the specific number of baskets that contain all items in .
Support Threshold (): A user-defined value. Itemsets that appear in at least baskets are classified as frequent itemsets.
Example: In a data set where {Beer, Bread} appear in TID 2 and TID 4, the support of {Beer, Bread} is .
Association Rule Format: An "if-then" rule regarding basket contents, represented as .
Confidence Calculation: The probability of item being in a basket given that the set of items is present.
Interesting Association Rules: Not all high-confidence rules provide useful information. The "Interest" of a rule is the difference between its confidence and the overall probability of item occurring in any basket regardless of context.
Calculated Example:
Baskets: 8 total ( to ). Coke () appears in 5 out of 8 baskets ().
Rule: .
If support for is and support for is , then .
.
Computational Implementation of Association Rule Mining
Primary Problem: Finding all rules with support and confidence . The most computationally intensive part is finding the frequent itemsets themselves.
Steps for Mining:
Step 1: Find all frequent itemsets .
Step 2: Rule generation. For every subset of a frequent itemset , generate a rule .
Rule Generation Observations:
If is frequent, its subset is also frequent.
If a rule is below the confidence threshold, any rule with a smaller subset as the antecedent (e.g., ) will also be below confidence.
The Computational Model and Memory Bottlenecks
Data Storage: Data is typically stored in flat files on a disk, organized basket-by-basket. Baskets are generally small, but the total number of items and baskets is massive.
True Cost Metric: The cost of mining disk-resident data is measured by the number of disk I/O operations (passes over the data), where a pass involves reading all baskets in order.
Main-Memory Constraint: Main memory is the critical resource. As baskets are read, counts must be stored in memory. Swapping counts in and out of disk is extremely inefficient and should be avoided.
Techniques for Counting Pairs in Memory
The Problem of Pairs: Finding frequent pairs is often the hardest stage of the process.
Naive Approach: Count all pairs once in main memory. This fails if the number of items results in pairs that exceed memory capacity.
Method 1: Triangular Matrix:
Used only if items are ordered i < j.
Counts are kept in lexicographical order:
Formula for the position of pair : .
Requires bytes per pair. Total bytes required is approximately .
Method 2: Triples/Dictionary:
Stores data as where is the count.
Requires bytes per occurring pair. This is more efficient only if the data is sparse (few pairs actually appear).
The A-Priori Algorithm
Key Principle: Monotonicity: If an itemset appears at least times, every subset of must also appear at least times.
Contrapositive: If an item does not appear at least times, then no pair or larger set involving can be frequent.
Two-Pass Approach:
Pass 1: Read baskets and count occurrences of individual items. Identify "frequent items" that meet the threshold .
Pass 2: Read baskets again, but only count pairs where both items were identified as frequent in Pass 1. This significantly reduces the memory needed to store pair counts.
Frequent k-tuples Procedure:
= Candidate k-tuples (potential frequent sets based on information from the pass).
= Truly frequent k-tuples (sets verified as satisfying support after a pass).
For market-basket data with a support threshold, the pass usually requires the most memory.
The PCY (Park-Chen-Yu) Algorithm
Observation: During Pass 1 of the A-Priori algorithm, substantial memory remains idle while only individual items are being counted.
PCY Pass 1:
Maintains item counts.
Simultaneously maintains a hash table using remaining memory. Every pair of items in a basket is hashed to a bucket, and the count for that bucket is incremented.
Refining Buckets:
A bucket is "frequent" if its total count is .
If a pair is frequent, the bucket it hashes to must be frequent.
If a bucket is not frequent, none of the pairs inside it can be frequent.
PCY Pass 2:
Replace the hash table buckets with a bit-vector (bitmap). A bit is if the bucket was frequent, and otherwise.
Only count a pair if:
Both and are frequent items (A-Priori condition).
The pair hashes to a frequent bucket (Bit-vector value is ).
Frequent Itemsets in Fewer Than Two Passes
Standard algorithms take passes to find itemsets of size . Certain methods aim for two or fewer passes for all sizes, though they may miss some results.
Random Sampling:
Takes a random sample of baskets and runs the algorithm in main memory.
Support threshold is reduced proportionally to the sample size.
Verification can be done in a second pass to avoid false positives, though false negatives (missing items frequent in the whole but not the sample) may remain.
SON (Savasere, Omiecinski, and Navathe) Algorithm:
Repeatedly reads small subsets of baskets into memory and identifies frequent itemsets within each subset.
An itemset is a "candidate" for the full data set if it is frequent in at least one subset.
Monotonicity Idea: An itemset cannot be frequent in the whole unless it is frequent in at least one subset.
Distributed Version: Can be implemented via MapReduce; each node computes local frequent itemsets and then candidates are distributed and counted across all nodes.
Toivonen’s Algorithm:
Pass 1: Run a random sample with a slightly lowered threshold. Find frequent itemsets in the sample.
Negative Border Concept: Add the negative border to the candidate list. An itemset is in the negative border if it is not frequent in the sample, but all of its immediate subsets are frequent in the sample.
Pass 2: Count all candidates and the negative border in the full data.
Theorem: If any itemset is frequent in the full data but missed by the sample, at least one itemset in the negative border must be frequent in the full data. If no itemset in the negative border is frequent in the full data, the algorithm is guaranteed to have found all frequent itemsets.