4
$\begingroup$

When using KNeighborsClassifier, what is the motivation of using weights="distance"?

According to the scikit-learn documentation:

‘distance’ : weight points by the inverse of their distance. In this case, closer neighbors of a query point will have a greater influence than neighbors which are further away.

What is the motivation for using this?

$\endgroup$
1
5
$\begingroup$

weights = 'distance' is in contrast to the default which is weights = 'uniform'. When weights are uniform, a simple majority vote of the nearest neighbors is used to assign cluster membership.

When weights are distance weighted, the voting is proportional to the distance value. Nearby points will have a greater influence than more distance points (even if the counts of different groups are the similar).

Distance weighting is very useful for sparse data.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.