ATLAS NOVA My AtlasVelocer ↗

Method · Machine learning

k-nearest neighbors

Instance-based classification method

k-nearest neighbors is a classification method that decides the label of a new data point by looking at the labeled examples closest to it.

The method keeps a store of examples whose classes are already known, and when an unclassified point arrives it measures how far that point lies from the stored ones, finds the k nearest neighbors (the k stored examples closest to it), and assigns the class that most of those neighbors belong to. The letter k is a number chosen in advance, so the rule reads: take the k closest known examples and let the majority decide.

Key facts
99.89%Detection rate of k=3 Euclidean KNN for QRS complexes on CSE ECG records (Saini et al. 2013)⁠[1]
83.62%Highest average accuracy among nine KNN variants for disease prediction, Hassanat KNN (Uddin et al. 2022)⁠[2]
61Average distance computations branch-and-bound needed to find nearest neighbor among 1000 samples (Fukunaga and Narendra 1975)⁠[3]
20%Accuracy drop of best distance measure as noise level reached 90 percent (Abu Alfeilat et al. 2019)⁠[4]

Overview

k-Nearest Neighbors

A concrete case makes the rule plain. Suppose a clinic has records of past patients, each described by a few measurements and each marked as healthy or ill. A new patient arrives with measurements but no diagnosis. The classifier compares the new patient's measurements with every stored record, ranks the records by closeness, and looks at the three or five nearest. If most of those nearest patients were marked ill, the new patient is labeled ill. Nothing about the disease is modeled; the decision rests entirely on resemblance to past cases.

A coordinate plot of five labeled points and a purple query connects to a distance ranking table and a blue majority vote.
A query is compared with five stored examples and classified using the three nearest. Two blue votes beat one orange vote. View full-size image.Classifying by Nearest Neighbor Votes by Atlas Nova. Illustration generated with AI for this article and checked against its text.

This is why the method is often described as storing rather than learning. The training examples are kept as vectors in a feature space, a multidimensional space in which each measurement is one coordinate, and each vector carries its class label.⁠[1] No general rule is extracted from them ahead of time. The comparison happens at the moment of classification, which is why the approach is called lazy learning: all the computation is deferred until a query arrives. The practical consequence is that the training phase is very fast, since it only stores the data, while the testing phase is costly in both time and memory, because every query must be compared against the stored examples.⁠[1]

Its simplicity is the main reason it matters. Because it requires only a few parameters to tune, chiefly k and the choice of distance, it is simple to implement.⁠[1] A method that is easy to implement and understand gives a simple reference point.⁠[5] The same simplicity carries known costs. The method slows markedly as the data set grows, and the ideal value of k is difficult to set.⁠[5] Its accuracy also depends heavily on the value of k and on the distance function used to measure closeness, so both are choices that shape the result rather than incidental settings.⁠[1]

The distance function is the rule that turns two feature vectors into a single number saying how far apart they are. Different rules measure distance differently, and the choice can change which examples count as nearest. The Euclidean distance, the straight-line distance familiar from geometry, is the most widely used, but it is not the only option; others include City Block and cosine, Chi square and Minkowsky distances.⁠[6][1] Because the whole classification rests on these measurements, the distance function is not a detail. Which function suits which kind of data is taken up later, along with how k is chosen and how the method is applied in practice.

k-nearest neighbors labels a new point by the majority class among its k closest stored examples, with no model fitted in advance.

History

From nearest neighbor rule to stored-example classifier

The rule at the heart of the method is older than the name it now carries. The nearest neighbor decision rule classifies a new object by finding the single most similar stored object and copying its label; k-nearest neighbors generalizes this by letting a small group vote.⁠[1] The classifier built on this rule is a non-parametric method, meaning it makes no assumption about the mathematical form of the distribution the data came from, unlike a model that fits a fixed set of parameters to the data. Cover and Hart described the k-nearest neighbor classifier as a conventional non-parametric classifier in 1967.⁠[6]

What made the rule attractive was not sophistication but reliability as a reference point. Because the method is simple and easy to implement, it has long served as the baseline classifier in many pattern classification problems, the standard against which a new method's results are measured.⁠[6] A baseline of this kind is useful precisely because it is hard to beat by accident: a more elaborate classifier that cannot outperform a rule this plain has not earned its complexity. The same role appears in reviews of classification algorithms, where k-nearest neighbors is grouped with support vector machines, random forests and neural networks as one of the standard non-parametric methods compared on robustness, stability, sensitivity to noise and accuracy.⁠[5]

The method's history is also a history of accumulated variants. A 2024 review dates the k-nearest neighbors method to 1951 and describes how it has since become a tool in data mining, recommendation systems and the Internet of Things, cataloguing 31 methods for searching out the nearest neighbors and 12 for joining two data sets by nearest-neighbor relations, with source code provided for each.⁠[7] That count is a measure of how much engineering has grown up around a rule that, in its basic form, is a majority vote among stored examples.

A tutorial treatment lays out the same picture from the teaching side: classification is achieved by identifying the nearest neighbors to a query example and using those neighbors to determine the query's class, and the approach has gained importance because the runtime cost that once made it impractical is less of a barrier with current computing power. The tutorial's concerns are the ones that follow from the rule itself: how similarity is assessed, how the nearest neighbors are found efficiently, and how the data can be reduced in dimension before the search begins.⁠[8]

Seen this way, the development runs in a straight line from a single-neighbor rule to a family of classifiers. The core decision never changed: an unknown object takes the class of the known objects most like it. What changed is everything around that decision, namely how closeness is measured, how many neighbors are consulted, how the search for them is sped up, and how the vote is counted. Those are the subjects of the sections that follow.

How it works

Storing examples instead of fitting a model

The method runs in two phases, and the split between them explains most of its behavior. In the training phase, the labeled examples are turned into vectors in the feature space and simply kept: each vector is stored together with its class label, and nothing else happens. In the classification phase, a query point arrives without a label, the algorithm computes its distance to the stored vectors, and the label assigned is the one most frequent among the k training samples nearest that query.⁠[1] The stored library is the whole of what the classifier knows.

It helps to picture the feature space concretely. Each measurement becomes one coordinate, so a patient described by age, blood pressure and cholesterol is a point in three dimensions, and a record with twenty measurements is a point in twenty. Storing the examples means placing labeled points in that space and leaving them there. Classifying a new point means asking which labeled points sit closest to it. The method has sometimes been described as comparing a query vector against a library of reference vectors and labeling it with the class of the nearest library entry.⁠[1]

Because no work is done in advance, the approach is called lazy learning: the classification function is approximated locally, and all computation is deferred until a query actually arrives.⁠[1] The name is apt in a second sense. A method that fits a model, such as a decision tree or a neural network, compresses the training data into a rule during training and can then discard the examples themselves. A lazy method performs no such generalization; every stored example is still needed at testing time, because any one of them might turn out to be a neighbor.⁠[1]

The practical consequences follow directly from that arrangement. Training is very fast, since it amounts to recording the vectors and their labels. Testing is costly in both time and memory: in time because each query must be compared against the stored examples, and in memory because the full training set has to remain available.⁠[1] The cost is paid per query rather than once, so a system that classifies many new points pays it many times over.

The same two-phase structure appears in descriptions of the method written for newcomers. One introductory treatment stresses that the algorithm directly searches through all the training examples at classification time, calculating distances between the test example and every stored example in order to identify its nearest neighbors and produce an output, with no offline training stage to speak of.⁠[6] The main computation is that on-line search, which is why the choice of how to conduct it matters so much.

There is a further consequence worth naming, because it shapes how the method is used. The price is that the boundary is never written down anywhere; it exists only implicitly, in the arrangement of the stored points, and is reconstructed anew for every query. The sections that follow take up how closeness is measured, how k is set, and where the resulting classifier has been put to work.

Training stores labeled vectors and nothing more; all the work, and all the cost, happens when a query arrives.

Training only stores examples, and all computation happens when a query arrives.

Measuring closeness: distance functions

Every decision the classifier makes rests on a single comparison: how far is the query point from each stored example? A distance function (also called a similarity measure) is the rule that takes two feature vectors and returns one number saying how far apart they are. It is the yardstick the method uses to rank the stored examples, and the k that come out on top are the ones that vote. Change the yardstick and a different set of examples becomes nearest, so the distance function is not a detail of implementation but part of the decision rule itself.

The most familiar yardstick is the Euclidean distance, the straight-line distance between two points. It is computed by taking the differences between the two vectors coordinate by coordinate, squaring each difference, adding the squares, and taking the square root. In two dimensions this is the length of the line segment joining the points, and the same formula extends to any number of dimensions. It is the most widely used distance function in k-nearest neighbors.⁠[6]

The City Block distance, also called Manhattan distance, measures the same separation differently: it adds the absolute differences along each coordinate rather than squaring them. The contrast is easiest to see in a city. Euclidean distance is the length of the path a bird would fly between two addresses; City Block distance is the length of the walk along the street grid, turning corners rather than cutting across blocks.⁠[1]

A third family treats the vectors as directions rather than positions. The cosine measure compares the angle between two vectors, ignoring their lengths, so two records pointing the same way count as close even if one has larger values throughout. This is the standard tool for comparing documents in text retrieval, where a long document and a short one on the same topic should be judged similar.⁠[6] The correlation distance works in the same spirit, subtracting each vector's average before comparing, so that it responds to the pattern of values across coordinates rather than their absolute size.⁠[1]

The Chi square distance is built for counts and frequencies. It weighs each coordinate's contribution by how large the values are expected to be, so that a difference in a coordinate with many counts counts for less than the same difference in a sparse one. It is one of the alternatives available to the classifier alongside the geometric measures.⁠[6]

The Minkowsky distance is a general formula that contains the first two as special cases. It raises each coordinate difference to a power r, sums them, and takes the r-th root. Setting r to 2 gives the Euclidean distance; setting r to 1 gives the City Block distance. The parameter r is typically set to 1 or 2, where the former is sometimes known as the Manhattan distance and the latter the Euclidean distance.⁠[6]

These are not the only options, and the list continues to grow. A review of distance measures tested a large number of them on real-world data sets, with and without added noise, and found that the performance of the classifier depends significantly on which distance is used, with large gaps between the results of different measures.⁠[4] That finding is a warning about treating the choice as arbitrary: two classifiers identical in every respect except their yardstick can behave quite differently on the same data.

Two practical points follow. How k is set, and whether the distance function actually changes accuracy on real medical data, are taken up in the sections that follow.

The distance function is the yardstick that decides which stored examples count as nearest; Euclidean is the common default, but City Block, cosine, correlation, Chi square and Minkowsky measure closeness in genuinely different ways.

Different distance functions measure closeness in different ways, so they can select different nearest examples.

Choosing k and the cost of the wrong choice

The letter k is not learned from the data. It is a user-defined constant, a number fixed before classification begins, and the classifier's behavior changes with it.⁠[1] The same stored examples, the same distance function and the same query can yield different labels under different values of k, because a different set of neighbors is allowed to vote. Setting k is therefore a decision the person building the classifier has to make, and it is one of only a few such decisions the method requires.

Two tables show three validation partitions and candidate accuracy scores, with the selected pair highlighted below.
Three validation folds compare candidate neighbor counts and distances. The illustrative results select k = 3 with Euclidean distance. View full-size image.Choosing Settings with Cross-Validation by Atlas Nova. Illustration generated with AI for this article and checked against its text.

The smallest setting has its own name. When k = 1, the class assigned is simply the class of the single closest stored example, and this special case is called the nearest neighbor algorithm.⁠[1] It is the purest form of the rule: no voting, no averaging, just copy the label of the most similar known case. It is also the most jumpy, since the outcome can change entirely if one stored example sits slightly closer than another.

Moving away from 1 trades one kind of error for another. Larger values of k reduce the effect of noise on the classification, because a single odd or mislabeled example can no longer decide the outcome on its own; it is outvoted by the rest of the neighborhood. The same increase makes the boundaries between classes less distinct, since a wide neighborhood reaches across the border and pulls in examples from the other side.⁠[1] A small k gives a flexible boundary that follows the data closely, including its noise; a large k gives a smooth boundary that may blur a real distinction. Neither is right in general, and the balance has to be struck for the problem at hand.

There is a small arithmetic reason to prefer odd values in some settings. In a two-class problem, an even k can split evenly, leaving no majority and no way to break the tie from the vote alone; choosing k to be odd avoids tied votes.⁠[1] This applies to binary classification, where two classes are in play. With three or more classes an odd k does not guarantee a majority either, since the neighbors can divide among several labels without any one of them winning.

Since no formula gives the right k, it is found by testing. Cross-validation is the procedure of partitioning the available samples into complementary subsets, training on one part and validating on the other, and repeating over several different partitions so that the results can be averaged and the variability reduced. In k-fold cross-validation the sample is split randomly into k subsamples; each subsample serves once as the validation set while the remaining ones serve as training data, and the k results are averaged into a single estimate.⁠[1] Applied to the classifier's own settings, the procedure is run for each candidate value of k and each candidate distance function, and the pair that classifies best is kept.

The same machinery serves to choose the distance function, and the two choices are usually settled together rather than one after the other. A study of medical datasets set k values from 1 to 15 and compared several distance functions under tenfold cross-validation.⁠[6] The details of what that comparison found belong to a later section; the point here is the method, namely that k and the yardstick are tuned as a pair against held-out data rather than assumed.

A fixed k has a known weakness that motivates later variants. Because one number is applied to every query, the classifier can be biased toward classes with many stored examples and can fail to make full use of the training set, which is why adaptive schemes that use different numbers of neighbors for different classes have been proposed.⁠[9] A related observation is that different regions of the feature space would require different values of k, since a query sitting in the middle of a class is in a very different situation from one near a boundary between two classes.⁠[10] Both responses take the same view: a single global k is a compromise, and a compromise that can be improved on locally.

k is set by the user, not learned; small values follow the data closely and inherit its noise, large values smooth the noise away and blur real boundaries, and cross-validation is how the balance is found.

Research

Does the distance function change accuracy?

The question is not whether distance functions differ in principle, since the formulas plainly compute different numbers, but whether the difference shows up in the accuracy of a working classifier on real data. The choice of yardstick was settled earlier as part of the decision rule; what remains is evidence about its practical weight. The most direct test comes from a study of medical datasets drawn from the UCI machine learning repository, a public collection of standard benchmark data used across machine learning.⁠[6]

The study was built around a simple observation about medical data. Records in that domain can be categorical (discrete values such as a yes-or-no finding), numerical (continuous measurements such as a blood pressure reading), or a mixture of both, and a distance function that suits one kind of data need not suit another. The researchers therefore assembled three groups of datasets, ten categorical, seventeen numerical and ten mixed, varying widely in the number of attributes, samples and classes, and classified each one with k-nearest neighbors using four distance functions in turn: Euclidean, cosine, Chi square and Minkowsky. The k values ran from 1 to 15, and tenfold cross-validation split each dataset into 90 percent training and 10 percent testing data so that every setting was judged on examples it had not seen.⁠[6]

The results were not uniform, and that is the substance of the finding. On the categorical datasets no single distance won on every dataset, though the Chi square function performed best on the Lymphograph and Promoters datasets, and Euclidean was not the best metric on two of the four categorical datasets shown. On the numerical datasets the pattern reversed: Euclidean, with Minkowsky behaving almost identically, performed best on most of them, including the breast cancer, Ecoli and Pima datasets, while the cosine function was better only on the blood dataset. On the mixed datasets Chi square was the best metric for most of them, including contraceptive, Liver_disorders and Stalog, and Euclidean did not outperform the other functions on the four mixed datasets shown.⁠[6]

Taken together, Chi square was the best choice across all three types of data, while cosine and Euclidean performed worst on the mixed type. The practical reading is that the distance function can affect classification accuracy, and that the right choice depends on what kind of data the records contain.⁠[6] A clinic whose records mix categorical findings with continuous measurements is in a different position from one whose measurements are all numerical, and the same classifier with the same k can be helped or hurt by the yardstick alone.

One detail of the comparison is worth noting because it bears on how much the Minkowsky parameter matters. The Minkowsky distance is typically used with r being 1 or 2, where the former is sometimes known as the Manhattan distance and the latter is the Euclidean distance, and the study found the accuracy under Euclidean and Minkowsky almost the same, meaning that using 1 or 2 for r did not affect the k-NN performance.⁠[6] The larger gaps lay between the geometric measures and Chi square, not within the Minkowsky family.

The scope of the result should be kept in view. It rests on medical datasets of three attribute types, judged by cross-validated accuracy, and it establishes that the choice matters and which function did best on these data; it does not make Chi square a universal rule for every problem. How the same two settings, k and distance, were tuned together in a quite different application, the detection of heartbeats in an electrocardiogram, is covered later.

On medical datasets of categorical, numerical and mixed types, Chi square gave the best overall accuracy, Euclidean did well on numerical and categorical data but poorly on mixed data, and the choice of distance function measurably changed the result.

Detecting heartbeats in an ECG signal

An electrocardiogram records the heart's electrical activity as a voltage that changes over time, and the signal is small, on the order of 1 mV, which makes it easy for interference to obscure. Within each beat, the QRS-complex is the sharp deflection that marks the electrical activity of the ventricles contracting; its timing and shape carry much of the information about the heart's state, and locating it is the reference step on which most automated ECG analysis depends. The normal QRS interval in an adult runs from 0.06 to 0.10 seconds.⁠[1] A detector that misses beats or invents them corrupts everything computed downstream, so the task is a demanding test of any classifier.

A printed ECG strip on graph paper with a timestamp, the header 'PHILIPS' and 'HR 213 LEAD II', and the handwritten word 'ADENOSINE' along the bottom, showing irregular spikes and a pause in the rhythm.
A printed ECG strip on graph paper with a timestamp, the header 'PHILIPS' and 'HR 213 LEAD II', and the handwritten word 'ADENOSINE' along the bottom, showing irregular spikes and a pause in the rhythm. View full-size image.Hr scan by Biosfear. CC BY 3.0, via Wikimedia Commons. Scaled to 960 pixels wide; no crop or other changes by Atlas Nova.

The problem suits k-nearest neighbors because it can be posed as a labeling question: given a short stretch of signal, is this a QRS-complex or not? The stored examples are labeled fragments of signal, and a new fragment is classified by resemblance to them. Two preparatory steps made that workable. A digital band-pass filter was applied first, to reduce false detections caused by interference, since noise accompanies ECG recording and must be suppressed before detection. The feature used for classification was then the gradient of the filtered signal, its rate of change, rather than the raw voltage; using the gradient reduced the computational burden on the classifier.⁠[1]

The settings were not assumed but selected. The researchers tested k values of 1, 3, 5, 7 and 9 against three distance metrics, Euclidean, City Block and correlation, and used fivefold cross-validation to find the combination giving the highest classification accuracy. The pair that won was k = 3 with the Euclidean distance, and that classifier was then used for detection.⁠[1] This is the same tuning procedure described earlier, applied here to a signal rather than a table of measurements.

Evaluation used two standard, manually annotated databases. The CSE multi-lead measurement library supplied 125 original 12-lead recordings, and the MIT-BIH Arrhythmia database supplied 48 half-hour two-lead recordings. A detection counted as a true positive when the algorithm correctly found a QRS-complex, a false negative when it missed one, and a false positive when it marked a non-QRS-complex as a beat. On the CSE recordings the detector reached a detection rate of 99.89 percent, with sensitivity and specificity both at 99.86 percent. On MIT-BIH the detection rate was 99.81 percent, with sensitivity 99.81 percent and specificity 99.86 percent, the errors amounting to 151 false positives and 207 false negatives.⁠[1]

The failures are as instructive as the successes. Across the CSE records the algorithm detected correctly in all but four; in two of those it missed a single beat each, and in the other two it marked one extra non-beat each. One missed beat, in record MO1_109, came from a QRS-complex of very low amplitude in most of the leads, a case where the signal itself gave the classifier little to match against. The same cause produced a miss in record 201 of MIT-BIH.⁠[1] These are the errors expected of a method that decides by resemblance: when a beat looks unlike the stored examples, it can be overlooked.

The study's authors set these figures against other published detectors run on the same two databases, and reported that the proposed algorithm gave an improved detection rate on CSE.⁠[1] What the numbers show is that a rule as plain as a majority vote among three nearest stored fragments can locate heartbeats with an error rate well under one percent on standard recordings. The classifier was not built from a theory of cardiac electrical activity; it was built from labeled examples of what a beat looks like, filtered and reduced to a gradient, with k and the distance function chosen by cross-validation. That a method this simple performs at this level on a clinical signal is the point the case makes, and it is why the same approach has been carried into other domains, covered later.

Filtering the signal, using its gradient as the feature, and tuning k and the distance by cross-validation let a three-neighbor classifier find heartbeats with detection rates above 99.8 percent on two standard ECG databases.⁠[1]

In practice

Where the classifier is put to work

The method's reach comes from the fact that many practical questions can be phrased as resemblance to past cases. A new document, a new pixel, a new signal, a new visitor to a website: each can be described by a set of measurements, and each can be labeled by the labels of the stored cases most like it. The applications below are not curiosities but working systems, and each one shows what the plain rule buys and what it costs in a particular setting.

Figure 1. Accuracy of k-nearest neighbors by document category on Reuters-21578. Classification accuracy of the k-nearest neighbors method for five categories of the Reuters-21578 text dataset. The source states: “KNN 98.00 98.51 99.70 99.29 99.27” (Bijalwan et al. (2014)).⁠[11]

Text categorization is the clearest case of the rule applied to something that is not a table of numbers. The task is to assign a set of documents to predefined categories, and a document belongs to exactly one category in single-label classification and to more than one in multi-label classification. To use k-nearest neighbors, each document is turned into a feature vector, and a new document is classified by the categories of the k nearest stored documents.⁠[11] The method suits the problem because the categories need not be described in advance; the stored examples carry the description. The same idea underlies a web recommendation system trained on click-stream data from an RSS reader website, where the classifier matches a visitor's session to a user group and recommends a browsing option tailored to that visitor, without the visitor being asked what they want. The authors of that work describe the classifier as transparent, consistent and easy to implement, particularly when little is known in advance about how the data are distributed.⁠[12]

Medical diagnosis has been a steady application. The ECG detector described earlier is one instance; disease classification more broadly has drawn on the method, and a comparison of nine k-nearest neighbor variants across eight benchmark datasets related to different diseases reported average accuracies ranging from 64.22 to 83.62 percent, with the Hassanat variant highest at 83.62 percent and an ensemble approach next at 82.34 percent.⁠[2] Those figures are per-variant averages over the eight datasets, not a claim that one variant is best in general, but they show the range a working classifier occupies on real medical data.

Remote sensing offers a case where the classifier competes directly with others on the same images. A study classified land use and land cover over a 30 by 30 kilometer area of the Red River Delta in Vietnam, with six cover types, using Sentinel-2 satellite imagery and fourteen training sample sizes from 50 to over 1250 pixels per class. All three classifiers compared, random forest, k-nearest neighbors and support vector machine, reached overall accuracies between 90 and 95 percent, and the support vector machine produced the highest accuracy with the least sensitivity to training sample size, followed by random forest and then k-nearest neighbors. The result is instructive about the method's place: it performed well, but it was not the strongest of the three, and all three converged to similar accuracy once the sample size passed 750 pixels per class.⁠[13]

Indoor positioning is a setting where the "stored examples" are measurements of radio signal strength. Wi-Fi based systems record the signal strengths reported at known reference points and match a new reading against them, but multipath signal attenuation and environmental change degrade the match. An improved scheme using a Spearman-distance-based k-nearest neighbor rule outperformed the original method under severe multipath fading and temporal dynamics.⁠[14] Radio-frequency identification has been used the same way, and a scheme combining Bayesian probability with k-nearest neighbors reported an average location error of about 15 centimeters, smaller than the Gaussian-based algorithm, the LANDMARC method and an improved k-nearest neighbor algorithm it was compared against.⁠[15]

Industrial processes use the rule for fault detection, where the situation is unusual because faults are usually neither identified nor characterized beforehand. A detection method built on the k-nearest neighbor rule was adapted so that only normal operation data is needed, and because the rule is a nonlinear classifier it handles nonlinearity in the data, while decisions based on small local neighborhoods of similar batches suit processes with multiple operating modes.⁠[16] The same rule has been extended from detecting a fault to isolating which variables caused it, by decomposing the k-nearest neighbor distance used as the detection index.⁠[17]

Gene function prediction shows the method stretched to heterogeneous data. A regression-based extension was applied to predict gene function in Escherichia coli under three classification schemes suggested by biologists, using information from microarray and genome sequencing data, and it outperformed naive k-nearest neighbor methods and was competitive with support vector machines for integrating heterogeneous data.⁠[18] Traffic forecasting is a further case: a short-term traffic condition model based on the rule, tested on GPS data from taxis in Foshan, China, performed well against support vector machine, artificial neural network, real-time-data and history-data models in multi-time-step prediction.⁠[19]

What these applications share is the shape of the problem rather than the subject matter. In each, a supply of labeled past cases exists, a sensible way to measure closeness can be defined, and the decision can be made by consulting the nearest of those cases. Where those three conditions hold, the method applies with little modification; where they fail, as when the signal is too noisy or the feature space too large, the difficulties covered later begin to bite.

Weighting the neighbors and adapting k

The plain rule counts every neighbor equally. Each of the k stored examples casts one vote, and the class with the most votes wins. That is a simplification with a visible cost. A stored example sitting right beside the query and another at the far edge of the neighborhood count for exactly the same, even though the closer one is plainly better evidence. The k-th neighbor is admitted and the (k+1)-th is excluded, so the outcome can jump when a query moves a hair's breadth and the membership of the neighborhood changes.⁠[20] The variants in this section all attack that flatness, either by giving neighbors unequal say or by letting the size of the neighborhood vary.

A table of three neighbors branches into equal-vote and inverse-distance calculations with orange and blue winners.
The same three neighbors yield different winners under equal and inverse-distance voting. A close blue neighbor outweighs two farther orange neighbors. View full-size image.Equal Votes and Distance Weights by Atlas Nova. Illustration generated with AI for this article and checked against its text.

Giving closer neighbors more say

The fuzzy k-nearest neighbor algorithm was introduced to address a related difficulty: in the standard rule each labeled sample is given equal importance in deciding the class of a new pattern, regardless of how typical that sample is of its class. The fuzzy version assigns each stored example a membership value, a number between 0 and 1 saying how strongly it belongs to each class, rather than a single hard label. Three methods of assigning those memberships were proposed and compared with the crisp version.⁠[21] A sample sitting deep inside its class can then carry more weight than one sitting ambiguously between two, and the vote becomes a sum of graded allegiances rather than a count of hard labels.

A simpler response keeps the hard labels and changes only the counting. In distance-weighted voting, each of the k neighbors contributes in proportion to how close it is, so the nearest example speaks loudest and the farthest barely counts. This softens the arbitrary cut at the k-th neighbor: an example just inside the boundary matters more than one just outside, and the outcome changes gradually as the query moves rather than jumping when the neighborhood's membership changes. A dual weighted voting scheme built on this idea was designed to reduce the effect of outliers among the k nearest neighbors of each query object, and in tests on one artificial and twelve real data sets it showed satisfactory classification performance and robustness over a wide range of k.⁠[22]

A third route replaces voting altogether. The Dempster-Shafer rule treats each neighbor not as a vote but as an item of evidence bearing on the query's class, with the strength of that support defined as a function of the distance between the two vectors, and pools the evidence of the k nearest neighbors by Dempster's rule of combination. This gives one framework for handling ambiguity, for rejecting a query whose neighbors are too distant to support any class, and for imperfect knowledge about the labels of the stored examples; its effectiveness against the voting and distance-weighted procedures was demonstrated on several sets of simulated and real-world data.⁠[23] The common thread is that closeness, typicalness or evidential weight, rather than mere presence in the neighborhood, decides how much each stored example counts.

Letting k vary

The other target of revision is k itself. A single number applied to every query is a compromise, and the compromise can be improved by letting the neighborhood size vary from place to place. One proposal associates a potentially different k with every stored prototype and finds the best value by optimizing a criterion that weighs the local and global effects of the different values in that prototype's neighborhood, on the reasoning that different regions of the feature space require different values because the prototypes are distributed differently.⁠[10] A query in the middle of a class and a query on the border between two classes are in very different situations, and a local k lets each be handled on its own terms. The method keeps a fast training stage and the same complexity as the standard rule at testing time.⁠[10]

A related line changes k by class rather than by region. Where the training set is uneven, some classes holding many more samples than others, a fixed k tends to bias the classifier toward the large classes and to waste the information in the small ones. An adaptive strategy therefore uses different numbers of nearest neighbors for different categories, taking more neighbors when deciding membership in a class that has more stored samples.⁠[24] The aim is to make the result less sensitive to the exact value of k and to classify documents from small classes properly even when k is large.⁠[9]

A more radical version drops the fixed neighborhood altogether. The k\*-nearest neighbors approach makes the bias-variance tradeoff explicit in a locally weighted regression or classification, which allows a notion of optimal weights to be stated and the optimal number of neighbors, together with those weights, to be found efficiently and adaptively for each data point whose value is to be estimated.⁠[25] Instead of choosing k once and applying it everywhere, the size of the neighborhood becomes part of what is fitted at each query.

Pooling several classifiers

Combining several classifiers is a further route. Ensemble methods pool the predictions of multiple models, and the approach has been applied here by selecting a subset of k-nearest neighbor classifiers on their individual out-of-sample accuracy and then combining the selected ones sequentially, starting from the best model and assessing the collective performance on a validation set. Evaluated on benchmark data sets with their original features and with added non-informative features, the ensemble gave better classification performance than the usual classifier and its ensembles, and performed comparably to random forest and support vector machines.⁠[26] The gain comes from averaging over several views of the same stored data, which is a different way of softening the influence of any single neighbor or any single arbitrary setting.

One further variant changes what the neighbors are compared against. The local mean representation-based classifier first chooses the categorical k nearest neighbors of a query sample, computes the corresponding categorical k-local mean vectors, represents the query as a linear combination of those means, and then uses the class-specific representation distances to decide the class. In experiments on many UCI and KEEL datasets and three face databases, it outperformed the related competitive k-nearest neighbor methods with more robustness and effectiveness.⁠[20] Here the vote is not over individual stored points at all but over summaries of each class's local neighborhood, which damps the effect of any one atypical example.

What these variants share is a refusal to treat the neighborhood as a flat ballot box. Each asks which neighbors deserve more say, or how many should be consulted, and answers with a rule drawn from the data rather than a constant. None of them changes the underlying decision, which is still resemblance to stored cases; they change how that resemblance is tallied. The difficulties that remain when the data are noisy, the features irrelevant or the store very large are covered later.

Weighting neighbors by closeness, giving them graded memberships, letting k vary by region or by class, pooling several classifiers, or treating neighbors as evidence all replace the flat majority vote with a more discriminating count.

Preprocessing and data quality for k-nearest neighbors

The classifier has no way to tell a good measurement from a bad one. Every coordinate of the feature space enters the distance calculation with the same standing, and whatever the stored examples contain passes straight into the vote. This is why the accuracy of the method can be severely degraded by three things: noisy data, irrelevant features, and features whose scales do not match their importance.⁠[1] Each of the three corrupts the same quantity, the distance between the query and its stored neighbors, and each is addressed before classification rather than by any change to the rule itself.

Original and scaled coordinate tables flank a Min-Max formula, with distance calculations identifying different nearest points.
Min-Max scaling changes the relative contributions of two features to Euclidean distance. In this worked example, the nearest point changes from A to B. View full-size image.Scaling Changes the Nearest Neighbor by Atlas Nova. Illustration generated with AI for this article and checked against its text.

Noise is the simplest of the three to picture. A coordinate recorded with random error adds an offset that has nothing to do with class, and that offset can push a stored example out of the neighborhood or pull a wrong one in. Because the decision rests on which examples land closest, a handful of corrupted coordinates is enough to change the answer. The remedy is to clean the signal before it becomes a feature.

In the ECG detector described earlier, a digital band-pass filter was applied first to reduce false detections caused by interference, since noise accompanies ECG recording and must be suppressed before detection. The same study then used the gradient of the signal as its feature for QRS detection, which served to reduce the computational burden on the KNN classifier.⁠[1] Filtering and feature construction are therefore not preliminaries to the method; they are part of making its central measurement meaningful.

Irrelevant features do their damage more quietly. A coordinate that carries no information about the class still contributes a difference to every distance, and if its values happen to be large it can dominate the sum. The classifier cannot discount it, because it has no notion of which coordinates matter. The ECG work is again an instance: the gradient of the signal was used as the feature for QRS detection, which served to reduce the computational burden on the KNN classifier.⁠[1]

Scale is the third problem and the most systematic. A measurement recorded in the thousands will outweigh one recorded in single digits, so the classifier effectively ignores the smaller one whatever its real value. The fix is normalization, rescaling each coordinate so that the measurements are comparable before distances are computed. A study comparing two normalization techniques, Z-score normalization and Min-Max normalization, classified the IRIS dataset with k-nearest neighbors and measured accuracy by cross-validation, treating the choice of scaling as a variable in its own right.⁠[27] The point is not that one rescaling is universally right but that the data must be put on a common footing before the yardstick is applied.

The same concern appears in settings where the coordinates are signal strengths rather than physical measurements. In Wi-Fi fingerprint-based indoor positioning, existing techniques failed to consider that equal differences in received signal strength at different signal levels may not mean equal differences in geometrical distance in a complex indoor environment. A feature-scaling-based variant introduced signal-level-based scaling weights into the computation of effective distances between a reported signal vector and the stored reference fingerprints, and in experiments it achieved an average location error as low as 1.70 meters, better than existing work.⁠[28] Here the scaling is not a preliminary cleanup but a correction built into the distance function, which shows how closely the two concerns are related.

Missing values raise a fourth difficulty, since a coordinate with no recorded value cannot enter a distance at all. The nearest-neighbor rule has been turned around to address this: missing values are imputed, and the same rule that classifies by resemblance is used to identify and correct imperfect data, alongside instance reduction that removes redundant samples, transforming large and messy collections into data of sufficient quality to expect a good outcome from any algorithm.⁠[29] The method that depends most on its stored examples is thus also used to repair them.

The general lesson is that the classifier's simplicity shifts work onto preparation. A method that fits a model can, in principle, learn to discount a noisy or irrelevant coordinate; a method that measures distance cannot, because the distance is computed before any such judgment could be made. The performance of the KNN classifier depends significantly on the distance measure used, and some distances are less affected by added noise than others.⁠[4] What the examples above show is the shape of the remedy: filter the signal, select the features, put the coordinates on a common scale, and fill the gaps, all before the first distance is measured.

The classifier cannot discount a bad coordinate, so noise, irrelevant features, mismatched scales and missing values must be handled before classification, by filtering, feature selection, normalization and imputation.

Alternatives

Variants that change the vote or the neighborhood

The plain rule counts every neighbor equally and gives each the same single vote. That is a simplification, and it has a visible cost. The fuzzy version assigns each stored example a membership value, a number between 0 and 1 saying how strongly it belongs to each class, rather than a single hard label, and three methods of assigning those memberships were proposed and compared with the crisp version.⁠[21] A sample that sits deep inside its class can then carry more weight than one that sits ambiguously between two.

This softens the arbitrary cut at the k-th neighbor: an example just inside the boundary matters more than one just outside, and the outcome changes gradually as the query moves rather than jumping when the membership of the neighborhood changes. The same idea appears in a dual weighted voting scheme designed to reduce the effect of outliers among the k nearest neighbors of each query object, which was tested on one artificial and twelve real data sets and reported satisfactory classification performance and robustness over a wide range of k.⁠[22]

A single number applied to every query is a compromise, and the compromise can be improved by letting the neighborhood size vary.

A related line of work changes k by class rather than by region. Where the training set is uneven, some classes holding many more samples than others, a fixed k tends to bias the classifier toward the large classes and to waste the information in the small ones; an adaptive strategy therefore uses different numbers of nearest neighbors for different categories, taking more neighbors when deciding membership in a class that has more stored samples.⁠[24]

Ensemble methods pool the predictions of multiple models, and the approach has been applied to this classifier by selecting a subset of k-nearest neighbor classifiers on their individual out-of-sample accuracy and then combining the selected ones sequentially, starting from the best model and assessing the collective performance on a validation set.⁠[26]

One variant replaces voting altogether. This gives a single framework for handling ambiguity, for rejecting a query whose neighbors are too distant to support any class, and for imperfect knowledge about the labels of the stored examples, and its effectiveness against the voting and distance-weighted procedures was demonstrated on several sets of simulated and real-world data.⁠[23]

Each one asks which neighbors deserve more say, or how many should be consulted, and answers with a rule drawn from the data rather than a constant. The difficulties that remain when the data are noisy, the features irrelevant or the set very large are covered later.

Comparing k-nearest neighbors with other classifiers

A classifier is rarely chosen in isolation. It is chosen against alternatives, and the comparison that matters is not which method is cleverest but which one suits the data, the budget and the tolerance for error. k-nearest neighbors enters that comparison with an unusual profile: it is the easiest of the standard methods to explain, it needs almost no preparation, and it pays for both advantages later. The evidence on how it fares comes from two kinds of source, a broad review that compared four non-parametric methods across many published studies, and a single controlled study that ran three of them on the same images.

The broad picture comes from a review of sixty-eight research articles published between 2000 and 2017, together with textbooks, that employed k-nearest neighbors, support vector machines, random forests and neural networks as their main statistical tools. The review compared the four on robustness to training data, sensitivity to changes, data fitting, stability, ability to handle large data sizes, sensitivity to noise, time invested in parameter tuning, and accuracy.⁠[5] Its conclusions are worth taking one at a time, because they do not point in a single direction.

On ease of use, k-nearest neighbors scores well and then stumbles. The method is easy to implement and understand, but it has a major drawback in becoming significantly slow as the size of the data in use grows, and the ideal value of k is difficult to set.⁠[5] Those two complaints are the ones raised throughout this chapter: the search cost that grows with the store, and the absence of a formula for k. The review adds a comparison of classification times that puts the cost in context. Larger input datasets lengthen classification times for neural networks and k-nearest neighbors more than for support vector machines and random forests.⁠[5] The reason is structural rather than incidental.

The same review found support vector machines and random forests insensitive to noise or overtraining, which it connects to their ability to deal with unbalanced data.⁠[5] That is a real advantage in settings where one class vastly outnumbers another, since a classifier that decides by local majority can be pulled toward the crowded class. Against this, random forest came out too sensitive to small changes in the training dataset, occasionally unstable and tending to overfit.⁠[5] No method in the comparison escaped criticism, which is the honest shape of the result: each has a failure mode, and the choice is a choice of which failure to risk.

The review's closing judgment is about practice rather than principle. Neural networks have the potential to become more widely used, but their time-consuming parameter tuning, high computational complexity, the numerous architectures to choose from and the many training algorithms make them costly to adopt, and most researchers in the reviewed literature recommended support vector machines and random forests as easier to wield, repeatedly accurate and often faster to implement. k-nearest neighbors sits outside that recommendation, not because it performed badly but because its costs, slowness on large data and the difficulty of setting k, are the ones practitioners feel most often.⁠[5]

A single study sharpens the comparison by holding the data fixed. Land use and land cover were classified over a 30 by 30 kilometer area of the Red River Delta in Vietnam, with six cover types, using Sentinel-2 satellite imagery and fourteen training sample sizes ranging from 50 to over 1250 pixels per class, balanced and imbalanced.⁠[13] Random forest, k-nearest neighbors and support vector machine were run on the same images, so differences in their results cannot be blamed on the data. All three reached high overall accuracy, between 90 and 95 percent. The support vector machine produced the highest accuracy with the least sensitivity to training sample size, followed by random forest and then k-nearest neighbors. Once the training sample passed 750 pixels per class, roughly 0.25 percent of the study area, all three converged to similar accuracy above 93.85 percent, and the high results held for both balanced and imbalanced samples.⁠[13]

The land cover result is the more useful of the two because it isolates one variable. Give it enough examples and the neighborhood fills with typical cases, and the gap closes. The practical reading is not that one classifier is better but that the amount of labeled data on hand changes the ranking, and a project with a small training set should weigh that before choosing.

One further comparison shows what happens when the plain rule is extended rather than replaced. A regression-based extension of k-nearest neighbors, which infers a similarity metric as a weighted combination of base measures instead of accepting an ad hoc one, was applied to gene function prediction in Escherichia coli under three classification schemes suggested by biologists, using microarray and genome sequencing data. It dramatically outperformed naive k-nearest neighbor methods and was competitive with support vector machines for integrating heterogeneous data.⁠[18] The lesson is that the gap between the simple method and the sophisticated ones is partly a gap in preparation, and that closing it does not require abandoning the rule of resemblance.

Set side by side, the comparisons agree on the shape of the trade. k-nearest neighbors asks least of its user at the outset and most of its data at classification time; support vector machines and random forests ask more in tuning and return robustness to noise and to unbalanced classes; neural networks ask most of all and demand the most experience to use well. The choice turns on how much labeled data exists, how quickly predictions must be returned, and how much noise the records carry.

Criticism

Speed, noise and the difficulty of setting k

The plain rule carries three costs that no amount of tuning removes, because they follow from how the method works. The first is search: classifying one query means measuring its distance to every stored example, and the number of measurements grows with the size of the store. The second is data quality: the decision rests entirely on the stored examples, so anything wrong with them passes straight into the answer. The third is the setting of k, which has no formula behind it. Each cost has drawn its own line of work.

The search cost is easy to underestimate. A classifier holding a million examples performs a million distance computations for a single query, and each computation runs over every coordinate of the feature space. A branch-and-bound algorithm was designed to cut this down by organizing the stored samples so that whole groups can be ruled out without measuring them, eliminating the need to calculate many distances; in tests it needed an average of only 61 distance computations to find the nearest neighbor of a test sample among 1000 stored samples.⁠[3] The saving comes from the structure of the search, not from any change to the rule, so the answer is the same one the exhaustive search would give.

A different strategy gives up exactness for speed. Approximate nearest neighbor search preprocesses a dataset of objects so that a new query can be matched quickly to the most similar stored object, accepting a small chance of missing the true nearest one in exchange for a large reduction in work.⁠[30] This trade is attractive when the store is huge and the cost of an occasional near miss is small, as in matching an image against a library of images. The same concern appears in reviews of the method's open problems, which list nearest neighbor search alongside the computation of k, the selection of neighbors and the choice of classification rule as matters still under active examination.⁠[31]

Data quality is the second cost, and it is sharper than it sounds. The accuracy of the classifier can be severely degraded by noisy data, by irrelevant features, and by features whose scales do not match their importance.⁠[1] The reason is that all three corrupt the distance measurement itself. A noisy coordinate adds a random offset that can push a stored example out of the neighborhood or pull a wrong one in. An irrelevant feature contributes a difference that has nothing to do with class, and if its values happen to be large it can dominate the sum. Unscaled features do the same thing systematically: a measurement recorded in the thousands will outweigh one recorded in single digits, so the classifier effectively ignores the smaller one whatever its real value. The remedy is preparation rather than a better rule, which is why the ECG detector filtered its signal and reduced it to a gradient before classifying.⁠[1]

The third cost is the setting of k, and it is the one with no clean solution. The ideal value of k for the classifier is difficult to set.⁠[5] Cross-validation gives an answer, but the answer is an average over the whole feature space, and the best value in one region need not be the best in another. Reviews of the method's challenges treat the computation of k as an open problem in its own right, alongside the other choices the rule leaves to its user.⁠[31] The variants described earlier, which let k vary by region or by class, are responses to exactly this difficulty rather than cures for it.

Noise deserves a final word because its effect has been measured. A review that tested many distance measures on real-world data sets, with and without added noise, found that the classifier using any of the top ten distances tolerated noise to a certain degree, and that the best-performing distance degraded only about 20 percent as the noise level reached 90 percent. Some distances were less affected by the added noise than others.⁠[4] The finding cuts both ways: the method is more robust to corrupted data than its reliance on exact distances might suggest, and yet the choice of yardstick still governs how much that robustness is worth.

The costs also compound as data grow. The method slows markedly as the data set grows, and massive amounts of data are likely to contain noise and imperfections, which turn it into an imprecise and inefficient technique.⁠[5][29] The response has been to clean and shrink the store before classifying: instance reduction removes redundant samples, missing values are imputed, and the same nearest-neighbor rule is turned around and used to identify and correct imperfect data, transforming large and messy collections into data of sufficient quality to expect a good outcome from any algorithm.⁠[29] The rule that classifies by resemblance can therefore also be used to judge which stored examples are worth keeping, which is a fitting end for a method whose whole knowledge lies in its examples.

The method's limits are structural: search cost grows with the store, noisy, irrelevant or unscaled features corrupt the distance itself, and k has no formula, only cross-validation and local compromises.

Key studies

YearStudySampleDesignFinding
1975Fukunaga & Narendra⁠[3]1000 design samplesbranch and bound search for nearest neighborsAn average of only 61 distance computations were needed to find the nearest neighbor of a test sample.
2013Saini et al.⁠[1]125 original 12-lead ECG recordings from the CSE database and 48 half-hour 2-lead recordings from MIT-BIHclassifier evaluation on two annotated ECG databasesWith k = 3 and Euclidean distance, detection rates were 99.89% for CSE and 99.81% for MIT-BIH.
2016Hu et al.⁠[6]comparison of four distance functions in k-nearest neighbors classificationThe Chi square distance performed best across all three dataset types, while cosine and Euclidean performed worst on the mixed type.
2016Li et al.⁠[28]WiFi fingerprint indoor positioning datafeature-scaling variant of k-nearest neighbors for localizationThe feature-scaling method achieved an average location error as low as 1.70 m.
2017Thanh Noi & Kappas⁠[13]a 30 by 30 km area in the Red River Delta of Vietnam with six land use typesland cover classification with 14 training sample sizes from 50 to over 1250 pixels per classAll classifiers reached 90% to 95% overall accuracy, and SVM was highest and least sensitive to sample size, followed by random forest and k-nearest neighbors.
2017Xu et al.⁠[15]117 reference tags and 5 target tags in a 3.6 m by 4.8 m areaindoor positioning experiment with RFID signalsThe proposed method had the smallest location error, about 15 cm on average.
2018Gul et al.⁠[26]31 benchmark datasets plus simulated dataensemble of a subset of k-nearest neighbors classifiersThe ensemble beat the usual k-nearest neighbors and its ensembles, and performed comparably to random forest and support vector machines.
2022Zhang⁠[31]15 UCI benchmark datasetscomparison of classification rules on balanced and unbalanced dataThe ShellKnn rule performed worst on the Yeast dataset but best on the German, Ionosphere and USPS datasets.

See also

References

  1. Saini, I., Singh, D., & Khosla, A. (2013). QRS detection using K-Nearest Neighbor algorithm (KNN) and evaluation on standard ECG databases. Journal of Advanced Research, 4(4), 331-344. doi:10.1016/j.jare.2012.05.007
  2. Uddin, S., Haque, I., Lu, H., Moni, M. A., & Gide, E. (2022). Comparative performance analysis of K-nearest neighbour (KNN) algorithm and its different variants for disease prediction. Scientific Reports, 12(1). doi:10.1038/s41598-022-10358-x
  3. Fukunaga, K., & Narendra, P. M. (1975). A Branch and Bound Algorithm for Computing k-Nearest Neighbors. IEEE Transactions on Computers, C-24(7), 750-753. doi:10.1109/t-c.1975.224297
  4. Abu Alfeilat, H. A., Hassanat, A. B. A., Lasassmeh, O., Tarawneh, A. S., Alhasanat, M. B., Eyal Salman, H. S., & Prasath, V. B. S. (2019). Effects of Distance Measure Choice on K-Nearest Neighbor Classifier Performance: A Review. Big Data, 7(4), 221-248. doi:10.1089/big.2018.0175
  5. Boateng, E. Y., Otoo, J., & Abaye, D. A. (2020). Basic Tenets of Classification Algorithms K-Nearest-Neighbor, Support Vector Machine, Random Forest and Neural Network: A Review. Journal of Data Analysis and Information Processing, 08(04), 341-357. doi:10.4236/jdaip.2020.84020
  6. Hu, L. Y., Huang, M. W., Ke, S. W., & Tsai, C. F. (2016). The distance function effect on k-nearest neighbor classification for medical datasets. SpringerPlus, 5(1). doi:10.1186/s40064-016-2941-7
  7. Halder, R. K., Uddin, M. N., Uddin, M. A., Aryal, S., & Khraisat, A. (2024). Enhancing K-nearest neighbor algorithm: a comprehensive review and performance analysis of modifications. Journal of Big Data, 11(1). doi:10.1186/s40537-024-00973-y
  8. Cunningham, P., & Delany, S. J. (2022). k-Nearest Neighbour Classifiers - A Tutorial. ACM Computing Surveys, 54(6), 1-25. doi:10.1145/3459665
  9. Zhang, S., Li, X., Zong, M., Zhu, X., & Cheng, D. (2017). Learning k for kNN Classification. ACM Transactions on Intelligent Systems and Technology, 8(3), 1-19. doi:10.1145/2990508
  10. Garcia-Pedrajas, N., Romero del Castillo, J. A., & Cerruela-Garcia, G. (2017). A Proposal for Local $k$ Values for $k$ -Nearest Neighbor Rule. IEEE Transactions on Neural Networks and Learning Systems, 28(2), 470-475. doi:10.1109/tnnls.2015.2506821
  11. Bijalwan, V., Kumar, V., Kumari, P., & Pascual, J. (2014). KNN based Machine Learning Approach for Text and Document Mining. International Journal of Database Theory and Application, 7(1), 61-70. doi:10.14257/ijdta.2014.7.1.06
  12. Adeniyi, D. A., Wei, Z., & Yongquan, Y. (2016). Automated web usage data mining and recommendation system using K-Nearest Neighbor (KNN) classification method. Applied Computing and Informatics, 12(1), 90-108. doi:10.1016/j.aci.2014.10.001
  13. Thanh Noi, P., & Kappas, M. (2017). Comparison of Random Forest, k-Nearest Neighbor, and Support Vector Machine Classifiers for Land Cover Classification Using Sentinel-2 Imagery. Sensors, 18(1), 18. doi:10.3390/s18010018
  14. Xie, Y., Wang, Y., Nallanathan, A., & Wang, L. (2016). An Improved K-Nearest-Neighbor Indoor Localization Method Based on Spearman Distance. IEEE Signal Processing Letters, 23(3), 351-355. doi:10.1109/lsp.2016.2519607
  15. Xu, H., Ding, Y., Li, P., Wang, R., & Li, Y. (2017). An RFID Indoor Positioning Algorithm Based on Bayesian Probability and K-Nearest Neighbor. Sensors, 17(8), 1806. doi:10.3390/s17081806
  16. He, Q. P., & Wang, J. (2007). Fault Detection Using the k-Nearest Neighbor Rule for Semiconductor Manufacturing Processes. IEEE Transactions on Semiconductor Manufacturing, 20(4), 345-354. doi:10.1109/tsm.2007.907607
  17. Zhou, Z., Wen, C., & Yang, C. (2016). Fault Isolation Based On k-Nearest Neighbor Rule For Industrial Processes. IEEE Transactions on Industrial Electronics, 1-1. doi:10.1109/tie.2016.2520898
  18. Yao, Z., & Ruzzo, W. L. (2006). A Regression-based K nearest neighbor algorithm for gene function prediction from heterogeneous data. BMC Bioinformatics, 7(S1). doi:10.1186/1471-2105-7-s1-s11
  19. Yu, B., Song, X., Guan, F., Yang, Z., & Yao, B. (2016). k-Nearest Neighbor Model for Multiple-Time-Step Prediction of Short-Term Traffic Condition. Journal of Transportation Engineering, 142(6). doi:10.1061/(asce)te.1943-5436.0000816
  20. Gou, J., Qiu, W., Yi, Z., Xu, Y., Mao, Q., & Zhan, Y. (2019). A Local Mean Representation-based K -Nearest Neighbor Classifier. ACM Transactions on Intelligent Systems and Technology, 10(3), 1-25. doi:10.1145/3319532
  21. Keller, J. M., Gray, M. R., & Givens, J. A. (1985). A fuzzy K-nearest neighbor algorithm. IEEE Transactions on Systems, Man, and Cybernetics, SMC-15(4), 580-585. doi:10.1109/tsmc.1985.6313426
  22. Gou, J., Xiong, T., & Kuang, Y. (2011). A Novel Weighted Voting for K-Nearest Neighbor Rule. Journal of Computers, 6(5). doi:10.4304/jcp.6.5.833-840
  23. Denoeux, T. (1995). A k-nearest neighbor classification rule based on Dempster-Shafer theory. IEEE Transactions on Systems, Man, and Cybernetics, 25(5), 804-813. doi:10.1109/21.376493
  24. Baoli, L., Qin, L., & Shiwen, Y. (2004). An adaptive k -nearest neighbor text categorization strategy. ACM Transactions on Asian Language Information Processing, 3(4), 215-226. doi:10.1145/1039621.1039623
  25. Anava, O., & Levy, K. Y. (2017). k*-Nearest Neighbors: From Global to Local. arXiv. doi:10.48550/arxiv.1701.07266 Free full text
  26. Gul, A., Perperoglou, A., Khan, Z., Mahmoud, O., Miftahuddin, M., Adler, W., & Lausen, B. (2018). Ensemble of a subset of kNN classifiers. Advances in Data Analysis and Classification, 12(4), 827-840. doi:10.1007/s11634-015-0227-5
  27. Bharati Vidyapeeth’s College of Engineering, Information Technology, New Delhi, 110063, India, Pandey, A., & Jain, A. (2017). Comparative Analysis of KNN Algorithm using Various Normalization Techniques. International Journal of Computer Network and Information Security, 9(11), 36-42. doi:10.5815/ijcnis.2017.11.04
  28. Li, D., Zhang, B., & Li, C. (2016). A Feature-Scaling-Based $k$ -Nearest Neighbor Algorithm for Indoor Positioning Systems. IEEE Internet of Things Journal, 3(4), 590-597. doi:10.1109/jiot.2015.2495229
  29. Triguero, I., García‐Gil, D., Maillo, J., Luengo, J., García, S., & Herrera, F. (2019). Transforming big data into smart data: An insight on the use of the k‐nearest neighbors algorithm to obtain quality data. WIREs Data Mining and Knowledge Discovery, 9(2). doi:10.1002/widm.1289
  30. Andoni, A., & Indyk, P. (2008). Near-optimal hashing algorithms for approximate nearest neighbor in high dimensions. Communications of the ACM, 51(1), 117-122. doi:10.1145/1327452.1327494
  31. Zhang, S. (2022). Challenges in KNN Classification. IEEE Transactions on Knowledge and Data Engineering, 34(10), 4663-4675. doi:10.1109/tkde.2021.3049250

Cite this page: Atlas Nova editors. (2026). k-nearest neighbors. Atlas Nova. https://velocer.io/atlas/k-nearest-neighbors/