logic behind weighted KNN I am reading about KNN





So I made another example to make things clearer

In this example (Image attached)



You can see there are in total 5 Greed Circles and 20 Blue Squares

by standard KNN (k=3) , X should be a Blue Square 

This is obvious 2 Blue Squares vs 1 Green Circle.

But in weighted KNN things are difference

In this case we have to calculate the weight (Likelihood) for each instance

Each Green Circle likelihood is $\frac{1}{5} $ , we have 5 Green Circles

While for Blue Squares it is  $\frac{1}{20} $ , we have 20 Blue Squares

Therefore the weights around X will be $\frac{1}{5} $  Green Circle, and $\frac{2}{20} $ Blue Squares.

which means $\frac{1}{5} &gt; \frac{2}{20} $

Then X is Green Circle

But if try to think of it logically then there are more Blue Squares than Green Circles which means X more likely to be Blue Square than Green Circle.

My question is :

Am I doing anything wrong here? Can someone explain why the equation is showing Green Circle while logic says Blue Square?
Logically speaking, I think "X is Green Circle" is a reasonable conclusion. I find the idea in the paper in your question is quite similar to this paper: KRNN: k Rare-class Nearest Neighbour Classification.

Intuitively, for example, if a new data point is close to one rare class' point and one common class' point, it is more likely to belong to the rare class.

There's no conflict here because a data point will be much more likely to be close to a common class' point. However, once it's already close to a rare class's data point, it's more likely to belong to this class.

That said, I didn't check your calculation, I just don't think the "X is Green Circle" conclusion is illogical for this algorithm.

[Update]

After reconsidering this problem, I think Weighted kNN want to put an emphasis on the rare class data point because that is the class of interest (e.g. Anomaly detection).

It's possible that Accuary is not the metrics here but a Weighted Accuracy metrics that penalize a misclassified rare class data point harder so that we can detect more rare class data point.