Introduction
Adversarial examples—small, often imperceptible perturbations designed to mislead classifiers—have predominantly been studied within the context of deep neural networks. However, the vulnerability to such attacks is not exclusive to parametric models. In "Analyzing the Robustness of Nearest Neighbors to Adversarial Examples," Yizhen Wang and colleagues provide a rigorous theoretical and empirical investigation into the $k$-Nearest Neighbors ($k$-NN) algorithm. Their work establishes a formal framework for understanding why $k$-NN fails under adversarial pressure and introduces a novel "Robust 1-NN" algorithm designed to mitigate these vulnerabilities through strategic data pruning.
A Framework for Adversarial Robustness
To analyze the problem systematically, the authors propose a decomposition of adversarial robustness analogous to the classic bias-variance decomposition in statistical learning. They identify three primary sources of robustness (or lack thereof):
- Distributional Robustness (Bias): The inherent robustness of a classifier in the limit of infinite data. This represents the best possible robustness achievable given the underlying data distribution.
- Finite Sample Robustness (Variance): The loss in robustness that occurs because the model is trained on a limited dataset rather than the full distribution.
- Algorithmic Robustness: The impact of specific algorithmic choices—such as the distance metric or the value of $k$—on the resulting decision boundaries.
This framework allows the authors to pinpoint whether $k$-NN's failures stem from the data itself or the mechanics of the algorithm.
The $k$-NN Robustness Gap
The paper explores two distinct regimes for the parameter $k$, revealing a significant gap between standard accuracy and adversarial safety:
- The Fragility of Small $k$: The authors prove that if $k$ remains a constant as the sample size $n$ increases, the model's robustness effectively vanishes in any region where class labels are noisy. Even if the model achieves high accuracy, a tiny perturbation can easily shift a test point into a neighborhood dominated by a different class.
- The Asymptotic Robustness of Large $k$: Conversely, they demonstrate that if $k$ is allowed to grow at a specific rate—specifically $\Omega(\sqrt{dn \log n})$—the $k$-NN classifier eventually converges to the robustness of the Bayes Optimal classifier.
A key insight from this analysis is that Accuracy $\neq$ Robustness. A small $k$ may yield high predictive accuracy, but it requires a much larger $k$ (and significantly more data) to achieve the same level of robustness as the theoretical optimum.
The Robust 1-NN Algorithm
While increasing $k$ improves robustness, it is computationally expensive and requires massive datasets to maintain accuracy. To address this, the authors propose Robust 1-NN, an algorithm that focuses on modifying the training data rather than the classifier logic.
The algorithm works by creating an $r$-separated set. It identifies "red" points—training samples where the model is highly confident—and prunes the dataset to remove points that are too close to neighbors with different labels. By enforcing a minimum distance (a "safety margin") between classes, the algorithm carves out a "no-man's land" around the decision boundary. This ensures that a small adversarial perturbation cannot easily push a test point across the boundary into an incorrectly labeled region.
Empirical Evaluation
The authors evaluated Robust 1-NN against standard 1-NN and Adversarially Trained Neural Networks (ATNN) across three diverse datasets:
- Halfmoon: A synthetic 2D dataset used to visualize the stabilization of decision boundaries.
- Abalone: A UCI repository dataset used for predicting age based on physical measurements.
- MNIST 1v7: A subset of the handwritten digits dataset focusing on the binary classification of the visually similar digits '1' and '7'.
Key Results
- Performance: Robust 1-NN consistently outperformed standard 1-NN and ATNN baselines. The gains were most pronounced in "dense" datasets where the sample size was large relative to the number of dimensions.
- Attack Resilience: The algorithm proved effective against both "Direct Attacks" (white-box) and "Substitute Attacks" (black-box). In substitute attacks, the attacker attempts to model the $k$-NN decision boundary using a surrogate neural network to find weaknesses; Robust 1-NN remained resilient even under these conditions.
- Sparsity Challenges: On high-dimensional, sparse datasets like MNIST, the improvements were more modest but still statistically significant at larger attack radii.
Conclusion and Future Work
This research highlights that adversarial vulnerability is a fundamental property of how algorithms interact with data distributions, not just a quirk of deep learning. By pruning training data to enforce spatial separation, Robust 1-NN provides a computationally efficient way to harden non-parametric models.
Future research directions include extending the $r$-separation logic to multiclass problems and exploring the "middle regime" of $k$ values. Additionally, while Robust 1-NN is efficient at test time, the preprocessing step involves solving a constrained matching problem that may require further optimization for extremely large-scale datasets.
Summary updated