Hello my friends, and welcome
to this new practical activity on support vector machines.
All right.
So we already built two classification models logistic regression and k.
And then we got the best results so far with Kinen.
And now let's see if SVM can beat it.
All right.
So before we start as usual let's make sure everyone here is on the same page.
And if that's the case then follow me into part three classification
and then section 16 Support Vector machine SVM.
And we're going to start with Python of course as usual.
And in this Python folder you will get two files.
The first is the same data set social network at dot csv
containing 400 observations, where each observation is actually a customer
who but yes or no SUV that is advertised on social networks.
And for each of these customers you have the age, the estimated salary.
So these are the two features.
And with these two features you will predict the dependent variable
purchased meaning whether or not the customers but the SUV.
So one means yes, the customer but a previous SUV and zero means no.
The customer didn't buy any SUV.
All right so same data set.
And of course the second file is this support vector machine implementation.
And the Ipynb format,
which you can either open with Google Colaboratory or Jupyter Notebook.
And as far as I'm concerned, I'm going to open it with Google Collaboratory.
But feel free to choose your favorite ID.
All right.
So let's put that file here. Actually here.
And right now it is loading the notebook laying it out.
And in a second we should have it open.
There we go.
All right.
So that's the whole support vector machine implementation.
And of course it is exactly the same as before.
In order to re-implement this we will only have to change
the code cell where we build and train this model.
Because indeed this implementation results from the exact same classification
template that we made when we built the logistic regression model.
We saw clearly when implementing
the K-nearest neighbors model, how indeed we only had to change one cell
and how this template worked super well for that model.
So here for SVM we're going to do exactly the same.
We're just going to leave all the cells
as they are, as they actually were in the logistic regression model.
And we will only re-implement the cell where we built the SVM.
All right.
So let's do this.
Let's create a new copy of this file.
Because this file is in read only mode.
So let's click here. Save a copy and drive.
And this will create a copy inside which we will indeed be able to modify
the implementation.
And mostly to re-implement that could sell to build the SVM model.
All right. Perfect.
So at the beginning of course, we start with the data preprocessing phase
with all the same outputs displayed on the notebook.
So that's all good.
Then we apply feature scaling because you know
it improves the training performance.
And anyway it's never bad to apply feature scaling.
And finally there we go.
That's the cell we have to re-implement together.
Because indeed
it is the one that differs with respect to the previous implementations.
So let's click this trash button here to, you know, re-implement it again.
Let's create a new code cell.
And now my friends, over to you once again I would like you to please
press pause on the video and try to implement that code.
Sell yourself.
And that's because I not only want to train you
in machine learning, but also train you on how to be independent
with machine learning.
So right now, the exercise I want you to do is to do some research
in the cycle Learning API to figure out
which class allows to build the SVM model.
So you will find it very easily actually, because
there is no trap in the name of the class or the name of the module.
So I trust
you will totally be able to do this exercise successfully and mostly know
which method to use at the end to train that SVM model on the training set.
All right, so please press pause.
And now in two seconds I'm going to give you the solution.
All right let's do this.
So I already have the cycle API open.
You know that was for the nearest neighbors.
The k nearest neighbors which we implemented previously.
In the previous section we used this class k neighbors classifier.
And now the next thing we would like to find in this API documentation
is the module that contains the class that allows to build the SVM model.
So naturally where can we find it?
You know here should we scroll back up or scroll down?
Well, let's hope that you know, the name of the module starts with an S,
because here, you know the modules are organized by alphabetical order.
So since here we are at N use neighbors, let's hope that the name of the module
we're looking for starts with a nest like support vector machine.
So let's scroll down and random projections semi-supervised learning.
And there we go support vector machines.
Hello.
That's exactly what we were looking for.
Support vector machine. So that's not the name of the module.
The name of the module is SVM. It's same.
That stands for Support Vector machines.
All right.
And then well you know the hardest part is done
now according to you which estimator is you know because here you have
all the basically support vector machines based machine learning models.
And so according to you which one do we need to take here.
Well, we actually have two options.
We could either take the linear SVC which will directly
build the linear support vector machine model,
or we can take this one SVC and choose a linear kernel.
All right.
And we will actually go for this option because in the next section
we will study the kernel SVM models, which as you might guess
allow us to choose some different kernels in our SVM, including the linear one
and the nonlinear ones, like for example, the very famous one RBF.