Analysis of KNN Density Estimation

Puning Zhao, Lifeng Lai · DOI

Abstract

This paper provides a rigorous theoretical analysis of the $k$-Nearest Neighbor (kNN) density estimator, establishing its convergence rates under both $\ell_1$ (average error) and $\ell_\infty$ (maximum error) criteria. By introducing a truncation mechanism, the authors demonstrate that kNN can outperform Kernel Density Estimation (KDE) for heavy-tailed distributions, challenging long-standing assumptions regarding the relative performance of these two fundamental nonparametric methods. The study establishes minimax optimality for kNN in various settings and provides empirical validation through synthetic simulations.

Introduction

Estimating the underlying probability density function (pdf) from a finite set of data points is a cornerstone of machine learning and statistics. While Kernel Density Estimation (KDE) has been exhaustively analyzed, the theoretical properties of the $k$-Nearest Neighbor (kNN) density estimator have historically been less understood. Previous analyses often relied on restrictive assumptions, such as 1D data, strictly bounded domains, or uniformly bounded Hessians—conditions that do not hold for many common distributions like the Gaussian or Cauchy distributions.

This research addresses these gaps by establishing the exact convergence rates of kNN for both bounded and unbounded distributions. Furthermore, it investigates whether kNN is "minimax optimal," meaning it achieves the theoretical limit of performance for any possible estimator in a given class.

The kNN Estimator and Its Variants

The standard kNN density estimator operates by determining the volume of a sphere centered at a point $x$ that expands to capture exactly $k$ data points. The density is then estimated as:

$$\hat{f}(x) = \frac{k}{n \cdot V_k(x)}$$

where $n$ is the total number of samples and $V_k(x)$ is the volume of the sphere. The authors analyze this estimator under two primary scenarios:

1. Bounded Support

In cases where data resides within a finite space and the density remains above a certain threshold, the standard kNN estimator is analyzed for $\ell_1$ error. However, for $\ell_\infty$ error (the maximum error at any single point), the authors introduce a boundary-corrected kNN estimator. This variant adjusts the volume calculation to account for the known edges of the data space, preventing the overestimation of volume that typically occurs near boundaries.

2. Unbounded Support

For distributions that extend to infinity (e.g., Gaussians), the density approaches zero in the tails. The authors prove that the standard kNN estimator fails in these regions, resulting in infinite $\ell_1$ error because the search radius expands too aggressively. To rectify this, they propose a truncated kNN estimator. If the distance to the $k$-th neighbor exceeds a predefined threshold $a$, the estimator stops expanding and calculates the density based on the number of points within radius $a$.

Key Insights and Theoretical Results

Optimality in Bounded Domains

The research demonstrates that for bounded support, the standard kNN estimator achieves the minimax optimal $\ell_1$ convergence rate of $\mathcal{O}(n^{-2/(d+2)})$. Interestingly, while the standard estimator is sufficient for $\ell_1$ optimality (as edge errors are averaged out), the boundary-corrected version is strictly necessary to achieve optimal $\ell_\infty$ rates. Without explicit boundary knowledge, the maximum error will fail to converge to zero.

Overturning the KDE Superiority Myth

A significant contribution of this paper is the comparison between kNN and KDE. Traditional literature suggested KDE was superior because it assumed a uniformly bounded Hessian (curvature) of the pdf. However, this paper adopts a more realistic assumption: that the curvature decays as the pdf itself decays (a property of Gaussians and Cauchy distributions). Under these conditions, kNN’s adaptive neighborhood size provides a superior bias-variance tradeoff in sparse tails compared to KDE’s fixed-size kernel. In head-to-head simulations on heavy-tailed distributions, the truncated kNN consistently outperformed KDE as sample sizes increased.

The Necessity of Truncation

The proof that standard kNN has infinite $\ell_1$ error on unbounded domains is a pivotal finding. By overestimating density in extreme tails, the standard method accumulates unbounded error. The proposed truncation method perfectly resolves this, allowing kNN to achieve optimal rates even for distributions with moderate-to-heavy tails.

Empirical Validation

While the paper is primarily theoretical, the authors validated their mathematical bounds using numerical simulations on synthetic data, including:

  • Bounded: 1D and 2D Uniform distributions.
  • Unbounded: 1D and 2D standard Gaussian distributions.
  • Heavy-tailed: Cauchy and custom heavy-tailed distributions.

In all cases, the empirical convergence rates matched the theoretical exponents derived in the proofs (e.g., an empirical rate of 0.33 for 1D uniform data, matching the theoretical prediction).

Conclusion and Future Work

This work establishes kNN as a formidable and often superior alternative to KDE, particularly for heavy-tailed data. However, some challenges remain. For extremely heavy-tailed distributions, a small gap exists between the kNN upper bound and the absolute minimax lower bound, suggesting room for further optimization. Additionally, the boundary-corrected estimator currently requires knowledge of the support set $S$, which is often unknown in high-dimensional real-world applications. Future research into adaptive boundary estimation could further enhance the practical utility of these theoretical advancements.

Summary updated

BibTeX
@article{zhao2020analysis,
  author = {Puning Zhao and Lifeng Lai},
  title = {{Analysis of KNN Density Estimation}},
  journal = {IEEE Trans. Information Theory},
  year = {2020},
  doi = {10.1109/tit.2022.3195870},
}
Figure