# Does this line in Python indicate that KNN is weighted?

Does this line in Python indicate that KNN is weighted?

clf = KNeighborsClassifier(n_neighbors=5, metric='euclidean', weights='distance')


Are the weights the inverse of the distance?

Can anyone also give an example of how weighted KNN works mathematically?

Yes, the line indicates that KNN is weighted and that the weight is the inverse of the distance. All of this can easily be found in scikit-learn's documentation

Also, pro-tip, you can find an object's documentation using the help function. In this case:

from sklearn.neighbors import KNeighborsClassifier

print(help(KNeighborsClassifier))