Nearest-neighbors can also be used for image recognition. The hello world of image recognition datasets is the MNIST handwritten digit dataset. Since we will be using this dataset for various neural network image recognition algorithms in later chapters, it will be great to compare the results to a non-neural network algorithm.
Using nearest-neighbors for image recognition
Getting ready
The MNIST digit dataset is composed of thousands of labeled images that are 28x28 pixels in size. Although this is considered a small image, it has a total of 784 pixels (or features) for the nearest-neighbor algorithm. We will compute the nearest-neighbor prediction for this categorical problem by considering the mode prediction of the nearest...