example we are building knn classifier to recognize digits for thiswe will use the mnist dataset we will write this code in the jupyter notebook import the necessary packages as shown below here we are using the kneighborsclassifier module from the sklearn neighbors packagefrom sklearn datasets import import pandas as pd %matplotlib inline from sklearn neighbors import kneighborsclassifier import matplotlib pyplot as plt import numpy as np the following code will display the image of digit to verify what image we have to testdef image_display( )plt imshow(digit['images'][ ],cmap='greys_r'plt show(nowwe need to load the mnist dataset actually there are total images but we are using the first images as training sample and the remaining would be kept for testing purpose digit load_digits(digit_d pd dataframe(digit['data'][ : ]nowon displaying the images we can see the output as followsimage_display( image_display( image of is displayed as follows