Welcome back.
We're now getting to the exciting step of creating a model.
How can we do this?
Well, we've split our data now.
And luckily for us, SCI could learn comes pre with some tools for us to use to actually build this
model.
So what we can do is actually import from second learn.
Different types of algorithms that we can use to create our model.
In our case, we're going to use the K neighbors classifier.
But just to show you, if I go to second learn.
Models or model selection.
You see that we have a ton of different types of things that we can do.
We're going to use the nearest neighbors, which is a very standard, easy to use algorithm and I'll
link to some resources so you can learn more about it.
And specifically do the nearest neighbor classification, which is going to do exactly this.
It's going to try and divide up the data into different segments.
But as you can see here, we have so many models to pick from or so many algorithms to pick from.
And one of the jobs of a machine learning engineer is to actually figure out which algorithm to use.
But again, this isn't a full machine learning course, so let's just use the neighbors module and from
there import the K.
Neighbors classifier.
Hopefully I, I spelled that right now the way the K nearest neighbor classifier works is we can just
use it as a function.
And all we have to give it is how many neighbors we want.
That is, how many classifications do we want.
In our case, we know that there's three types of flowers.
So all I'm going to do is give it the parameter NW neighbors of equal to three.
And then finally we're going to try and fit this data.
And use this algorithm by giving it the train data set and the Y train output.
So that if I run this.
Well, nothing comes out of it.
Hopefully we've created our model, but there's no way for us to test it.
Right?
If we go back to our steps, we need to check the output rate.
We've created the model.
Yes, it's as simple as what we just did, but we now need to check to see how good our model is, how
good is our function.
Well, we can use the predict now.
To predict and try out our tests so we can use the X test data set and give it to the y underscore predict.
Variable, which will be our predictions.
So what the model predicts based on this new input X test data.
Now the cool thing that we can do now is to actually compare the output of Y predictions that our model
created.
With the actual answers, because remember, we created four different data sets, right?
We created the train data sets for X and Y and also the test data sets.
So for the X test, we gave our new model the test data, which we have the answers to and the model
predicted.
So this function was run to try and predict what type of flower might be based on.
Remember the columns that we gave in?
And now we have our predictions.
So we need to compare the predictions with the why test variable.
And again, I could learn to the rescue has a nice tool for us to do that.
All we need to do is from psychic learn import.
Metrics.
And we can now print the actual accuracy of our model.
And all we do is say metrics dot.
Accuracy.
Make sure I spell that right.
Accuracy.
Score.
And the function takes the Y test data, which is the correct answers and the Y underscore predict,
which is the predictions that our model made.
So if I run this.
I get an error because I haven't run the block with the y predict variable being created.
So let's do that and then run this.
And there we go.
That's our accuracy metrics.
Accuracy score tells us that it's 96% correct.
That's pretty amazing.
Our model, which we just created in honestly three lines of code, is 96% accurate.
How cool is that?
So if we go over what we just did, we imported the data.
We split the data into training and test set.
We created a model by using the K nearest classifier and second learn.
We checked the output using the y prediction and y test variables and now we got the output.
So now we can improve if we want our machine learning algorithm.
So let's do that in the next video.