How is a distance metric used in KNN when $K$ is given? I am new to non-paramtric methods.
The conditional probability for classification using KNN is gen by:
$$
P(y=c|x,D)=\frac{1}{K}\sum_{n\in N_K(x,D)}I(y_n=c)
$$
where $N_K(x,D)$ is the set such that $K$ points are included to be nearest to the new point.
The 2 parameters required for the KNN is:

*

*$K$

*A distance metric (e.g. Mahalanobis):
$$
d(x,\mu)=\sqrt{(x-\mu)^T M(x-\mu)}
$$
My question is, why is a distance metric required? When all I need is to get the number of points belonging to a class $c$ and divide it by the total number of points nearest as dictated by $K$. I can repeat this for $c\in L$ and there goes my probability distribution for the most probable class.
To get the nearest $K$ points, shouldn't I just simply create a N-dimensional sphere from my new point and increase the radius until $K$ points are enclosed? I will then extract the labels of these points and do the usual KNN

Changing the distance metric changes the shape of that sphere enclosing the query point, and possibly the number of points inside a radius. For instance, compare Manhattan and Euclidean distances. The shape of all points in a 2-dimensional space within 1 unit in Manhattan distance is a square, but is a circle for Euclidean distance.
