We can view nearest neighbor as a voting process where we consult our nearest neighbor.

We give the -th data point a voting weight .

In your example, each data point in class has weight and each data point in class has weight . There are votes from class and votes from class . We give class a score of and class a score of . Class has a higher score, hence we assign it to class .

Answer from Siong Thye Goh on Stack Exchange
🌐
Visual Studio Magazine
visualstudiomagazine.com › articles › 2019 › 04 › 01 › weighted-k-nn-classification.aspx
Weighted k-NN Classification Using Python -- Visual Studio Magazine
For example, if k = 4 and c = 3, ... rule approach. The majority rule approach has two significant problems, First, ties are possible....
🌐
Univr
profs.sci.univr.it › ~bicego › papers › 2016_ICPR.pdf pdf
Weighted K-Nearest Neighbor Revisited M. Bicego University of Verona
Given a classification problem · involving C classes, and a pattern x to be classified, every ... P(c|x)— or simply a matching score, i.e. a number indicating · how likely is that the class of x is c (called confidences in · [12]). A given classifier (expert) Eℓtakes a decision on x ... III. THE WEIGHTED KNN RULE REVISITED
🌐
GeeksforGeeks
geeksforgeeks.org › machine learning › weighted-k-nn
Weighted K-NN - GeeksforGeeks
July 12, 2025 - Consider the white point as the query point( the point whose class label has to be predicted) If we give the above dataset to a kNN based classifier, then the classifier would declare the query point to belong to the class 0. But in the plot, it is clear that the point is more closer to the class 1 points compared to the class 0 points. To overcome this disadvantage, weighted kNN is used.
🌐
YouTube
youtube.com › watch
9. Weighted KNN Solved example Weighted K-Nearest Neighbors (KNN) Classification Vidya Mahesh Huddar - YouTube
9. Weighted KNN Solved example Weighted K-Nearest Neighbors (KNN) Classification by Vidya Mahesh HuddarConsider the student performance training dataset of 8...
Published: May 28, 2026
🌐
Open Access LMU
epub.ub.uni-muenchen.de › 1769 › 1 › paper_399.pdf pdf
Hechenbichler, Schliep: Weighted k-Nearest-Neighbor Techniques and Ordinal
Now the problem arises of how to standardize these dummy variables. We offer · a standardization technique for both kinds of dummy variables, that is based · on the trace of the covariance matrix of the corresponding dummies. We ignore ... These standardized distances always take values within the interval [0, 1]. In · our implementation we add a small constant ϵ > 0 to d(x, x(k+1)) in order to · avoid weights of 0 for some of the nearest neighbors.
🌐
James D. McCaffrey
jamesmccaffreyblog.com › home › weighted k-nearest neighbors classification example using python
Weighted k-Nearest Neighbors Classification Example Using Python - James D. McCaffreyJames D. McCaffrey
July 25, 2025 - I set k = 6 in my demo code. The problem with a simple majority voting rule is that it doesn’t take into account how close the k points are. A better approach is to give more weight to points that are close to the data item that is being predicted.
Find elsewhere
🌐
Medium
vishvaasswaminathan.medium.com › weighted-knn-algorithm-c43b400346bf
Weighted KNN Algorithm. Weighted k-NN is a modified version of… | by Vishvaasswaminathan | Medium
September 28, 2023 - Weighted KNN Algorithm Weighted k-NN is a modified version of k nearest neighbors. One of the many issues that affect the performance of the k-NN algorithm is the choice of the hyperparameter k. If k …
🌐
Wikipedia
en.wikipedia.org › wiki › K-nearest_neighbors_algorithm
k-nearest neighbors algorithm - Wikipedia
August 27, 2026 - That is, examples of a more frequent class tend to dominate the prediction of the new example, because they tend to be common among the k nearest neighbors due to their large number. One way to overcome this problem is to weight the classification, taking into account the distance from the ...
🌐
Slideshare
slideshare.net › home › education › knn,weighted knn,nearest centroid classifier,locally weighted regression
KNN,Weighted KNN,Nearest Centroid Classifier,Locally Weighted Regression | PDF
May 24, 2025 - Problem 5 Consider thestudent performance training dataset. Given a test instance (6.1, 40, 5) and a set of categories {Pass, Fail}.Classify the test instance considering k=3 using Weighted k-NN
🌐
Medium
medium.com › @lakshmiteja.ip › understanding-weighted-k-nearest-neighbors-k-nn-algorithm-3485001611ce
Understanding Weighted k-Nearest Neighbors (k-NN) Algorithm | by Lakshmi Teja Illuri | Medium
September 26, 2023 - On the other hand, weighted k-NN introduces the concept of assigning different weights to neighbors based on their proximity to the query point, which can lead to improved performance.
Top answer
1 of 2
2

Consider a simple example with three classifications (red green blue) and the six nearest neighbors denoted by R, G, B. I'll make this linear to simplify visualization and arithmetic

R B G x G R R

The points listed with distance are

class dist
  R     3
  B     2
  G     1
  G     1
  R     2
  R     3

Thus, if we're using unweighted nearest neighbours, the simple "voting" algorithm is 3-2-1 in favor of Red. However, with the weighted influences, we have ...

red_total   = 1/3^2 + 1/2^2 + 1/3^2  = 1/4 + 2/9 ~=  .47
blue_total  = 1/2^2 ..............................=  .25
green_total = 1/1^2 + 1/1^2 ......................= 2.00

... and x winds up as Green due to proximity.

That lower-delta function is merely the classification function; in this simple example, it returns red | green | blue. In a more complex example, ... well, I'll leave that to later tutorials.

2 of 2
1

Okay, off the bat let me say I am not the fan of the link you provided, it has image equations and follows a different notation in the images and the text.


So leaving that off let's look at the regular k-NN algorithm. regular k-NN is actually just a special case of weighted k-NN. You assign a weight of 1 to k neighbors and 0 to the rest.

  1. Let Wqj denote the weight associated with a point j relative to a point q
  2. Let yj be the class label associated with the data point j. For simplicity let us assume we are classifying birds as either crows, hens or turkeys => discrete classes. So for all j, yj <- {crow, turkey, hen}
  3. A good weight metric is the inverse of the distance , whatever distance be it Euclidean, Mahalanobis etc.
  4. Given all this, the class label yq you would associate with the point q you are trying to predict would be the the sum of the wqj . yj terms diviided by the sum of all weights. You do not have to the division if you normalize the weights first.
  5. You would end up with an equation as follows somevalue1 . crow + somevalue2 . hen + somevalue3 . turkey
  6. One of these classes will have a higher somevalue. The class witht he highest value is what you will predict for point q
  7. For the purpose of training you can factor in the error anyway you want. Since the classes are discrete there are a limited number of simple ways you can adjust the weight to improve accuracy
🌐
Medium
medium.com › analytics-vidhya › feature-engineering-experiment-weighted-knn-3f28dfdf30e1
Feature Engineering Experiment- Weighted KNN | by Abhijeet Pokhriyal | Analytics Vidhya | Medium
March 15, 2020 - Then we wrap the KNN algorithm in a function. Lets go over the overall approach. ... 3. Then we pick the k- nearest neighbors and use them to predict,for each observation, the correct label. ... To get a sense of how good the learned weights are we can run KNN using all features and compare it with KNN run using only the 5 features with highest weights (remember while creating the dataset we had set n_informative to 5).
🌐
RStudio
rstudio-pubs-static.s3.amazonaws.com › 248376_c3c699140f4b4d7ba3f3e496dcedc99b.html
Instance-Based Learning: kNN, weighted kNN
November 2, 2016 - The goal of this work is to experiment with classical kNN algorithm and distance weighted kNN and compare their accuracy. The idea of the knn algorithm is to measure the distance between the given test example and all the examples in the dataset, choose k closest examples and then predict class ...
🌐
MDPI
mdpi.com › 1996-1073 › 12 › 5 › 916
Application of the Weighted K-Nearest Neighbor Algorithm for Short-Term Load Forecasting
March 9, 2019 - In the future, authors will combine the short-term forecasting approach with the medium-short-term forecasting approach, to detect the market demand shrinking information problem, particularly for the upper-point point (peak) of the electric behavior regulations. Meanwhile, authors will also look for an optimized approach to optimize the weight, in order to improve the forecasting accuracy, for example, for the complete, the same, or very closed commodities, their weights would be set as huge or even infinite; therefore, when calculating the reciprocal distance, some constant can be added to revise the distance.
🌐
Scribd
scribd.com › document › 640881835 › Solved-Example-K-Nearest-Neighbors-Algorithm-Weighted-KNN-to-classify-New-Instance-by-Mahesh-Huddar
Solved Example K Nearest Neighbors Algorithm Weighted ...
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
IJACSA
thesai.org › Downloads › Volume15No9 › Paper_22-Compactness_Weighted_KNN_Classification_Algorithm.pdf pdf
(IJACSA) International Journal of Advanced Computer Science and Applications,
Minkowski distance using compactness weights is proposed, forming the basis for developing the CKNN algorithm. Compara- tive experimental results on five real-world datasets demonstrate · that the CKNN algorithm outperforms eight existing variant · KNN algorithms in Accuracy, Precision, Recall, and F1 perfor-
🌐
ResearchGate
researchgate.net › publication › 274479835_Weighted_K-Nearest_Neighbor_Classification_Algorithm_Based_on_Genetic_Algorithm
(PDF) Weighted K-Nearest Neighbor Classification Algorithm Based on Genetic Algorithm
October 1, 2013 - The optimized KNN uses weights to classify test sample. The new technique is tested on four standard datasets. Results show the significant increment in accuracy in comparison with conventional KNN strategy. ... T. I. Drovosekova ... One of the most urgent problems in the study and analysis of hydrolithospheric processes is the construction of verifiable mathematical and computer models that make it possible to predict the behavior of an object under various initial conditions and input influences.