Stratified Sampling Meets Machine Learning

Edo Liberty, Kevin J. Lang, Konstantin ShmakovICML 2016

This paper offers a clever bridge between classical statistics and modern machine learning. It tackles a fundamental database problem—how to sample data to answer aggregate queries accurately—by reframing it as a supervised learning task.

TL;DR

The authors replace manual, "artistic" stratified sampling with an automated machine learning approach. By treating historical query logs as training data, they learn optimal sampling probabilities for individual records, reducing estimation error by up to 50% compared to industry-standard uniform sampling.

What Problem Does This Paper Address?

When dealing with massive databases (like Yahoo’s user action logs), performing a full linear scan to answer a query like "How many users in New York clicked this ad?" is often too slow and expensive. The standard solution is sampling: evaluate the query on a small subset of the data and scale the result up.

The challenge lies in how to sample.

  1. Uniform Sampling is the "safe" default, but it's often inaccurate for "hard" queries (those that match only a few records).
  2. Stratified Sampling (Neyman Allocation) can be much more accurate, but it requires a human expert to manually group records into "strata" (e.g., by age or location). If you pick the wrong strata, your accuracy plummets.

The authors ask: Can we automate this? Can we look at a log of past queries and automatically learn the best sampling probability for every single record in the database?

Methods

The authors frame sampling as a Probably Approximately Correct (PAC) learning problem. They assume that past queries (the training set) and future queries (the test set) are drawn from the same underlying distribution.

The ERM Approach

They use Empirical Risk Minimization (ERM) to find a vector of sampling probabilities $p$ that minimizes the expected squared error of the queries in the log.

  • The Objective: Minimize the variance of the Horvitz-Thompson estimator (a standard way to scale up sample results).
  • The Constraint: The "budget" $B$ (the total number of records or disk space allowed for the sample).

The Algorithm

The authors derive a simple, one-pass algorithm. It calculates a "sensitivity" score $z_i$ for each record $i$ based on how often and how strongly it contributed to queries in the log. The optimal probability for a record is essentially proportional to this score ($p_i \propto z_i$).

Regularization

A key contribution is the introduction of regularization. Without it, the algorithm would assign a probability of zero to any record that didn't appear in the training log. If a future query hits those records, the error becomes infinite. The authors solve this by enforcing a "probability floor" (controlled by a parameter $\eta$), ensuring every record has at least a small chance of being sampled.

Expected error vs. regularization parameter across datasets.

Datasets

The authors evaluated their approach on three distinct datasets:

  1. Cube Dataset: A synthetic 5-dimensional dataset used to test the algorithm in a controlled environment where the "ground truth" structure is known.
  2. DBLP Dataset: A real-world dataset of 2.1 million academic papers. They generated synthetic queries based on common search patterns.
  3. YAM+ Dataset: A massive, real-world advertising dataset from Yahoo consisting of 60 million users and 1.6 billion values, using actual queries issued by campaign managers.

Key Insights and Ideas

  • Sampling as Regression: The most profound insight is that assigning sampling probabilities is just a specialized regression problem where the loss is inversely proportional to the values being regressed.
  • The "No Free Lunch" Trade-off: The algorithm works by "stealing" sampling probability from "easy" queries (those that match many records and already have low relative error) and giving it to "hard" queries (low cardinality). This increases the error on easy queries slightly but dramatically improves the overall system accuracy.
  • Automation beats Intuition: The ML approach outperformed manual stratification. In the DBLP and YAM+ datasets, standard Neyman allocation actually performed worse than uniform sampling because the human-chosen strata didn't align well with the actual query patterns. The ERM approach found the "hidden" strata automatically.

Key Results

  • Significant Error Reduction: On the real-world YAM+ dataset, the regularized ERM approach reduced the average expected squared error by 40% to 50% compared to uniform sampling.
  • Generalization: The models showed classic ML behavior—more training queries led to better performance on the test set, proving that query patterns are indeed learnable.
  • Robustness: Even with small training sets, the regularized version of the algorithm was "safe," never performing significantly worse than uniform sampling, while the unregularized version failed due to overfitting.
Expected error vs. query cardinality.

Limitations and Future Work

  • The I.I.D. Assumption: The paper assumes the distribution of queries is stationary (doesn't change over time). In the real world, query trends shift. The authors suggest Online Convex Optimization as a potential future direction to handle drifting distributions.
  • Computational Overhead: While the algorithm is a "one-pass" approach, it still requires a full scan of the query log against the database to compute the sensitivity scores. For truly massive logs, this could be a bottleneck.
  • Complex Loss Functions: The paper focuses on squared loss. The authors note that other loss functions (like absolute error) are harder to optimize because they aren't convex in this specific formulation, leaving room for more complex optimization research.

Summary updated

BibTeX
@inproceedings{liberty2016stratified,
  author = {Edo Liberty and Kevin J. Lang and Konstantin Shmakov},
  title = {{Stratified Sampling Meets Machine Learning}},
  booktitle = {International Conference on Machine Learning},
  year = {2016},
}
Figure