Abstract
Data valuation is essential for dataset cleaning and fair compensation, with the Shapley value serving as the gold standard for fair attribution. However, computing exact Shapley values for Weighted K-Nearest Neighbors (WKNN) has historically been computationally prohibitive, requiring $O(N^K)$ time. This paper introduces the first quadratic-time algorithm ($O(N^2)$) for computing exact WKNN-Shapley values. By employing weight discretization and dynamic programming, the authors achieve a $10^6\times$ speedup over previous baselines. Furthermore, a sub-quadratic deterministic approximation is proposed that preserves key fairness axioms.
Introduction
In machine learning, the quality of training data directly dictates model performance. Data valuation aims to quantify the contribution of individual training points, enabling tasks such as mislabeled data detection and fair data marketplaces. While the Shapley value provides a theoretically sound framework for this valuation, its exponential complexity ($O(2^N)$) usually necessitates approximations.
For the K-Nearest Neighbors (KNN) algorithm, exact Shapley values can be computed efficiently in $O(N \log N)$ time. However, the more practical Weighted KNN (WKNN)—which weights neighbors based on their proximity to the query point—remained computationally intractable with a baseline complexity of $O(N^K)$. This paper addresses this bottleneck, making high-quality data valuation practical for large-scale datasets.
Methodology: Scaling WKNN-Shapley
The authors transform the WKNN-Shapley calculation into a tractable "Shapley-friendly" problem through two primary innovations:
- Hard-label Classifiers: By focusing on classifiers that output discrete class labels rather than probability vectors, the authors eliminate complex normalization terms in the utility function.
- Weight Discretization: The authors demonstrate that rounding continuous weights to a small number of bits (e.g., 3 bits) preserves the ranking order of data values while significantly simplifying the underlying mathematics.
These modifications allow the Shapley calculation to be reframed as a counting problem solvable via Dynamic Programming (DP). The resulting exact algorithm operates in $O(N^2)$ time. For even larger datasets, a deterministic approximation with $O(N^{1.5})$ complexity is introduced. Unlike stochastic Monte Carlo methods, this deterministic approach ensures that identical data points receive identical values (symmetry) and useless data receives zero value (null player), maintaining the core fairness of the Shapley framework.
Experimental Evaluation
The proposed algorithms were evaluated across 13 benchmark datasets, including tabular data (e.g., Fraud, Creditcard), image data (MNIST, CIFAR10), and text data (AGNews, DBPedia).
Key Results
- Efficiency: On a dataset of $N=10^5$, the new algorithm is approximately one million times faster than previous exact methods.
- Data Cleaning: WKNN-Shapley significantly outperforms unweighted KNN-Shapley in identifying noisy or mislabeled data. For instance, on the "Fraud" dataset, the AUROC for detecting mislabeled points improved from 0.55 (unweighted) to 0.75 (weighted).
- Robustness: WKNN-Shapley exhibits superior stability relative to the choice of $K$. While unweighted KNN performance often degrades as $K$ increases, the weighted version remains stable because distant neighbors are naturally down-weighted by the proximity-based weights.
Discussion and Future Work
While WKNN-Shapley serves as an efficient proxy for data valuation, its assigned values may not perfectly correlate with a point's impact on complex deep neural networks. However, the authors demonstrate its empirical effectiveness in data selection tasks. Future research may explore applying similar "Shapley-friendly" modifications to other learning algorithms to achieve polynomial-time data valuation across a broader range of models.
Summary updated