We have been using handwritten classification code, but Python is a very appropriate language for machine learning because of its excellent libraries. In particular, scikit-learn has become the standard library for many machine learning tasks, including classification. We are going to use its implementation of nearest neighbor classification in this section.
The scikit-learn classification API is organized around classifier objects. These objects have the following two essential methods:
fit(features, labels): This is the learning step and fits the parameters of the model
predict(features): This method can only be called after fit and returns a prediction for one or more inputs
Here is how we could use its implementation ...