arXiv:2610.41896cs.LGOct 2026

Manuscript Offprint

arXiv:2610.41896

On k-nearest-neighbor regression in metric spaces

László Györfi, Vladimir G. Pestov, Harro Walk, Roi Weiss

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

László Györfi, Vladimir G. Pestov, Harro Walk and Roi Weiss

Abstract: We study mean squared consistency of kk-nearest-neighbor regression for metric space valued features. For a fixed feature distribution μ\mu with atomless distance distributions, we describe how neighbor selection redistributes probability through the density of a uniformly chosen neighbor of an independent query. This gives separate conditions for the approximation error and the conditional response variance, and weakens Stone's domination condition when stronger response moments are available. In particular, when kn→∞k_n \to \infty and kn/n→0k_n/n \to 0, a uniform L2(μ)L_2(\mu) bound on the selection densities suffices under a finite fourth response moment. We give a corresponding condition in terms of neighborhoods of fixed population mass and recover the Euclidean density bound. Finite global Nagata dimension gives Stone's domination. While sigma-finite Nagata dimensionality is known to ensure universal consistency of kk-NN classification in complete separable spaces, we show that this is not the case for mean squared consistency with unbounded responses: we construct a space in this class on which one fixed noiseless response with all finite moments has diverging mean squared error.

MSC2020 subject classifications: Primary 62G08; secondary 62G20, 54F45.

Keywords and phrases: kk-nearest-neighbor regression, Mean squared consistency, Metric spaces, Nagata dimension, Neighbor-selection density, Unbounded responses.

1. Introduction

Let (X,ρ)(\mathcal{X}, \rho) be a separable metric space with its Borel σ\sigma-algebra. For the estimation of the nonparametric regression function, let the random feature (predictor) XX take values in the space X\mathcal{X}, and let its response (label) YY be real valued. We denote by μ\mu the feature distribution, that is, μ(A)=P(X∈A)\mu(A) = \mathbb{P}(X \in A) for all measurable sets A⊆XA \subseteq \mathcal{X}. For the mean squared error analysis, assume EY2<∞\mathbb{E}Y^2 < \infty. Define measurable versions of the regression function and the conditional variance by

m(x)=E[Y∣X=x],(1)m(x) = \mathbb{E}[Y \mid X = x], \tag{1} σ2(x)=E[(Y−m(X))2∣X=x].(2)\sigma^2(x) = \mathbb{E}[(Y - m(X))^2 \mid X = x]. \tag{2}

Let Dn={(X1,Y1),…,(Xn,Yn)}\mathcal{D}_n = \{(X_1, Y_1), \ldots, (X_n, Y_n)\} consist of independent copies of (X,Y)(X, Y). A test pair, again denoted by (X,Y)(X, Y), is independent of Dn\mathcal{D}_n. For a query xx, order the observations XiX_i by increasing distance ρ(x,Xi)\rho(x, X_i) and denote them by

(X(n,1)(x),Y(n,1)(x)),…,(X(n,n)(x),Y(n,n)(x)).\left(X_{(n,1)}(x), Y_{(n,1)}(x)\right), \ldots, \left(X_{(n,n)}(x), Y_{(n,n)}(x)\right).

Thus X(n,k)(x)X_{(n,k)}(x) is the kk-th nearest neighbor of xx. Ties are resolved by indices. For integers 1≤kn<n,n≥21 \leq k_n < n, n \geq 2, satisfying

kn⟶∞,kn/n⟶0,(3)k_n \longrightarrow \infty, \qquad k_n/n \longrightarrow 0, \tag{3}

L. Györfi et al.

the estimate and its mean integrated squared error are

mn(x)=1kn∑i=1knY(n,i)(x),(4)m_{n}(x)=\frac{1}{k_{n}}\sum_{i=1}^{k_{n}}Y_{(n,i)}(x), \tag{4} Rn,2=E∫(mn(x)−m(x))2μ(dx).(5)R_{n,2}=\mathbb{E}\int(m_{n}(x)-m(x))^{2}\mu(d x). \tag{5}

The relevance of this criterion comes from the mean squared error identity

E[(Y−mn(X))2]=E[σ2(X)]+Rn,2.\mathbb{E}[(Y-m_{n}(X))^{2}]=\mathbb{E}[\sigma^{2}(X)]+R_{n,2}.

The first term is the irreducible prediction error. Thus Rn,2→0R_{n,2} \to 0 means that the mean squared prediction error approaches the expected conditional variance, E[σ2(X)]\mathbb{E}[\sigma^2(X)]. We call this weak consistency in L2(μ)L_2(\mu). Background on nearest-neighbor regression is given in Györfi et al. [12, Chapter 6] and Biau and Devroye [1, Chapter 11].

Separability of the metric space X\mathcal{X} alone does not ensure consistency of ordinary kk-NN. There are feature distributions on the infinite-dimensional Hilbert space ℓ2\ell_2, with deterministic binary responses, for which the rule is inconsistent for every sequence satisfying (3); see Cérou and Guyader [2, Section 3.2] and Collins et al. [5, Section 3]. Thus locality of the selected neighbors is not by itself sufficient for estimating an arbitrary measurable conditional mean.

The failure of ordinary kk-NN in some separable metric spaces is a property of this estimator, rather than an impossibility of learning in those spaces. For classification, the OptiNet rule of Hanneke et al. [15] is universally strongly Bayes consistent in every separable metric space. The simpler Proto-NN construction of Györfi and Weiss [14] uses an independent unlabeled sample (prototypes) to form a Voronoi partition of X\mathcal{X} and averages the labeled responses within its cells. If the number MnM_n of prototypes tends to infinity and Mn/n→0M_n/n \to 0, their Theorem 3 gives strong integrated consistency of regression for bounded responses. For unbounded responses, set the estimate to zero in cells with fewer than log⁡n\log n observations and require Mnlog⁡n/n→0M_n \log n/n \to 0. Their Theorem 5 and the subsequent discussion then give strong L2L_2 consistency whenever EY2<∞\mathbb{E}Y^2 < \infty.

The partition structure explains an important difference. Conditional on a partition independent of the labeled sample, the expected cell-average of a nonnegative integrable function φ\varphi equals its conditional mean in that cell, multiplied by the probability that the cell is occupied. Averaging over the independent query therefore gives

E∑i=1nVn,i(X)φ(Xi)≤∫φdμ,\mathbb{E}\sum_{i=1}^{n}V_{n,i}(X)\varphi(X_{i})\leq\int\varphi d\mu,

where Vn,iV_{n,i} are the cell-average weights and are zero on empty cells. The modified rule for unbounded regression only reduces these weights, leaving the inequality intact. This domination holds without any dimension bound. Ordinary k-NN uses a different neighborhood for every query, so a separate argument is needed to control the distribution of the observations it selects.

The classical connection with differentiation of measures also has a statistical interpretation. Write B(x,t)B(x,t) for the closed ball of radius tt around xx. For a query xx and a radius tt with μ(B(x,t))>0\mu(B(x,t)) > 0, the population mean response in the ball is

at(x):=E[Y∣X∈B(x,t)]=∫B(x,t)m(z)μ(dz)μ(B(x,t)).a_{t}(x):=\mathbb{E}[Y\mid X\in B(x,t)]=\frac{\int_{B(x,t)}m(z)\mu(d z)}{\mu(B(x,t))}.

This is the population quantity estimated by a local average over that ball. Recovering m(x)m(x) as t↓0t \downarrow 0 is therefore the approximation requirement behind local averaging. In Euclidean spaces the differentiation theorem supplies this requirement almost everywhere for every Borel probability measure and every integrable regression function [1, Theorem 20.19]. In general metric spaces it can fail, even for an indicator function. The relevance to nearest-neighbor classification was developed by Cérou and Guyader [2]. Their corrected sufficient condition uses almost-everywhere differentiation even for weak consistency; see Pestov [19, Section 2.3, Theorem 2.2].

To see the role of this condition, fix a query xx where at(x)→m(x)a_t(x) \to m(x) as t↓0t \downarrow 0. Given ϵ>0\epsilon > 0, there is a radius t0(x,ϵ)>0t_0(x, \epsilon) > 0 such that ∣at(x)−m(x)∣<ϵ|a_t(x) - m(x)| < \epsilon for every 0<t<t0(x,ϵ)0 < t < t_0(x, \epsilon). This controls the average also at a random positive nearest-neighbor radius once that radius is sufficiently small. Convergence in μ\mu-measure for a common radius tt says only that most query points are well approximated at that radius; it does not provide the same control when the radius is selected separately for each query. Here “almost everywhere” concerns query points under μ\mu. It is distinct from the almost-sure convergence along training sequences required by strong consistency.

The obstruction can occur even when XX has a Gaussian distribution. Preiss et al. [21] constructed a nondegenerate Gaussian measure μ\mu on an infinite-dimensional separable Hilbert space HH and a Borel set MM of positive measure for which

lim sup⁡t↓0sup⁡x∈Hμ(B(x,t)∩M)μ(B(x,t))=0.\limsup_{t\downarrow0}\sup_{x\in H}\frac{\mu(B(x,t)\cap M)}{\mu(B(x,t))}=0.

For the noiseless response Y=1M(X)Y = \mathbf{1}_M(X), the population averages over small balls therefore approach zero even at points where the conditional mean equals one. A Gaussian distribution for XX alone does not ensure that local averages recover arbitrary measurable regression functions.

Pointwise estimation and integrated prediction error address different statistical questions. Pointwise consistency concerns the estimate at a fixed query, whereas integrated consistency averages its error over the distribution μ\mu of an independent test point XX. Devroye [7] studies conditions for pointwise convergence of nearest-neighbor regression estimates. In metric measure spaces, Cesari and Colomboni [3] connects Lebesgue points with noiseless nearest-neighbor pointwise estimation and examines the role of distance ties. Pointwise convergence alone does not ensure convergence of the mean integrated squared error: large errors on sets of small feature probability can still make a substantial contribution to the integral. If ∣Y∣≤L|Y| \leq L almost surely, then ∣mn(x)−m(x)∣2≤4L2|m_n(x) - m(x)|^2 \leq 4L^2 for μ\mu-almost every xx, almost surely. Pointwise almost-sure convergence for μ\mu-almost every xx then allows passage through both integration and expectation by the bounded convergence theorem. For unbounded responses there is no such bound, and additional integrability control is needed.

Strong consistency in L2(μ)L_2(\mu) means

∫∣mn−m∣2dμ⟶0almost surely.\int|m_{n}-m|^{2}d\mu\longrightarrow0\qquad\mathrm{a l m o s t~s u r e l y}.

Weak consistency requires the expectation of this integrated error, taken over the training sample, to tend to zero. Strong consistency requires the integrated error itself to approach zero for almost every infinite training sample. For Euclidean predictors and bounded responses, Devroye et al. [9, Theorem 1 and Remark 7] established strong integrated consistency under kn→∞k_n \to \infty

L. Györfi et al.

and kn/n→0k_n/n \to 0, using a specified randomized rule for distance ties. Their Theorem 2 treats integrated absolute error for integrable responses under the additional condition kn/log⁡n→∞k_n/\log n \to \infty. For metric spaces, Kumari and Pestov [16, Theorem 4.1] proved strong consistency of the k-NN classifier on complete separable sigma-finite-dimensional spaces in the absence of distance ties, under (3). Here sigma-finite dimensionality means a countable cover by sets of finite relative Nagata dimension on positive scales; the geometric definition is given in Section 3. Their proofs also use concentration inequalities to control deviations of integrated error terms from their expectations over the training sample. The results of the present paper concern mean integrated squared error.

Another statistical question is whether the random integrated error is accurately described by its expectation. Writing

En=∫∣mn(x)−m(x)∣2μ(dx),EEn=Rn,2,E_{n}=\int|m_{n}(x)-m(x)|^{2}\mu(d x),\qquad\mathbb{E}E_{n}=R_{n,2},

the corresponding relative-stability property is En/Rn,2→1E_n/R_{n,2} \to 1 in probability, when Rn,2>0R_{n,2} > 0 eventually. Relative stability of integrated errors, including nearest-neighbor regression errors, is studied by Györfi et al. [13].

Mean squared consistency of k-nearest-neighbor regression is studied in Section 2, the underlying geometric conditions in Section 3, and rates of convergence in Section 4. Proofs of the main consistency and geometric results are deferred to Section 5.