On Finding Similar Items in a Stream of Transactions

Andrea Campagna, Rasmus Pagh

TL;DR

This paper tackles the challenge of finding pairs of items that are "similar" (not just frequent) within a massive, fast-moving stream of transactions. While theoretical limits suggest this is nearly impossible for worst-case data, the authors demonstrate that if transactions arrive in a random order—a condition often met by real-world data—we can achieve high accuracy with very little memory.

What Problem Does This Paper Address?

In data mining, the "market basket" model usually focuses on finding frequent itemsets (items often bought together). However, frequency doesn't always equal relevance. For example, two niche items might be bought together 100% of the time but only appear in 0.1% of transactions; a frequency-based algorithm would ignore them, even though they are highly "similar" according to measures like Jaccard or Cosine similarity.

Doing this in a streaming model is incredibly difficult. You only see each transaction once, you have very little time to process it, and you don't have enough memory to store every possible pair of items. The authors first prove a "negative result": in a worst-case scenario, any algorithm would need an impractical amount of memory to find the most frequent pairs. This paper seeks a way to bypass that theoretical wall.

Methods

The authors propose a two-stage pipelined algorithm that operates in a single pass:

  1. Pair Sampling: Based on an existing algorithm called BiSam, this stage samples pairs $\{i, j\}$ from a transaction with a probability proportional to their similarity. To make this work in a stream, the authors introduce a clever "rounding" technique—sampling probabilities are rounded down to the nearest negative power of 2. This ensures that samples are independent and can be processed in "linear time with high probability," avoiding the quadratic explosion of checking every pair in a large transaction.
  2. SampleCount: This stage filters the stream of sampled pairs. It uses reservoir sampling to maintain a representative subset of pairs and then counts their occurrences in subsequent "chunks" of the stream. By weighing these counts against the sampling probability, the algorithm estimates the true similarity.

The algorithm relies on a random-order assumption. Instead of assuming the data is adversarial, it assumes transactions are presented in a random permutation. This allows the algorithm to use item frequencies from the first half of a stream prefix to accurately predict sampling probabilities for the second half.

Datasets

The authors evaluated the characteristics of several well-known datasets from the FIMI (Frequent Itemset Mining Implementations) repository to see if they behave like "random order" data:

  • Accidents: Traffic accident data.
  • BMS-POS & BMS-Webview1: Point-of-sale and web clickstream data.
  • Pumsb: Census data.
  • Retail: Retail transaction data.
  • T40I10D100K: A standard synthetic benchmark.

Key Insights and Ideas

  • Frequency $\neq$ Similarity: The authors provide a clear example where a pair appearing in 10% of transactions is actually less similar (using Cosine similarity) than a pair appearing in only 5%. This motivates the need for similarity-specific streaming algorithms.
  • Bypassing the Lower Bound: The "Aha!" moment is realizing that while the problem is impossible for any stream, it is solvable for randomly ordered streams.
  • Self-Improving Accuracy: Surprisingly, the algorithm’s accuracy actually improves as the stream gets longer. As more data arrives, the estimates of individual item frequencies become more stable, leading to better sampling and more precise similarity calculations.
  • Real Data is "Random Enough": By plotting the distribution of items in the first vs. second halves of real-world datasets, the authors show that real data often naturally approximates a random distribution, making their theoretical model applicable to practice.

Key Results

  • Theoretical Bound: The paper proves that for worst-case streams, you essentially need enough space to store the entire stream or a count for every possible pair to find the most frequent $k$-itemsets.
  • Streaming Performance: The proposed algorithm uses $O(n + s)$ space, where $n$ is the number of distinct items and $s$ is the number of pairs we wish to track. This is a massive improvement over the $O(n^2)$ space required by naive approaches.
  • Time Complexity: Transactions are processed in $O(mb \log(nm))$ time, meaning the time per item is nearly constant, making it suitable for high-speed streams.

Limitations and Future Work

  • The Random Order Assumption: While the authors show this holds for many datasets, the algorithm might fail or lose significant accuracy on "adversarial" streams where similar items are intentionally clustered at the very beginning or end.
  • Experimental Validation: While the paper provides strong theoretical proofs and analyzes dataset characteristics, it lacks a full-scale experimental comparison of the algorithm's actual precision/recall against other streaming methods. The authors note that a "thorough experimental study... remains to be carried out."
  • Extension of Lower Bounds: An open question remains: can the negative results (lower bounds) be extended to the random-order model, or is the current algorithm already near-optimal?

Summary updated

BibTeX
@inproceedings{campagna2010finding,
  author = {Andrea Campagna and Rasmus Pagh},
  title = {{On Finding Similar Items in a Stream of Transactions}},
  booktitle = {Workshops @ ICDM},
  year = {2010},
  doi = {10.1109/icdmw.2010.152},
}
Figure