NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Efficient Task-Specific Data Valuation for Nearest Neighbor Algorithms

Ruoxi Jia, David Dao, Boxin Wang, Frances Ann Hubis, Nezihe Merve Gürel, Bo Li, Ce Zhang, Costas J. Spanos, Dawn Song

Abstract

Valuing individual data points in machine learning is notoriously slow, typically requiring exponential time to compute Shapley values. This paper introduces a breakthrough for K-Nearest Neighbor (KNN) models, reducing exact Shapley value computation from exponential to $O(N \log N)$ time, and even achieving sublinear time using approximations. This makes fair, task-specific data valuation practical for datasets with millions of records.

Introduction: The Challenge of Data Valuation

As data becomes commoditized, a major challenge arises: if a machine learning model is trained on a dataset crowdsourced from thousands of individuals, how do we fairly distribute the revenue generated by that model back to the data contributors?

The workflow of data valuation and profit allocation between data contributors, the ML model, and the buyer.

The gold standard for fair revenue allocation in cooperative game theory is the Shapley value (SV). It measures the marginal contribution of a single data point across all possible subsets of the training data. Unfortunately, computing the exact SV requires $O(2^N)$ model evaluations, where $N$ is the number of data points. Even state-of-the-art Monte Carlo approximations require $O(N \log N)$ model retrainings, which is computationally prohibitive for modern, large-scale datasets. The authors tackle this bottleneck by asking if we can bypass this exponential complexity for specific, widely-used ML models.

Methodology: Exploiting Locality in KNN

The authors focus on K-Nearest Neighbors (KNN) algorithms. Because KNN predictions rely entirely on local data points, the authors exploit this locality to drastically speed up SV computation.

Exact Computation via Piecewise Utility

The authors mathematically prove that for unweighted KNN classifiers and regressors, the difference in marginal contribution between two data points has a "piecewise" form. This insight reduces the combinatorial explosion of evaluating every subset into a simple counting problem. The result is an algorithm that computes the exact Shapley value for all $N$ points in just $O(N \log N)$ time—essentially the time it takes to sort the dataset.

Sublinear Approximation via LSH

For even larger datasets where sorting is too slow, they introduce an approximation algorithm using Locality Sensitive Hashing (LSH). By realizing that only the top $O(1/\epsilon)$ nearest neighbors significantly impact the SV (where $\epsilon$ is the error tolerance), LSH can find these neighbors in sublinear time, avoiding the need to scan the whole dataset.

Improved Monte Carlo (MC) for Complex Variants

For extensions like weighted KNN or scenarios where one curator provides multiple data points, the exact algorithm degrades to $O(N^K)$ time. To handle this, the authors propose an improved MC approximation that uses Bennett's inequality (which relies on variance) rather than the standard Hoeffding's inequality (which relies on range), resulting in much tighter bounds and faster convergence.

Experimental Results and Insights

The authors evaluated their algorithms on several benchmark image datasets, including MNIST, CIFAR-10, and a 10-million image subset of the Yahoo Flickr Creative Commons 100M dataset.

Comparison of computational complexity for exact and approximate Shapley value computation across different baselines and KNN variants.

Key Performance Gains

  • Massive Speedups: The proposed exact algorithm is up to three orders of magnitude (1000x) faster than the baseline Monte Carlo approximation, while providing zero-error, exact Shapley values.
  • LSH Scalability: On the massive 10-million point Yahoo dataset, the LSH-based approximation provided an additional 4.6x speedup over their already-fast exact algorithm.
  • Better MC Sampling: For weighted KNN, the improved Monte Carlo method based on Bennett's inequality was more than 2x faster than the baseline Hoeffding-based method for datasets over 1 million points.

Strategic Insights

  • Locality as a Computational Advantage: The utility of a data point in KNN only matters if it falls within the top-$K$ nearest neighbors of a test point. This structural sparsity is what allows the exponential-to-linear time reduction.
  • Valuing the "Analyst": The paper introduces a "composite game" framework that assigns a Shapley value to the data analyst alongside contributors. This naturally incentivizes analysts to build better models, as their share of the value scales with total model utility.

Conclusion and Future Work

While the exact $O(N \log N)$ algorithm is currently limited to unweighted KNN, it provides a powerful foundation for fair data markets. Future work aims to integrate these algorithms into real-world, blockchain-backed clinical data markets and explore efficient data valuation for other popular models like gradient boosting and deep neural networks.

Summary updated

BibTeX
@article{jia2019efficient,
  author = {Ruoxi Jia and David Dao and Boxin Wang and Frances Ann Hubis and Nezihe Merve Gürel and Bo Li and Ce Zhang and Costas J. Spanos and Dawn Song},
  title = {{Efficient Task-Specific Data Valuation for Nearest Neighbor Algorithms}},
  journal = {Proc. VLDB Endow.},
  year = {2019},
  url = {https://openreview.net/forum?id=tIZ0u9zRxFb},
}
Figure