A Bayes consistent 1-NN classifier

Aryeh Kontorovich, Roi Weiss

Abstract

We show that a simple modification of the 1-nearest neighbor classifier yields a strongly Bayes consistent learner. Prior to this work, the only strongly Bayes consistent proximity-based method was the $k$-nearest neighbor classifier with $k$ growing with sample size. Our approach leverages structural risk minimization to select a representative subset of the data, maintaining the simplicity of 1-NN while gaining theoretical robustness and computational efficiency.

Introduction

In machine learning, a primary goal is to develop "consistent" classifiers—those whose error rates converge to the Bayes-optimal risk ($R^*$) as the training sample size grows. The classic 1-nearest neighbor (1-NN) classifier is widely used due to its simplicity and speed. However, it is fundamentally limited by its lack of Bayes consistency; its error rate typically converges to a value between $R^*$ and $2R^*$.

To achieve consistency, practitioners often turn to $k$-NN models where $k$ increases with the sample size. While theoretically sound, $k$-NN requires storing the entire dataset and suffers from slow query times and difficult-to-derive error bounds. This paper introduces a Regularized 1-NN classifier that bridges this gap, offering the theoretical guarantees of $k$-NN with the practical benefits of 1-NN.

Methods: Regularized 1-NN via Structural Risk Minimization

The proposed algorithm is based on the principle of Structural Risk Minimization (SRM). Instead of using the full training set $S$, the learner identifies a sub-sample $\tilde{S}$ that optimizes a balance between empirical error and a margin-based penalty.

The optimization involves two key components:

  1. Empirical Error: The accuracy of the 1-NN classifier induced by the sub-sample $\tilde{S}$ on the original training set $S$.
  2. Margin Penalty: A regularization term that favors a larger margin $\gamma$—the minimum distance between points of different classes in $\tilde{S}$.

The algorithm employs a nested routine. For a fixed margin $\gamma$, it constructs a bipartite graph of "conflicting" points (those with different labels within distance $\gamma$) and solves a Minimum Vertex Cover problem. Removing these vertices yields the optimal $\gamma$-separable sub-sample. An outer loop then searches for the $\gamma$ that minimizes the total penalized risk. This approach is metric-space agnostic, relying on the doubling dimension of the space rather than Euclidean properties.

Experimental Setup

The algorithm was evaluated on a synthetic 2D spiral dataset. Points were sampled along a spiral, with stochastic labels whose class probability varied sinusoidally. This complex geometry allows for an exact calculation of the Bayes-optimal risk, providing a rigorous benchmark for testing convergence.

Performance and Efficiency

The experimental results confirm that the SRM-based 1-NN classifier achieves its theoretical promises.

Generalization error vs. sample size showing convergence to the Bayes optimal risk.

As shown in the generalization error analysis, the SRM-1-NN (magenta triangles) successfully converges toward the Bayes-optimal error rate as the sample size increases. While standard cross-validated 1-NN (CV-1-NN) may perform slightly better on very small samples, SRM-1-NN catches up rapidly, demonstrating its strong consistency.

Running time comparison between SRM-1-NN and other standard classifiers.

Beyond accuracy, the computational efficiency of SRM-1-NN is a significant advantage. By avoiding the exhaustive "leave-one-out" cycles required by $k^*$-NN or SVMs, the proposed method is orders of magnitude faster. For a sample size of 5,000, SRM-1-NN completes in seconds, whereas competing methods can take hours.

Conclusion

This work provides the first proof of strong Bayes consistency for an algorithmically efficient 1-NN classifier. By framing subset selection as a combinatorial optimization problem, the authors have created a learner that is both theoretically robust and practically superior for large datasets. Future work may focus on further reducing the $O(n^{4.376})$ runtime through approximation algorithms and testing the method on high-dimensional real-world data where the doubling dimension plays a more prominent role.

Summary updated

BibTeX
@inproceedings{kontorovich2015bayes,
  author = {Aryeh Kontorovich and Roi Weiss},
  title = {{A Bayes consistent 1-NN classifier}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2015},
  url = {https://openreview.net/forum?id=Bq5Fmgezmq},
}
Figure