TL;DR
This paper introduces "Learning to Sample" (LSS), a hybrid approach for estimating counts in databases with complex, expensive-to-evaluate queries. By using a machine learning classifier to guide a stratified sampling process, the authors achieve the high efficiency of ML while maintaining the rigorous, unbiased statistical guarantees of traditional sampling.
What Problem Does This Paper Address?
In modern data science, we often need to count objects that satisfy complex conditions—think of user-defined functions (UDFs), self-joins, or deeply nested subqueries. For example, "How many points in this dataset have fewer than $k$ neighbors within distance $d$?"
Standard database techniques struggle here:
- Full Evaluation: Too slow. A self-join on a large table is computationally brutal.
- Simple Random Sampling (SRS): Often requires too many samples to reach a tight confidence interval, especially if the "positive" results are rare.
- Pure Machine Learning: You could train a classifier to predict the predicate and just count its "1"s. However, ML models are biased, prone to overfitting, and—crucially—don't provide the statistical confidence intervals that data scientists rely on.
The authors seek a "best of both worlds" solution: the speed of ML and the mathematical rigor of sampling.
Methods
The authors propose a two-phase framework:
Phase 1: Learning. A small portion of the sampling budget is used to "label" data (evaluate the expensive predicate). This data trains a probabilistic classifier (like a Random Forest or Neural Network). The classifier doesn't need to be perfect; it just needs to provide a "score" representing the likelihood that an object satisfies the query.
Phase 2: Sampling. Instead of using the classifier's predictions as the final answer, the authors use the scores to design an optimized sampling scheme. They propose two main methods:
- Learned Weighted Sampling (LWS): Objects with higher classifier scores are sampled with higher probability.
- Learned Stratified Sampling (LSS): This is the paper's primary contribution. The scores are used to sort all objects. The algorithm then partitions these objects into "strata" (groups) and decides how many samples to take from each.
The core technical challenge is Optimizing the Stratification. The authors developed several algorithms—DirSol (for 3 strata), LogBdr, and DynPgm (a dynamic programming approach)—to find the optimal boundaries between strata that minimize the variance of the final estimate.
Datasets
The authors evaluated their approach on three diverse real-world scenarios and several synthetic ones:
- Sports: MLB pitching statistics used for "k-skyband" queries (finding points dominated by fewer than $k$ others).
- Neighbors: The KDD Cup 1999 dataset, used for "neighborhood" queries common in intrusion detection.
- Text: 2.4 million Wikipedia documents (LSHTC dataset) where the predicate involves a complex black-box function for document categorization.
- Synthetic: Noise-injected versions of the Sports dataset used to test how the system handles "bad" or "noisy" classifiers.
Key Insights and Ideas
- Robustness through Ordering: The "aha moment" of LSS is that it doesn't rely on the exact values of the classifier scores, only their relative ordering. If a classifier is slightly off but still generally ranks likely-positive objects higher than negative ones, LSS still performs beautifully.
- Unbiased by Design: Because the final count comes from a sampling formula (like the Horvitz-Thompson or Neyman allocation), the estimate is mathematically guaranteed to be unbiased. Even if the ML model is terrible, the answer will eventually converge to the truth—it just might take more samples.
- Negligible Overhead: The time spent training the model and running the optimization algorithms is miniscule (often <0.2% of total time) compared to the cost of evaluating the expensive query predicates.
- ML as a "Surrogate": Traditional stratified sampling uses simple attributes (like X-Y coordinates) to group data. LSS effectively uses the ML model as a "super-attribute" that captures the complex logic of the query itself.
Key Results
- Superior Accuracy: LSS consistently achieved lower Mean Absolute Error (MAE) than Simple Random Sampling and standard Stratified Sampling across all datasets.
- Resilience to Poor Models: In the "Text" dataset, where classification is notoriously difficult, pure ML approaches failed miserably. LSS, however, recognized the model's uncertainty and "degenerated" into something similar to random sampling, maintaining accuracy where pure ML produced wildly skewed results.
- Variance Reduction: In the "Sports" dataset, LSS provided much tighter confidence intervals (lower variance) compared to baselines, meaning you need fewer samples to get a trustworthy answer.
- Efficiency: LSS outperformed "SampleClean" style methods (which use sampling only to correct ML errors) because LSS uses the ML model to actively target the most informative samples.
Limitations and Future Work
- Enumeration Cost: The method assumes that you can efficiently enumerate or scan the objects you are counting. If the "candidate set" is itself massive and hard to define, the overhead of scoring every object with the ML model might become a bottleneck.
- Sample Reuse: Currently, the authors use separate samples for the "Learning" and "Sampling" phases to ensure independence. They suggest that "safe reuse" of samples from the learning phase is a promising area for future optimization.
- Online Aggregation: The authors point toward extending this to "online aggregation," where the estimate is updated continuously as the user watches, providing a "progress bar" with shrinking confidence intervals.
Summary updated