Abstract
Data valuation using the Shapley value is a powerful tool for assessing data quality, but its computational complexity often makes it impractical for large datasets. While efficient algorithms exist for unweighted K-Nearest Neighbors (KNN), the more expressive Weighted KNN (WKNN) has remained computationally expensive ($O(N^K)$). This paper introduces a novel quadratic-time algorithm ($O(N^2)$) for exact WKNN-Shapley computation by leveraging dynamic programming and discretized weights. Our approach achieves speedups of up to $10^6\times$ over existing baselines, enabling practical data valuation on large-scale datasets while preserving key fairness axioms.
Introduction
In modern machine learning, the quality of training data is as critical as the model architecture. Data valuation aims to quantify the contribution of individual data points to a model's performance, facilitating tasks like dataset cleaning, model debugging, and fair data compensation. The Shapley value, derived from cooperative game theory, is considered the gold standard for this purpose because it fairly distributes "profit" (model accuracy) among "players" (data points) based on their marginal contributions.
However, calculating exact Shapley values is generally NP-hard ($O(2^N)$). While the unweighted KNN-Shapley can be computed in $O(N \log N)$, it fails to account for the varying distances of neighbors. Weighted KNN (WKNN) is more powerful but has been computationally impractical, with previous state-of-the-art algorithms requiring $O(N^K)$ time. For a dataset of $N=100,000$ and $K=5$, this complexity is prohibitive.
Methodology
The authors propose a significant leap in efficiency by reframing the WKNN-Shapley calculation through two primary innovations:
Shapley-friendly Configurations
The complexity of previous WKNN-Shapley methods often stemmed from continuous weights and soft-label outputs. This paper simplifies the utility function by adopting hard-label KNN (outputting a discrete class) and discretized weights (rounding weights to a finite number of bits). Crucially, the authors prove that discretizing weights preserves the ranking order of data values, ensuring that the most influential points remain correctly identified.
Dynamic Programming for Counting
By using hard labels and discrete weights, the Shapley calculation is transformed into a counting problem: determining in how many subsets of the data adding a specific point $z_i$ flips the majority vote for a validation point.
The authors develop a Dynamic Programming (DP) algorithm that computes these counts in $O(N^2)$ time. To further enhance performance, they introduce a deterministic subquadratic approximation ($O(N^{1.5})$) that ignores distant neighbors. Unlike stochastic Monte Carlo methods, this approximation is guaranteed to preserve fundamental fairness properties like the "null player" and "symmetry" axioms.
Experimental Setup
The proposed algorithms were evaluated across 13 benchmark datasets, including:
- Tabular/Binary: Click, Fraud, Creditcard, Apsfail, Phoneme, Wind, Pol, CPU, 2DPlanes.
- Image: MNIST and CIFAR10 (using ResNet50 embeddings).
- Text: AGNews and DBPedia (using Sentence-BERT embeddings).
Key Results
The primary achievement of this work is the massive reduction in computational overhead. On a dataset with $10^5$ points, the new exact algorithm is nearly one million times faster than the previous $O(N^K)$ baseline.
Beyond speed, WKNN-Shapley demonstrates superior performance in practical applications:
- Data Cleaning: In mislabeled data detection tasks, WKNN-Shapley consistently outperformed unweighted KNN-Shapley. It is particularly effective at identifying "sneaky" mislabeled points near decision boundaries that unweighted versions might miss.
- Stability: WKNN-Shapley is robust to the choice of $K$. While unweighted KNN performance often degrades as $K$ increases due to the inclusion of irrelevant neighbors, the weighted version remains stable because distant neighbors are naturally down-weighted.
Conclusion and Future Work
This work makes weighted nearest-neighbor data valuation feasible for large-scale applications for the first time. While the $O(N^2)$ efficiency relies on hard-label assumptions, it provides a robust framework for high-quality data valuation. Future research may explore extending these efficient DP-based approaches to more complex models like Neural Networks or Gradient Boosted Trees, and further optimizing the initial sorting steps required in high-dimensional spaces.
Summary updated