All right.
So that was the name of the module you had to find.
And now the next question is which of these classes.
Because you see these are all the classes of this neighbors module.
That's actually the name of the module by site learn neighbors.
And these are all the classes that allow you to build machine learning tools.
You know, in this nearest neighbors branch of machine learning.
All right.
So of course, the one we're interested in is this one k neighbors classifier.
There you go. Congratulations if you found it.
So let's click it and let's see the whole documentation.
So feel free to read it if you want.
You can see what are all the parameters and also attributes.
But what we actually simply need is this, you know,
the whole name of the class and the module and the library scikit learn.
Because the only thing that we need really to build and train the skin and model
is the name of this class to, you know, create the object
and also the parameters here we need to know which parameters
we have to enter here in order to build a relevant K and an ML.
All right.
So first let's do this and let's go back to our implementation to here paste it
and then adapted by you know doing this from from scikit
learn and then from the neighbors module of scikit learn.
We will import this class the k neighbors classifier.
That's the class.
And then you know the next natural step it is to create an object of this class
which will represent exactly the k and in model itself, the classifier.
And that's why we call it classifier.
And then
to create an object of this class, well we just need to call the class again.
So I'm copying this basing it here and then adding some parenthesis.
All right.
So that's the first information we need to get from the cycling API.
But then the second thing we need to check also are the parameters here.
And you have all the descriptions here.
So for example the first one and neighbors equals five.
And neighbors is of course the number of neighbors of your k-NN and model.
You remember the intuition lectures
you have the neighbors that you use to make your predictions.
And we have to
choose a number of neighbors and well, you know, we can just try this value.
Five I actually know that we will get good results with this.
But you know, in your future machine learning projects,
if you're using a K in in model, well, I recommend to tune it
with several values, but five is usually good.
So let's do this.
First parameter n neighbors
equals five good.
Then next parameter.
Let's see weights equals uniform.
So uniform is the default value of weights.
And weight is the weight function used in prediction.
And well here we will actually keep the default values uniform,
which means that all the points in each neighborhood are weighted equally okay.
So they have the same importance.
So we will keep that. That's fine.
Then algorithm equals zero.
What does that mean.
Well that's basically the algorithm used to compute the nearest neighbors.
And zero is the best value to choose because it will decide automatically
the most appropriate algorithm based on the values passed to the fit method.
You know, the method that trains your model on the training set.
So definitely here it will be simple if we choose auto and then you have
some other parameters, leaf size of which will give the default value, and P
which is the power parameter for the Minkowski metric.
So there we go. That's important.
That's the other parameters.
We will enter the last two parameters I actually want to enter are this one
metric equals min koski and p because indeed metric
is actually the distance you want to use to compute, you know,
the distance between your observation points and the neighbors.
And we actually want to choose the Euclidean distance,
which is, you know, the classic distance equal to the square root
of the sum of the squared differences between the coordinates
and in order to take that classic Euclidean distance, well,
we have to choose a Minkowski metric with p equals two.
So basically we're keeping all the default
values of this k neighbors classifier class.
But in order to make sure that we are using them and just to highlight them,
well, let's just write these parameters with their default values anyway
because it's important to see what we're dealing with.
You know what version of K and then we're dealing with okay.
So let's do this quickly.
Metric equals Minkowski.
And then p equals two.
Perfect.
And so now we have basically
a classic K-nearest neighbors model with five neighbors.
And the classic Euclidean distance okay.
And now you perfectly know how to finish this.
The last step here is of course to train our classifier,
which indeed we built so far but is not trained yet on the training set.
So that's exactly what we need to do as a final step.
And so there you go.
We call our classifier from which we're going to call our fit method,
which as usual takes as input.
First the matrix of features X train.
And second, the dependent variable vector y train of the training set.
Of course. All right. Perfect.
And that's it.
You know we are done with this implementation.
All the rest is the same.
We don't have to change anything else here because indeed since we called
R-cnn and model classifier.
Well here to make the predictions,
we already have the right name of the variable classifier.
And then same here to predict the test results classifier.
And then same for the confusion matrix Y test wipe read which result
from our same classifier and then same for the visualization of the results.
Sorry, I just show them to you.
I hope you didn't see, but we're going to get to that in a second.
There you go.
That's the same same names of the variable classifier Xtrain y train.
So all the rest is the same.
And that's why I like to call it a good code template.