Hello my friends, and welcome
to this new practical activity on this time the kernel SVM model.
So please follow me into part three classification
to implement the kernel SVM model.
And as usual we're going to start with Python.
And here we are with our two files.
The first one that contains
the whole implementation of the kernel SVM model in the Ipynb format.
And the second one the data set, that same data set on which we trained
and will train all the classification models of this part.
So let's have a quick look at it again.
This data set contains some information of 400 customers
represented by each row here.
So each row corresponds to a customer.
And for each of these customers, well we have the age which is a first feature.
The estimated salary which is a second feature.
And the dependent variable purchased which tells whether or not
they bought no or yes, a previous SUV.
All right.
And so in our practical activities
of this part three classification, we build several classification models
to understand the correlations between these two features here.
And this dependent variable purchased in order to predict which future customers
will buy brand new luxury SUV that is advertised on social networks.
All right. So still the same story. And now.
Well, let's begin our kernel SVM implementation.
I'm going to open it with Google Colaboratory.
But you have the choice to open it with Jupyter Notebook as well.
Choose your favorite.
And now it is opening the notebook loading it, laying it out.
And there we go.
Welcome to the kernel SVM implementation.
All right.
And of course it results from the exact same classification template
which we made in the first section of this part logistic regression.
Indeed, when we built the logistic regression model,
we made at the same time a great classification template
which allows us to only change one cell when building another classification
model, which is exactly, you know, the cell where we build
and train this classification model on the training set.
So this cell is the only one we have to modify here.
However, this notebook is in read only mode.
So in order to modify this cell to build a kernel SVM model,
we have to indeed click file here in order to create a copy of this notebook.
And to do this you just need to click save a Copy and drive.
This will create a copy of this notebook.
And in a second you'll have it opened on your machine.
All right so I'm going to put everything in that order.
All right.
And now this is our copy.
And so inside the only thing we have to re-implement is indeed that cell
where we build and train the kernel SVM model on the training set.
So let's not look at it.
Let's put it in the trash.
And now let's re-implement it from scratch.
All right. Perfect.
So it's actually super, super easy.
We can even do it even more efficiently than, you know, the usual way.
When we went to the cycling API, then got the name of the function
because, as I explained in the previous section, when building the SVM model,
the classic one, well, the way we built it was actually to, you know, build
an object of this class as VC and then choose a linear kernel.
And now actually, you know, we're about to do the same.
We're about to use the same class to build this kernel, SVM objects.
But this time, instead of choosing a linear kernel,
we will choose a nonlinear one.
And that's the best example of it.
You know, the most commonly used it is the RBF radial basis function kernel.
And you also have some other ones like the polynomial kernel or the sigmoid kernel.
But really this one is the best option to start with.
And that's the one we'll choose for our kernel SVM implementation,
as you might have guessed.
And therefore remember how I also want to train you on
how to juggle with the different tools of your machine learning toolkit.
You know, the data preprocessing toolkit or the regression toolkit, or even now
the classification toolkit containing all your classification models.
The most efficient way now to build this kernel SVM model is just to go back
to our SVM implementation, then find that cell where we built the SVM.
And indeed, since we built that SVM with the same class as VC,
but choosing a linear kernel, well now as simple as that.
In order to build a kernel SVM, we just need to take this code cell
and paste it right here in a new code cell.
And then guess what?
Just change that kernel parameter.
All right.
And as we said this time we're not using a linear kernel.
We're going to use an RBF kernel.
The radial basis function which was explained in the intuition lectures.
And there you go, my friend.
That implementation is over.
You see how I'm doing
all these templates to make you as most efficient as possible?
Well, that's what I mean.
Now we can juggle between our different codes, different tools
of machine learning, and we can build new models in flashlight.
And that's what we just did with kernel SVM.
All right. So basically we're done. We're ready.
So the next natural step is to upload the data set inside the notebook.
And to do this you need to click this folder button here.
Then your notebook will be connecting to a runtime to enable file browsing.
Still the same story.
In a few seconds we should be able to see the upload button.
Perfect. There we go.
And so now we're going to click it
and we will directly get access to social network.
As if you know you were here in the SVM section.
But let me show you the path once again.
So please find first your whole machine learning is that folder.
Then please go to part three, then section 17 kernel SVM,
then Python and then social network ads dot CSV.
Perfect.
It will upload as a data set inside the notebook.
And now.
Now we can run everything by clicking runtime here and then run