nowwe need to classify new data point with black dot (at point , into blue or red class we are assuming it would find three nearest data points it is shown in the next diagramwe can see in the above diagram the three nearest neighbors of the data point with black dot among those threetwo of them lies in red class hence the black dot will also be assigned in red class implementation in python as we know -nearest neighbors (knnalgorithm can be used for both classification as well as regression the following are the recipes in python to use knn as classifier as well as regressor