How KNN is used?

Can someone exactly tell me how KNN Algorithm is used to recognise digits from MNIST Dataset?

Hi Jayanth,
KNN in MNIST is similarly applied as we did for a simpler example with 2 features.

Some points you need to understand.

  • Every image is of size 28x28. so it has 28*28 = 784 pixels, we will flatten these images to get a vector of (784,)
  • In earlier example we had only features x1 and x2, but now every pixel is a new feature so a total of 784 pixels.
  • So, whenever a new image comes, first flatten it to 784 features, and compute it’s distance with all other images(examples).
  • sort the distance in increasing order, take first K examples and do majority voting.

Final Note: Everything is the same, except we first need to flatten the image, and distances will be computed in 784 dimensions instead of 2dim(earlier example)

I hope you understand the logic now :slight_smile:

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.