Manuscript Offprint

arXiv:2611.07257

Evolutionary Adaptive Neighborhood Learning: A Genetic Algorithm for Instance-Dependent k Optimization in Nearest Neighbor Classification

Isaac Touza, Kaladzavi Guidedi, Kolyang

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

Abstract

The number of neighbours kk is the central hyper-parameter of the kk-nearest neighbour (kk-NN) classifier, and it is almost always chosen globally, by cross-validation or, increasingly, by evolutionary search. Yet the bias-variance trade-off that governs kk is local: dense, noise-free regions favour small neighbourhoods, whereas sparse or label-noisy regions favour large ones. Because the global-kk search space is one-dimensional, replacing exhaustive search by a genetic algorithm (GA) cannot improve on it. We therefore change the object being optimised. We propose EANK (Evolutionary Adaptive Neighborhood KK), which evolves a low-dimensional policy gθg_\theta mapping a description of the local neighbourhood of a point (density, label entropy at two scales, vote margin, concentration, relative density) to an instance-dependent number of neighbours k(x)∈{1,…,K}k(x) \in \{1, \dots, K\}. A real-coded elitist GA maximises the leave-one-out accuracy of the induced adaptive rule, penalised by a neighbourhood-smoothness term. A pre-computed vote table reduces each fitness evaluation to O(n)O(n) look-ups. We prove that (i) a seeded EANK never does worse than the best global kk on its training criterion, (ii) the GA converges almost surely to the essential supremum of the fitness, (iii) the learned neighbourhood size is Lipschitz in the meta-features, and (iv) the policy class has a growth function polynomial in the sample size with exponent d+2d+2. This yields a uniform generalisation bound that does not depend on nn, which per-instance encodings do not enjoy. On a controlled benchmark with spatially heterogeneous structure, EANK recovers small neighbourhoods in the fine-grained region and large ones in the noisy region, and it improves accuracy over the best global kk at every noise level. In a nested, 5×55 \times 5-fold evaluation on twelve public datasets, EANK obtains the best average rank among six kk-NN variants. Its accuracy is statistically indistinguishable from the tuned global-kk baselines, and it is significantly better than the default k=5k=5. We document the gap between in-sample and out-of-sample gains, and we identify it as the main obstacle for adaptive-neighbourhood methods.

Keywords: kk-nearest neighbours; adaptive neighbourhood; genetic algorithms; hyper-parameter optimisation; leave-one-out; generalisation bounds.

1 Introduction

The kk-nearest neighbour rule [5, 14, 29] remains one of the most widely used non-parametric classifiers. It is simple and universally consistent when k→∞k \to \infty and k/n→0k/n \to 0 [12, 30], and its predictions are easy to interpret. Its behaviour, however, depends strongly on the neighbourhood

*Corresponding author. E-mail: isaac_touza@outlook.fr.

size kk. A small kk gives a low-bias, high-variance rule that is sensitive to label noise. A large kk smooths the decision boundary but erases fine structure and minority regions.

In practice kk is selected once for the whole input space, by grid search with cross-validation, by leave-one-out (LOO) error, or by a metaheuristic. A recent line of applied work uses genetic algorithms (GAs) to tune kk, often jointly with feature selection or distance weights [17, 20, 24, 25]. Further studies examine how the choice of kk interacts with feature selection and class imbalance [6]. When kk is the only quantity being optimised, the search space {1,…,K}\{1, \ldots, K\} is one-dimensional and small. Exhaustive LOO search costs essentially the same as a single kk-NN pass, because all KK predictions of a point can be read from one sorted neighbour list. Exhaustive search therefore finds the exact optimum of the global-kk criterion, and it is an upper bound for any other optimiser of that criterion: a GA, random search [2] or Bayesian optimisation. Replacing grid search by a GA cannot, by construction, improve on it.

The statistical theory of nearest neighbours, by contrast, says that the right amount of smoothing is local. Convergence rates depend on the local density and the local margin [4], kk-NN adapts to the local intrinsic dimension [19], and recent adaptive rules choose the neighbourhood point by point [1]. This suggests changing the object being optimised: we look for a function x↦k(x)x \mapsto k(x) rather than an integer.

Approach. We parameterise this function as a policy kθ(x)=1+rnd((K−1)σ(w⊤z(x)+b))k_\theta(x) = 1 + \mathrm{rnd}((K-1)\sigma(w^\top z(x)+b)). Here z(x)∈Rdz(x) \in \mathbb{R}^d is a small vector of meta-features that describe the neighbourhood of xx in the training set (scale, label entropy, vote margin, concentration, relative density), and θ=(w,b)∈Rd+1\theta = (w, b) \in \mathbb{R}^{d+1} with d=7d=7. The induced rule classifies xx by majority vote among its kθ(x)k_\theta(x) nearest neighbours. The objective is piecewise constant and non-differentiable in θ\theta, and it has many plateaus, so we optimise it with a real-coded elitist GA. The fitness is the LOO accuracy of the adaptive rule minus a smoothness penalty on kk between neighbouring points.

References (33)