Ensemble K-Nearest Neighbors

Machine Learning
Introduced by
Domeniconi, C. & Yan, B. (key formalization)
Year
2000s
Type
Ensemble (aggregated KNN classifiers/regressors)
Family
Machine learning

What does it do?

Ensemble K-Nearest Neighbors combines several KNN models, each varied in k, distance metric, feature subset, or bootstrap sample, and aggregates their predictions by majority vote.

Diversity among the members is what distinguishes the ensemble from a single KNN, since nearly identical members add little. The key formalization cited here (Domeniconi and Yan, 2004) builds diverse members from different input feature choices and reports improvements over competing methods; the other sources of diversity listed above are common design choices rather than part of that work.

The intuition behind the method

A single KNN model is sensitive to its settings: the choice of k, the distance metric, and the input features all change which training points count as neighbours. Training several KNN models under different settings and letting them vote can reduce how much the final prediction depends on any one of those choices. The cited work rests on a related observation: nearest-neighbour classifiers are robust to variations of the data set but sensitive to the input features, so models built on different feature choices can make partly different errors. Whether the combined vote beats the best single member depends on how diverse the members actually are.

History

Nearest-neighbour classification is a classical non-parametric rule. Domeniconi and Yan (2004) described an approach that builds diverse NN classifiers from different input feature choices, reporting improvements over competing methods in their experiments. Their abstract emphasises diversity generated by feature choices rather than variation of k or the distance metric described on this page. For general background on ensemble methods, see Zhou (2012).

When to use it

Choose Ensemble KNN when a single KNN is a reasonable baseline but its results change noticeably with k, the distance metric, or the feature set, and you want to reduce that sensitivity while keeping a neighbour-based model. It fits small to medium tabular datasets where a distance metric is meaningful and features have been scaled. It is also a reasonable option when the best k is unclear, because members with different k values spread that choice across the ensemble. Avoid it on very large datasets: every member searches its stored training data for each query, so cost grows with both data size and the number of members. Be cautious with high-dimensional inputs: plain distance-based search becomes less informative as dimensionality grows, but the cited approach is designed to exploit high dimensionality through feature-subset diversity, so compare feature-subset members with dimensionality reduction on your own data. Also consider a simpler model when each individual prediction must be explained in detail, since the vote combines several neighbourhoods into one label.

Limitations and considerations

  • Inference cost grows with the training set size multiplied by the number of members, because each member searches its stored training data for every query.
  • Distance-based neighbour search degrades as feature dimensionality grows, so high-dimensional inputs may need reduction or careful feature-subset design. The cited abstract reports that the approach takes advantage of high dimensionality, so the effect of dimension depends on the setting and should be checked on the data at hand.
  • Memory use grows with the number of members, since each member keeps its own view of the training data.
  • Gains over a well-tuned single KNN are not guaranteed and may be small, especially on small or already well-scaled datasets.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Diverse members can improve on a single KNN without changing the core neighbour rule. The cited work reports better accuracy than competing methods from diverse NN classifiers built on different feature sets; variance reduction is a plausible explanation rather than a result shown in the cited abstract.
  • Exploits the sensitivity of nearest-neighbour classifiers to input features: members built on different feature choices can make partly different errors, which is the mechanism the cited work reports.
  • Requires no distributional assumptions beyond a distance metric that is meaningful for the features.
  • Handles multiclass classification directly, since the majority vote operates over class labels.
  • Members predict independently at inference time, so the work can be parallelised across members.

Applications

  • Tabular classification where a single KNN is an acceptable baseline but its predictions change with k, the metric, or the feature set.
  • Small to medium tabular datasets with meaningful feature distances, where a neighbour-based model is already an accepted baseline.
  • Classification tasks in which members can be built on different feature views, as in the cited work.

How it works

How it works

1

Diversity is created by varying one or more settings across members: k (for example 3, 5, 7, 11), the distance metric (Euclidean, Manhattan, Minkowski), bootstrap samples of the training data, or random feature subsets. The cited abstract attributes its gains to feature-subset diversity specifically. Without diversity, the ensemble is in effect a single KNN. In notation, member m uses its own k_m, distance d_m and feature subset F_m, and the members should differ in these settings.

2

Each member is fitted on its assigned view of the training data. KNN estimates no parameters during training, so this step mainly stores each member's training subset, feature view, and distance settings.

3

For a query point, each member finds the k nearest neighbours in its own feature and distance space and outputs a prediction: the majority class among those neighbours for classification, or their mean target value for regression.

4

For classification, the M member predictions are combined by majority vote, with ties broken by a secondary rule or random choice. This is the rule given in the formula above, which covers classification only. For regression, the member mean values are typically averaged; the sources used here do not give a formula for this case. Weighted voting, in which members with higher validation accuracy or closer neighbours receive larger votes, is a common extension and is not part of the formula above.

Formula
\hat{y} = \text{mode}(\{\hat{y}_1, \ldots, \hat{y}_M\})

Common pitfalls

  • Forgetting to scale features before computing distances: KNN is not scale-invariant, and unscaled features dominate distance calculations.
  • Creating non-diverse members (e.g., all using the same k and metric) so the ensemble is effectively a single KNN.
  • Ignoring class imbalance: KNN majority vote is biased toward the dominant class; use weighted voting or resampling.
  • Evaluating only on the training set or without cross-validation, which hides how the ensemble performs on unseen data.
  • Discarding high-dimensional features before testing: the cited approach relies on feature-subset diversity, so compare feature-subset members against dimensionality reduction on your data.

Frequently asked questions

How many KNN members should I include?

No fixed number is recommended here. A practical start is a small set of members that differ in k (for example 3, 5, 7, 9, 11) or in metric, checking cross-validated accuracy as members are added. Stop when validation performance no longer improves, since each member adds inference cost.

Does Ensemble KNN outperform Random Forest on tabular data?

No general ranking holds across tabular datasets, so compare both methods with cross-validation on your own data. Ensemble KNN is more plausible as a competitor when the dataset is small and the distance structure is clear, but that should be tested rather than assumed.

How do I handle categorical features?

KNN requires a numeric distance. Encode ordinal categories with ordered numbers, one-hot encode nominal categories, and use Hamming distance for binary features or Gower distance for mixed-type data. Scale all numeric features to comparable ranges before computing any distance.

Can I use weighted voting based on distance?

Yes. Distance-weighted KNN (each neighbor's vote is weighted by the inverse of its distance) extends naturally to ensembles. Each member applies its own distance-weighted vote, and the ensemble aggregates those weighted predictions.

Is cross-validation necessary if KNN has no explicit training phase?

Yes. Although KNN does not fit parameters, the choice of k, metric, and ensemble size are hyperparameters that must be validated on held-out data. Use k-fold cross-validation to select these and to report honest generalization performance.

Related methods

Sources

  1. Domeniconi, C., & Yan, B. (2004). Nearest neighbor ensemble. In Proceedings of the 17th International Conference on Pattern Recognition (ICPR), Vol. 1, pp. 228–231. IEEE.

    Open DOI reference
  2. Zhou, Z.-H. (2012). Ensemble Methods: Foundations and Algorithms. Chapman and Hall/CRC.

    ISBN: 978-1-4398-3003-1